// Global Variables //
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 _isLoaded = false, _navCount = _subNavCount = 0, _canAni = "show", _animateBy = 40;
var _incArrayMenu = [0,10,17,19,20], _incArrayUL = [20,13,6,2,0], _incArrayMenuH = [20,19,17,10,0], _incArrayULH = [0,2,6,13,20];

$S = function(_elementID) {
	return $(_elementID).style;
}

setNavEvents = function() {
	$("nav").onmouseover = function() {menuOver();};

	$("Nav0").onmouseover = function() {showSubNav("Nav0");};
	$("Nav1").onmouseover = function() {showSubNav("Nav1");};
	$("Nav2").onmouseover = function() {showSubNav("Nav2");};
	$("Nav3").onmouseover = function() {showSubNav("Nav3");};
	$("Nav4").onmouseover = function() {showSubNav("Nav4");};	
	$("Nav5").onmouseover = function() {showSubNav("Nav5");};
	$("Nav6").onmouseover = function() {showSubNav("Nav6");};
	$("Nav7").onmouseover = function() {showSubNav("Nav7");};
	$("Nav8").onmouseover = function() {showSubNav("Nav8");};
}


httpPost = function() {
	var _httpPostSocket;
	// Send request //
	this.sendRequest = function(_contentElement,_args) {
		var _url = ("/ajax/" + _contentElement), _continue = true, _method = "POST", _postArgs = "";

		if (window.XMLHttpRequest) {
			_httpPostSocket = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				_httpPostSocket = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(_e) {
				_httpPostSocket = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
}

// Show subNav //
showSubNav = function(_elementID) {
	_wait = 0;
	if (_canAni == "show") {
		$S("navUL").marginBottom = 0;
		if ($("subNavContainer").style.height != (_incArrayMenuH[0] + "px")) {
			// If subNavContainer is closed...
			_canAni = "";
			for (_i=0;_i<_incArrayMenu.length;_i++) {
				setTimeout("aniSubNav(" + _incArrayMenu[_i] + "," + _incArrayUL[_i] + ")",(_animateBy * _i));
			}
			$S("subNavContainer").display = "block";
		}
		_wait = (_incArrayMenu.length * _animateBy);
		setTimeout("menuAniStop('hide')",(_wait + 19));
	}

	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) {
	$S("subNavContainer").height = (_howMuchMenu + "px");
	$S("navUL").marginTop = (_howMuchUL + "px");
}

// Hide subNav //
hideSubNav = function() {
	_wait = 0;
	if (_canAni == "hide") {
		if ($S("subNavContainer").height == (_incArrayMenuH[0] + "px")) {
			_canAni = "";
			for (_i=0;_i<_incArrayMenu.length;_i++) {
				setTimeout("aniSubNav(" + _incArrayMenuH[_i] + "," + _incArrayULH[_i] + ")",(_animateBy * _i));
			}
			_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 = "transparent url(/images/header/nav/meny-top.png) top right no-repeat";
		$S("Nav" + _i).color = "#2978ae";
	}
	if (_elementID) {
		// See .nav li a:hover in ./global.css for values //
		$S(_elementID).background = "transparent url(/images/header/nav/knapp-over-alt3.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);
	}
}
