var siteWidth = 950;
var linkBlueColor 	 = '#164764';
var linkBlueBGColor1 = '#242038';
var linkBlueBGColor2 = '#545068';

var activeDivObj = null;
var activeDivObj = null;
var nextActiveDivObj = null;

/**
 * om man lämnar en tab innan timeouten är slut så avbryts timeouten...
 * På så vis byter man inte flik om man drar musen över menyn snabbt..
 */
var menuTimeoutHandler = null; 

function abortWaitingMenuChange()
{
	if (menuTimeoutHandler != null)
	{
		clearTimeout(menuTimeoutHandler);
		menuTimeoutHandler = null;
	}
}
function setMenuStateActive(divObj)
{
	try 
	{
		if (activeDivObj == divObj)
			return;
			
		nextActiveDivObj = divObj;
		updateMenu = true;

		menuTimeoutHandler = setTimeout(
			function()
			{
				menuTimeoutHandler = null;
				var fadeDuration = 150;
			
				if (activeDivObj != null)
				{
					$('#' + activeDivObj.id + ' .menu_item_active').fadeOut(fadeDuration*.5);
					$('#sub_' + activeDivObj.id).hide();
				}
				$('#' + nextActiveDivObj.id + ' .menu_item_active').fadeIn(fadeDuration);
				$('#sub_' + nextActiveDivObj.id).show(); //fadeIn(fadeDuration);
				$('#sub_' + nextActiveDivObj.id).click(dynamicLinkResponse); // since <a>s are hidden on document load
				
				activeDivObj = nextActiveDivObj;
			}
			, 
			25
		);
	}
	catch (e)
	{
		if (menuTimeoutHandler != null)
		{
			clearTimeout(menuTimeoutHandler)
			menuTimeoutHandler = null;
		}
	}
}
	
function dynamicLinkResponse()
{
	var fullUrlParts = null;
	try
	{
		// avoid issues if .attr is not set
		fullUrlParts = $(this).attr("href").split(/[\#\?]/, 3); //retrieve anchor and queryString
	}
	catch (e) {}

	if (fullUrlParts == null || fullUrlParts.length < 2 || $(this).attr("target") == "_blank" || $(this).attr("class") == "addthis_button") // för tex javascript- o externa länkar..
	{
		return true;
	}
	else
	{
		$.ajax({
			dataType: "html",
			method: "get",
			url: "DefaultAjaxResponse.aspx",
			data: fullUrlParts[1],
			beforeSend: function() { 
					$("#loading").show();
			}, //show loading just when link is clicked
			complete: function() { $("#loading").fadeOut();}, //stop showing loading when the process is complete
			success: function(html) { //so, if data is retrieved, store it in html
					$("#SiteContent").html(html); //show the html inside div
					//$id('SiteContent').innerHTML = html; // IE8 issues...-> $("#SiteContent").html(html); //show the html inside div
					$('#SiteContent a').click(dynamicLinkResponse);
					try 
					{
						if (fullUrlParts.length == 3)
						{
							window.location.hash = fullUrlParts[2];
						}
					}
					catch (e) {}
				},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
					$("#SiteContent").html("<img src=\"../images/loading_error.png\" style=\"margin:30px 0 0 100px;\" />"); //'<div class="text"><h1>Timeout</h1>Det tog för lång tid att hämta sidan du begärde.<br />Var god försök igen.</div>'); //show the html inside div
//							// typically only one of textStatus or errorThrown will have info
//							this; // the options for this ajax request
//							if (textStatus == 'timeout')
//								$("#SiteContent").html('<div class="text"><h1>Timeout</h1>Det tog för lång tid att hämta sidan du begärde.<br />Var god försök igen.</div>'); //show the html inside div
//							else if (textStatus == 'error')
//								$("#SiteContent").html('<div class="text"><h1>Fel</h1>Något gick fel när sidan skulle laddas.<br />Var god försök igen.</div>'); //show the html inside div
//							else
//								alert(XMLHttpRequest + " or " + errorThrown);
				}
//					, timeout: 1
		});
		return false; // if javascript is disabled... we want the link to behave as normal... but not now
	}
}

