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;
	}

document.getElementsByClassName = function(tag, elemClass)
	{
	var elementsList = [];
	for(var i=0; i < document.getElementsByTagName(tag).length; i++)
		{
		if(document.getElementsByTagName(tag)[i].className == elemClass) elementsList.push(document.getElementsByTagName(tag)[i]);
		}
	return elementsList;
	}



showCase = [];
showCase = 
	{
	showcase	: false,
	tempPos	: 0,
	scrollPos	: 0,

	change: function(elem, caseData, direction, orientation)
		{
		if(!direction) direction = 1;
		showCase.showcase = caseData;		
		showCase.scrollPos+=direction;
		if(showCase.scrollPos >= elem.getElementsByTagName("IMG").length) showCase.scrollPos = 0;
		if(showCase.scrollPos < 0) showCase.scrollPos =  elem.getElementsByTagName("IMG").length-1;
		var counterContainer = document.getElementsByClassName('div', 'imageCounter');
		counterContainer[0].innerHTML = "Kuva " + (showCase.scrollPos+1) + " / " +  elem.getElementsByTagName("IMG").length;
		if(!orientation)
			{
			fpTools.animate.init(elem, animate._x, (showCase.tempPos)*-800, (-800*showCase.scrollPos), 10, 30)
			}
		else	{
			fpTools.animate.init(elem, animate._y, (showCase.tempPos)*-280, (-280*showCase.scrollPos), 10, 30)
			}
		showCase.tempPos = showCase.scrollPos;
		}
	}

window.onload = function()
	{
	initAfterDashboard();
	}

function initAfterDashboard()
	{
	if(typeof(fixedPointAjaxFramework) != 'object')
		{
		setTimeout("initAfterDashboard()", 300);
		return false;
		}
	
	attachLinks();
	getHash();
	insertContactDetails();
	}

function insertContactDetails()
	{
	var emailAddress = 'pyry'+'@'+'kiinto'+'.'+'com';
	var emailLink = document.createElement("A");
	emailLink.setAttribute("HREF", 'mailto:'+emailAddress);
	emailLink.appendChild(document.createTextNode(emailAddress));
	$("contactInformation").appendChild(emailLink);
	}

function getHash()
	{
	if(window.location.hash)
		{
		pageLocation = window.location.hash;
		pageLocation = pageLocation.slice(1);
		pageLocation = pageLocation.toParameters('&','=');
		contentUrl = pageLocation.content;
		if(contentUrl)
			{
			fixedPointAjaxFramework.addToLine(["content_"+contentUrl+'.php?'+'page='+contentUrl, $('bottomContent'), true, false, false, true]); 
			var navigationLinksTemp = document.getElementById("header").getElementsByTagName("a");
			for (var i=0; i<navigationLinksTemp.length;i++)
				{
				(navigationLinksTemp[i].href.indexOf(contentUrl) == -1) ? navigationLinksTemp[i].className = "" : navigationLinksTemp[i].className = "selected";
				}
			}
		}
	}

function attachLinks()
	{
	var navigationLinks = document.getElementById("header").getElementsByTagName("a");
	for (var i=0; i<navigationLinks.length;i++)
		{
		navigationLinks[i].onclick = function()
			{
			var navigationLinksTemp = document.getElementById("header").getElementsByTagName("a");
			for (var i=0; i<navigationLinksTemp.length;i++)
				{
				navigationLinksTemp[i].className = "";
				}
			this.className = "selected";

			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))
					{
					fixedPointAjaxFramework.addToLine(["content_"+contentUrl+'.php', $('bottomContent'), true, false, false, true]); 
					window.location.href= "#content="+contentUrl;
					getHash();
					}
				}
			return false;
			}
		}
	}