opacityFade=100;
fading = false;
fadeSpeed = 30;
fadeSteps = 20;
ajaxRequest = false;
var shopInit = false;

templocation = 1;
var contentUrl;
var contentPage;
var currentContentUrl; 
var currentContentPage;

function showDemo(objID,final_x,interval)
	{
	if (!document.getElementById) return false;
	if (!document.getElementById(objID)) return false;
	var elem = document.getElementById(objID);
	if (elem.movement)
		{
		clearTimeout(elem.movement);
		}
	if (!elem.style.left)
		{
		elem.style.left= "-816px";
		}
	var xpos = parseInt(elem.style.left);
	if (xpos < final_x)
		{
		var dist = Math.ceil((final_x - xpos)/8);
		xpos = xpos + dist;
		}
	if (xpos > final_x)
		{
		var dist = Math.ceil((xpos - final_x)/8);
		xpos = xpos - dist;
		}
	elem.style.left= xpos + "px";
	var repeat = "showDemo('"+objID+"',"+final_x+","+interval+")";
	elem.movement = setTimeout(repeat,interval);
	}

function collapse(objID,final_x,interval, direction)
	{
	if (!document.getElementById) return false;
	if (!document.getElementById(objID)) return false;
	if (!document.getElementById(objID).style.height){document.getElementById(objID).style.height = document.getElementById(objID).scrollHeight+"px";}


	var elem = document.getElementById(objID);
	if (elem.movement)
		{
		clearTimeout(elem.movement);
		}
	var objHeight = parseInt(elem.style.height);
	if (objHeight < final_x)
		{
		var dist = Math.ceil((final_x - objHeight)/8);
		objHeight = objHeight + dist;
		}
	if (objHeight > final_x)
		{
		var dist = Math.ceil((objHeight - final_x)/8);
		objHeight = objHeight - dist;
		}
	if(objHeight == final_x)
		{
		final_x = false;
		objHeight = false;
		fading = false;
		if(direction == 'in') fadeIn();
		if(direction == 'out') fadeOut();
		return false;
		}
	elem.style.height= objHeight + "px";
	var repeat = "collapse('"+objID+"',"+final_x+","+interval+",'"+direction+"')";
	elem.movement = setTimeout(repeat,interval);
	}

function getHTTPObject()
	{
	if (window.ActiveXObject)
		{
		waystation = new ActiveXObject("Microsoft.XMLHTTP");
		}
	else if (window.XMLHttpRequest)
		{
		waystation = new XMLHttpRequest();
		}
	else	{
		 waystation = false;
		}
	
	return waystation;
	}

function loadContent(fileName)
	{
	if(ajaxRequest || fading) return false;
	request = getHTTPObject();
	if(!request) return false;
	request.open("GET", fileName, true);
	request.onreadystatechange = readExternal;
	request.send(null);
	}

function loadSubContent(fileName)
	{
	if(ajaxRequest || fading) return false;
	request = getHTTPObject();
	if(!request) return false;
	request.open("GET", fileName, true);
	request.onreadystatechange = readExternal2;
	request.send(null);
	}

function readExternal()
	{
	if (request.readyState != 4)
		{
		if(document.getElementById("loader").style.display != "block")
			{
			ajaxRequest= true;
			fading = true;
			document.getElementById("loader").style.display = "block";
			}
 		}

	if (request.readyState == 4)
		{
		ajaxRequest= false;
		document.getElementById("loader").style.display = "none";
		document.getElementById("tmpContainer").innerHTML = request.responseText;
		collapse('maincontent',0,30, 'out');
		}
	}

function readExternal2()
	{
	if (request.readyState != 4)
		{
		if(document.getElementById("loader").style.display != "block")
			{
			ajaxRequest= true;
			fading = true;
			document.getElementById("loader").style.display = "block";
			}
 		}

	if (request.readyState == 4)
		{
		ajaxRequest= false;
		document.getElementById("loader").style.display = "none";
		document.getElementById("RightColumnContent").innerHTML = request.responseText;
		}
	}


function fadeOut(direction)
	{
	fading = true;

	if(opacityFade>=0)
		{
		with(document.getElementById("maincontent").style)
			{
			opacity = opacityFade/100;
			filter	= "Alpha(opacity="+opacityFade+")";
			}
		setTimeout('opacityFade=opacityFade-fadeSteps;fadeOut(\''+direction+'\')',fadeSpeed);
		}
	else	{
		setTimeout("displayContent()",30);
		}
	}

