/* MENU */
var _isMoz = (navigator.appName == "Netscape");
var _isIE = (navigator.appName == "Microsoft Internet Explorer");
var _isIE6 = (navigator.appVersion.search("MSIE 6.0") != -1);
var _isSafari = (navigator.userAgent.indexOf("Safari") != -1);
var _canAni = "show";

// Ugly as HELL //
var _incArrayMenu = [0,10,17,21,23];
var _incArrayUL = [57,47,40,36,34];
var _incArrayMenuH = [23,21,17,10,0];
var _incArrayULH = [34,36,40,47,57];

// nav count equals one less than total number of main items
var _navCount = 8;
// sub nav count equals one less than total number of main items
var _subNavCount = 8;
var _animateBy = 30;

// Show subNav //
showSubNav = function(_elementID) {
	//alert("sub nav: " + _elementID);
	_wait = 0;
	if (_canAni == "show") {
		$S("navUL").marginBottom = 0;
		//alert("sub nav height: " + $("subNavContainer").style.height);
		if ($("subNavContainer").style.height != "22px") { //(_incArrayMenuH[0] + "px")) {
			// If subNavContainer is closed...
			_canAni = "";
			for (_i=0;_i<_incArrayMenu.length;_i++) {
				setTimeout("aniSubNav(" + _incArrayMenu[_i] + "," + _incArrayUL[_i] + ")",(_animateBy * _i));
				//alert ("from show calling ani sub nav: " + _incArrayMenuH[_i] + ", " + _incArrayULH[_i]);
			}
			$S("subNavContainer").display = "block";
		}
		_wait = (_incArrayMenu.length * _animateBy);
		setTimeout("menuAniStop('hide')",(_wait + 19));
	}

	/*
	fadeElement("sub" + _elementID,0);
	for (_i=1;_i<=10;_i++) {
		setTimeout("fadeElement('sub" + _elementID + "'," + _i + ")",(_wait + (_animateBy * _i)));
	}
	*/
	
	highlightNav(_elementID);

	// Close any SubNavs we have open //
	for (_i=0;_i<=_subNavCount;_i++) {
		$S("subNav" + _i).display = "none";
	}
	$S("sub" + _elementID).display = "block";
}

aniSubNav = function(_howMuchMenu,_howMuchUL) {
	//alert("how much: " + _howMuchMenu);
	if (_howMuchMenu=="0") {
		$S("subNavContainer").visibility = "hidden";
		
	} else {
		$S("subNavContainer").visibility = "visible";
		$S("subNavContainer").height = (_howMuchMenu + "px");
	}
	//$S("navUL").marginTop = (_howMuchUL + "px");
}

// Hide subNav //
hideSubNav = function() {
	_wait = 0;
	if (_canAni == "hide") {
		//alert("hide");
		if ($S("subNavContainer").height == (_incArrayMenuH[0] + "px")) {
			_canAni = "";
			//alert("hiding");
			for (_i=0;_i<_incArrayMenu.length;_i++) {
				setTimeout("aniSubNav(" + _incArrayMenuH[_i] + "," + _incArrayULH[_i] + ")",(_animateBy * _i));
				//alert ("from hide calling ani sub nav: " + _incArrayMenuH[_i] + ", " + _incArrayULH[_i]);
			}
			$S("subNavContainer").display = "none";
			_wait = (_incArrayMenu.length * _animateBy);
			setTimeout("menuAniStop('show')",(_wait + 19));
		}
	}
}

menuOver = function() {
	try {
		clearTimeout(_timeOut);
	} catch(_e) {}
}

menuOut = function() {
	_timeOut = setTimeout("hideSubNav(); highlightNav();",750);
}

// Called when the menu is done animating [either up or down]
menuAniStop = function(_showHide) {
	_canAni = _showHide;
}

// Highlight whatever _elementID is passed //
highlightNav = function(_elementID) {
	// Clear any Nav Anchors we have higlighted //
	for (_i=0;_i<=_navCount;_i++) {
		// See .nav li a in ./global.css for values //
		$S("Nav" + _i).background = "url(/media/system/menu/nav_sep.png) right no-repeat";
		// check if current nav element is the same as the store element id which is the selected menu item
		$S("Nav" + _i).color = (("Nav"+_i)==element_id) ? "#303030" : "#63a0a8";
	}
	if (_elementID) {
		// See .nav li a:hover in ./global.css for values //
		$S(_elementID).background = "63a0a8 url(/media/system/menu/nav_sep.png) top right no-repeat";
		$S(_elementID).color = "#ffffff";
	}
}

// Fades _elementID to _opacity, called from timeouts //
fadeElement = function(_elementID,_opacity) {
	// Safari seems to think it's funny to throw a moueover event when you move your mouse, so this will flicker: //
	if (_isIE) {
		$(_elementID).style.filter = "alpha(opacity=" + (_opacity * 10) + ")";
	} else if (_isMoz) {
		$(_elementID).style.MozOpacity = (_opacity / 10);
		$(_elementID).style.opacity = (_opacity / 10);
	}
}

toggleDisplay = function(_elementIDs,_flow) {
	if (_elementIDs.constructor != Array) {
		_elementIDs = [_elementIDs];
	}
	for (_i=0;_i<_elementIDs.length;_i++) {
		$(_elementIDs[_i]).style.display = (_flow) ? _flow : "none";
	}
}


swapImage = function(_elementID,_src) {
	var _element = "";
	if (_element = _src.match(/(.+)_off\.png$/)) {
		$(_elementID).src = _element[1] + "_on.png";
	} else {
		$(_elementID).src = _src.match(/(.+)_on\.png$/)[1] + "_off.png";
	}
}













