// JavaScript Document

// mouse over images

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_over = newImage("images/menu_home_on.gif");
		products_over = newImage("images/menu_products_on.gif");
		portfolio_over = newImage("images/menu_products_on.gif");
		contactus_over = newImage("images/menu_contactsus_on.gif");
		preloadFlag = true;
	}
}


// drop down menus


	// the number you pass to initLeft doesn't matter since it will get changed onactivate
	// Order within the parenthasis is: (ID Tag, direction, left margin, top margin, width, height)
	var who = 	new ypSlideOutMenu("who", "down", 0, 370, 110, 140)
	who.onactivate = function() { repositionMenu(who, -344, 355); }

	var what = 	new ypSlideOutMenu("what", "down", 0, 370, 130, 240)
	what.onactivate = function() { repositionMenu(what, -256, 355); }

	var challenge = 	new ypSlideOutMenu("challenge", "down", 0, 370, 110, 20)
	challenge.onactivate = function() { repositionMenu(challenge, -168, 355); }

	var reports = 	new ypSlideOutMenu("reports", "down", 0, 370, 240, 140)
	reports.onactivate = function() { repositionMenu(reports, -63, 355); }

	var press = 	new ypSlideOutMenu("press", "down", 0, 370, 100, 200)
	press.onactivate = function() { repositionMenu(press, +108, 355); }

	var news = 	new ypSlideOutMenu("news", "down", 0, 370, 100, 60)
	news.onactivate = function() { repositionMenu(news, +203, 355); }

	// this function repositions a menu to the speicified offset from center
	function repositionMenu(menu, offsetW, leftpos)
	{
		// IS added to adjust when the window is too small
		var maxWidth = 909;

		var mnuwid = getWindowWidth();

		// the new left position should be the center of the window + the offset
		var newLeft = mnuwid > maxWidth ? getWindowWidth() / 2 + offsetW : leftpos;

		// setting the left position in netscape is a little different than IE
		menu.container.style ? menu.container.style.left = newLeft + "px" : menu.container.left = newLeft;
	}

	// this function calculates the window's width - different for IE and netscape
	function getWindowWidth() { return window.innerWidth ? window.innerWidth : document.body.offsetWidth; }

ypSlideOutMenu.writeCSS();