function fadeIn(direction)
	{
		
	if(opacityFade<=100)
		{
		with(document.getElementById("maincontent").style)
			{
			opacity = opacityFade/100;
			filter	= "Alpha(opacity="+opacityFade+")";
			}
		setTimeout('opacityFade=opacityFade+fadeSteps;fadeIn(\''+direction+'\')',fadeSpeed);
		}
	else	{
		fading = false;
		if(shopInit == true) initShop()
		}
	}

function displayContent()
	{
	document.getElementById("maincontent").innerHTML = document.getElementById("tmpContainer").innerHTML;
 	collapse('maincontent',parseInt(document.getElementById("maincontent").scrollHeight),30 ,'in');
	}

function getHash()
	{
	if(window.location.hash)
		{
		pageLocation = window.location.hash;
		pageLocation = pageLocation.slice(1);
		pageLocation = pageLocation.toParameters('&','=');
		contentUrl = pageLocation.content;
		if(pageLocation.pageid) contentPage = pageLocation.pageid;
		else contentPage ="";
		if(contentUrl && !ajaxRequest)
			{
			loadContent(contentUrl+'.php?'+'page='+contentUrl+'&pageid='+contentPage);
			if(contentPage == 'initShop') shopInit = true;
			else shopInit = false;
			templocation= 1;
			}
		}
	else	{
		if(templocation!= 0)
			{
			loadContent('mainpage.php');
			templocation= 0;
			}
		}
	}

String.prototype.toParameters = function(s,vs){
	var sep = "&";
	var valsep = "=";
	
	if(s)	{
		sep = s;
		valsep = vs;
		}

	var par = {}
	var prop = this.split(sep);
					
	for(var i=0;i<prop.length;i++)
		{
		var cprop = prop[i].split(valsep);
		if(cprop.length>=2)
			{
			var param = cprop.shift();
			par[param] = cprop.join("=");
			}
		}
	return par;
	}


function pollHash()
	{
	currentPageLocation = window.location.hash;
	currentPageLocation = currentPageLocation.slice(1);
	currentPageLocation = currentPageLocation.toParameters('&','=');
	currentContentUrl = currentPageLocation.content;
	currentContentPage = currentPageLocation.pageid;
	if(currentContentPage)
		{
		if(contentUrl != currentContentUrl || contentPage != currentContentPage)
			{
			getHash();
			}
		}
	else	if(contentUrl != currentContentUrl)
		{
			{
			getHash();
			}
		}
	setTimeout("pollHash()",100);
	}

onload = function()
	{
//	attachLinks();
	getHash();
//	pollHash();
	}

function attachLinks()
	{
	var navigationLinks = document.getElementsByTagName("a");
	for (var i=0; i<navigationLinks.length;i++)
		{
		if(navigationLinks[i].getAttribute("class") == 'navigation')
			{
			navigationLinks[i].onclick = function()
				{
				if(fading) return false;
				if(ajaxRequest) return false;

				var navigationLinksTemp = document.getElementsByTagName("a");
				for (var i=0; i<navigationLinksTemp.length;i++)
					{
					navigationLinksTemp[i].className = "navigation";
					}
				this.className = "navigationSelected";


				pageLocation = this.getAttribute("href");
				pageLocation = pageLocation.substr(pageLocation.indexOf("?"));
				pageLocation = pageLocation.slice(1);
				pageLocation = pageLocation.toParameters('&','=');
				contentUrl = pageLocation.content;
				if(contentUrl)
					{
					if(contentUrl != location.hash.slice(9))
						{
						setTimeout("loadContent('"+contentUrl+".php?')",30);
						pageTracker._trackPageview(contentUrl); 
						window.location.href= "#content="+contentUrl;
						}
					}
				return false;
				}
			}
		}
	}

function ajaxReq(elem)
	{
	pageLocation = elem;
	pageLocation = pageLocation.substr(pageLocation.indexOf("?"));
	pageLocation = pageLocation.slice(1);
	pageLocation = pageLocation.toParameters('&','=');
	contentUrl = pageLocation.content;
	if(pageLocation.pageid) contentPage = pageLocation.pageid;
	else contentPage ="";
	if(contentUrl && !ajaxRequest)
		{
		loadContent(contentUrl+'.php?'+'page='+contentUrl+'&pageid='+contentPage);
		pageTracker._trackPageview(contentUrl+'&pageid='+contentPage); 
		window.location.href= "#content="+contentUrl+"&pageid="+contentPage;
		}
	return false;
	}
