document.observe('dom:loaded', function() {
	var showBoxTyyliTiedosto = document.createElement('link');
	showBoxTyyliTiedosto.setAttribute("rel", 'stylesheet');
	showBoxTyyliTiedosto.setAttribute("type", 'text/css');
	showBoxTyyliTiedosto.setAttribute("href", 'show_box/show_box_tyylit.css');
	document.getElementsByTagName("head")[0].appendChild(showBoxTyyliTiedosto);
	
	var showBoxObjBody = document.getElementsByTagName("body").item(0);
	
	var showBoxObjAlusta = document.createElement("div");
	showBoxObjAlusta.setAttribute('id', 'showBoxAlusta');
	showBoxObjAlusta.style.display = 'none';
	showBoxObjAlusta.style.position = 'absolute';
	showBoxObjAlusta.style.top = '0px';
	showBoxObjAlusta.style.left = '0px';
 	showBoxObjAlusta.style.width = '0px';
	showBoxObjAlusta.style.height = '0px';
	showBoxObjAlusta.innerHTML = '<table align="center" cellpadding="0" cellspacing="0" border="0" id="showBoxSisaltoTaulu"><tr><td align="left" valign="top" height="20px" width="20px"><img src="show_box/show_box_vasen_yla.png" border="0" /></td><td align="left" bgcolor="#a16849" id="showBoxSisaltoYla">&nbsp;</td><td align="right" valign="top" height="20px" width="20px"><img src="show_box/show_box_oikea_yla.png" border="0" /></td></tr><tr><td align="left" colspan="3" bgcolor="#a16849" id="showBoxSisalto"></td></tr><tr><td align="left" valign="bottom" height="20px" width="20px"><img src="show_box/show_box_vasen_ala.png" border="0" /></td><td align="left" bgcolor="#a16849" id="showBoxSisaltoAla">&nbsp;</td><td align="right" valign="bottom" height="20px" width="20px"><img src="show_box/show_box_oikea_ala.png" border="0" /></td></tr></table>';
	showBoxObjBody.insertBefore(showBoxObjAlusta, showBoxObjBody.firstChild);
	
	var showBoxObjVarjostus = document.createElement("div");
	showBoxObjVarjostus.setAttribute('id', 'showBoxSivunVarjostus');
	showBoxObjVarjostus.style.display = 'none';
	showBoxObjVarjostus.style.position = 'absolute';
	//showBoxObjVarjostus.onclick = function () {ShowBoxPiilotaVarjostus();};
	showBoxObjVarjostus.style.top = '0px';
	showBoxObjVarjostus.style.left = '0px';
 	showBoxObjVarjostus.style.width = '0px';
	showBoxObjVarjostus.style.height = '0px';
	showBoxObjBody.insertBefore(showBoxObjVarjostus, showBoxObjBody.firstChild);
	
	var showBoxNaytettava='';
});

function ShowBoxAvaa(mika) {
	//VAIN BILIKSEN SIVUJEN OMINAISUUS
	if(document.getElementById('footer')) {
		document.getElementById('footer').style.zIndex='-1';
	}
	
	showBoxNaytettava = document.getElementById(mika);
	var showBoxAlusta = document.getElementById('showBoxAlusta');
	var showBoxSisalto = document.getElementById('showBoxSisalto');
	var showBoxSisaltoTaulu = document.getElementById('showBoxSisaltoTaulu');
	var showBoxSisaltoYla = document.getElementById('showBoxSisaltoYla');
	var showBoxSisaltoAla = document.getElementById('showBoxSisaltoAla');
	
	showBoxNaytettava.style.position = 'absolute';
	
	showBoxNaytettava.style.display = '';
	var showBoxNaytettavanKorkeus = showBoxNaytettava.offsetHeight;
	var showBoxNaytettavanLeveys = showBoxNaytettava.offsetWidth;
	var showBoxAlustanKorkeus = showBoxNaytettavanKorkeus - (-45);
	var showBoxAlustanLeveys = 	showBoxNaytettavanLeveys - (-40);
	showBoxNaytettava.style.display = 'none';
	
	ShowBoxNaytaVarjostus(showBoxAlustanKorkeus, showBoxAlustanLeveys);
		
	var showBoxScrolliX = ShowBoxHaeVaakaScrolli() || 0;
	var showBoxScrolliY = ShowBoxHaePystyScrolli() || 0;
	var showBoxVieritysLeveys = showBoxScrolliX - (-ShowBoxHaeIkkunanLeveys());
	var showBoxVieritysKorkeus = showBoxScrolliY - (-ShowBoxHaeIkkunanKorkeus());
	
	var showBoxAlustanSijaintiX = showBoxVieritysLeveys - (showBoxAlustanLeveys);
	var showBoxAlustanSijaintiY = showBoxVieritysKorkeus - (showBoxAlustanKorkeus);
	
	showBoxAlustanSijaintiX = showBoxAlustanSijaintiX - ((ShowBoxHaeIkkunanLeveys()/2) - (showBoxAlustanLeveys/2));
	showBoxAlustanSijaintiY = showBoxAlustanSijaintiY - ((ShowBoxHaeIkkunanKorkeus()/2) - (showBoxAlustanKorkeus/2));
	
	if(showBoxAlustanSijaintiX < 10)
	{
		showBoxAlustanSijaintiX = 10;
	}
	if(showBoxAlustanSijaintiY < 100)
	{
		showBoxAlustanSijaintiY = 100;
	}
	else {
		if((showBoxAlustanSijaintiY-100)>100) {
			showBoxAlustanSijaintiY-=100;
		}
	}
	
	if(showBoxAlustanSijaintiX < ShowBoxHaeVaakaScrolli())
	{
		showBoxAlustanSijaintiX = ShowBoxHaeVaakaScrolli() - (-10);
	}
	if(showBoxAlustanSijaintiY < ShowBoxHaePystyScrolli())
	{
		showBoxAlustanSijaintiY = ShowBoxHaePystyScrolli() - (-10);
	}
	
	showBoxAlusta.style.top = showBoxAlustanSijaintiY + 'px';
	showBoxAlusta.style.left = showBoxAlustanSijaintiX + 'px';
	
	var showBoxNaytettavanSijaintiX = showBoxAlustanSijaintiX - (-20);
	var showBoxNaytettavanSijaintiY = showBoxAlustanSijaintiY - (-25);
	
	showBoxNaytettava.style.top = showBoxNaytettavanSijaintiY + 'px';
	showBoxNaytettava.style.left = showBoxNaytettavanSijaintiX + 'px';
	
	var showBoxSisaltoEteneminen = 0;
	showBoxSisaltoTaulu.style.width = '0px';
	showBoxSisalto.style.height = '0px';
	showBoxSisalto.style.width = '0px';
	showBoxSisaltoYla.style.width = '0px';
	showBoxSisaltoAla.style.width = '0px';
	var showBoxNapinSijainti;
	var showBoxLeveysFadeInValmis = false;
	var showBoxKorkeusFadeInValmis = false;
	
	showBoxSisalto.fadeIn = window.setInterval(
	function() 
	{
		showBoxSisaltoEteneminen+=20;
		
		showBoxTempSisaltoHeight = showBoxSisalto.style.height
		showBoxTempSisaltoHeight = showBoxTempSisaltoHeight.replace("px", "");
		if(showBoxTempSisaltoHeight<showBoxNaytettavanKorkeus) {
			showBoxSisalto.style.height = showBoxSisaltoEteneminen+'px';
		}
		else {
			if(showBoxKorkeusFadeInValmis==false) {
				showBoxSisalto.style.height = showBoxSisaltoEteneminen+'px';
				
				showBoxKorkeusFadeInValmis = true;
			}
		}
		
		showBoxTempSisaltoWidth = showBoxSisaltoTaulu.style.width;
		showBoxTempSisaltoWidth = showBoxTempSisaltoWidth.replace("px", "");
		if(showBoxTempSisaltoWidth<showBoxNaytettavanLeveys) {
			showBoxSisaltoTaulu.style.width = (showBoxSisaltoEteneminen-(-40))+'px';
			showBoxSisalto.style.width = (showBoxSisaltoEteneminen-(-40))+'px';
			showBoxSisaltoYla.style.width = showBoxSisaltoEteneminen+'px';
			showBoxSisaltoAla.style.width = showBoxSisaltoEteneminen+'px';
		}
		else {
			if(showBoxLeveysFadeInValmis==false) {
				showBoxSisaltoTaulu.style.width = (showBoxSisaltoEteneminen-(-40))+'px';
				showBoxSisalto.style.width = (showBoxSisaltoEteneminen-(-40))+'px';
				showBoxSisaltoYla.style.width = showBoxSisaltoEteneminen+'px';
				showBoxSisaltoAla.style.width = showBoxSisaltoEteneminen+'px';			
				
				showBoxNapinSijainti = showBoxSisaltoEteneminen;
				showBoxLeveysFadeInValmis = true;
			}
		}
		
		if(showBoxSisaltoEteneminen==20) {
			showBoxAlusta.style.display = '';
		}
		
		if(showBoxLeveysFadeInValmis==true && showBoxKorkeusFadeInValmis==true)
		{
			window.clearInterval(showBoxSisalto.fadeIn);
			
			showBoxNaytettava.style.display = '';
			
			document.getElementById('showBoxSivunVarjostus').onclick = function () {ShowBoxPiilotaVarjostus();};
			
			var showBoxObjSuljeNappi = document.createElement("div");
			showBoxObjSuljeNappi.setAttribute('id', 'showBoxSuljeNappi');
			showBoxObjSuljeNappi.innerHTML = '<img src="show_box/sulje.gif" id="showBoxSulje" border="0" onmouseover="javascript: document.getElementById(\'showBoxSulje\').src = \'show_box/sulje_over.gif\'" onmouseout="javascript: document.getElementById(\'showBoxSulje\').src = \'show_box/sulje.gif\'" />';
			showBoxObjSuljeNappi.style.position = 'absolute';
			showBoxObjSuljeNappi.onclick = function () {ShowBoxPiilotaVarjostus();};
			showBoxObjSuljeNappi.style.top = (showBoxAlustanSijaintiY-(-5)) + 'px';
			showBoxObjSuljeNappi.style.left = (showBoxAlustanSijaintiX-(-(showBoxNapinSijainti-(-10)))) + 'px';
			showBoxObjSuljeNappi.style.width = '20px';
			showBoxObjSuljeNappi.style.height = '20px';
			var showBoxObjBody = document.getElementsByTagName("body").item(0);
			showBoxObjBody.insertBefore(showBoxObjSuljeNappi, showBoxObjBody.lastChild);
		}
	}
	,1);
}

function ShowBoxNaytaVarjostus(sisallonKorkeus, sisallonLeveys)
{
	var showBoxVarjostus = document.getElementById('showBoxSivunVarjostus');
	var showBoxKorkeus = ShowBoxHaeIkkunanKorkeus();
	var showBoxLeveys = ShowBoxHaeIkkunanLeveys();
	
	if(showBoxKorkeus < ShowBoxHaeSivunKorkeus())
	{
		showBoxKorkeus = ShowBoxHaeSivunKorkeus();
	}
	
	if(showBoxKorkeus<sisallonKorkeus) {
		showBoxKorkeus = sisallonKorkeus-(-110);
	}
	
	if(showBoxLeveys < ShowBoxHaeSivunLeveys())
	{
		showBoxLeveys = ShowBoxHaeSivunLeveys();
	}
	
	if(showBoxLeveys<sisallonLeveys) {
		showBoxLeveys = sisallonLeveys-(-10);
	}
	
	showBoxKorkeus += 30;
	
	showBoxVarjostus.style.width = showBoxLeveys + 'px';
	showBoxVarjostus.style.height = showBoxKorkeus + 'px';
	showBoxVarjostus.style.display = '';
}

function ShowBoxPiilotaVarjostus() {
	//window.clearInterval(showBoxSisalto.fadeIn);
	//VAIN BILIKSEN SIVUJEN OMINAISUUS
	if(document.getElementById('footer')) {
		document.getElementById('footer').style.zIndex='';
	}
		
	document.getElementById('showBoxSivunVarjostus').style.display = 'none';
	document.getElementById('showBoxAlusta').style.display = 'none';
	showBoxNaytettava.style.display = 'none';
	
	document.getElementById('showBoxSivunVarjostus').onclick='';
	
	if(document.getElementById("showBoxSuljeNappi")) {
		var showBoxObjBody = document.getElementsByTagName("body").item(0);
		showBoxObjBody.removeChild(document.getElementById("showBoxSuljeNappi"));
	}
	
	/*showBoxSisaltoTaulu.style.width = '0px';
	showBoxSisalto.style.height = '0px';
	showBoxSisalto.style.width = '0px';
	showBoxSisaltoYla.style.width = '0px';
	showBoxSisaltoAla.style.width = '0px';
	var showBoxLeveysFadeInValmis = false;
	var showBoxKorkeusFadeInValmis = false;*/
}

//HAE SIVUN MITAT
function ShowBoxHaeSivunLeveys()
{
	var showBoxSivunLeveys;
		
	if(window.innerHeight && window.scrollMaxY) 
	{	
		showBoxSivunLeveys = document.body.scrollWidth;
	} 
	else if(document.body.scrollWidth > document.body.offsetWidth)
	{
		showBoxSivunLeveys = document.body.scrollWidth;
	} 
	else
	{
		showBoxSivunLeveys = document.body.offsetWidth;
	}
	
	this.showBoxSivunLeveys = showBoxSivunLeveys;
	return this.showBoxSivunLeveys;
}

function ShowBoxHaeSivunKorkeus()
{
	var showBoxSivunKorkeus;
		
	if(window.innerHeight && window.scrollMaxY) 
	{	
		showBoxSivunKorkeus = window.innerHeight + window.scrollMaxY;
	} 
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{
		showBoxSivunKorkeus = document.body.scrollHeight;
	} 
	else
	{
		showBoxSivunKorkeus = document.body.offsetHeight;
	}
	
	this.showBoxSivunKorkeus = showBoxSivunKorkeus;
	return this.showBoxSivunKorkeus;
}

function ShowBoxHaeIkkunanLeveys()
{
	var showBoxIkkunanLeveys;
		
	if(window.innerWidth) 
	{
    	showBoxIkkunanLeveys = window.innerWidth;
    } 
	else if(document.documentElement && document.documentElement.clientWidth) 
	{
    	showBoxIkkunanLeveys = document.documentElement.clientWidth;
	} 
	else if(document.body && document.body.clientWidth) 
	{
    	showBoxIkkunanLeveys = document.body.clientWidth;
  	}
	
	return showBoxIkkunanLeveys;
}

function ShowBoxHaeIkkunanKorkeus()
{
	var showBoxIkkunanKorkeus;
	
	if(window.innerHeight) 
	{
    	showBoxIkkunanKorkeus = window.innerHeight;
	} 
	else if(document.documentElement && document.documentElement.clientHeight) 
	{
    	showBoxIkkunanKorkeus = document.documentElement.clientHeight;
	} 
	else if(document.body && document.body.clientHeight) 
	{
    	showBoxIkkunanKorkeus = document.body.clientHeight;
  	}
	
	return showBoxIkkunanKorkeus;
}
function ShowBoxHaeVaakaScrolli()
{
	var showBoxVaakaScrolli;

	if(typeof(window.pageYOffset) == 'number') 
	{
		showBoxVaakaScrolli = window.pageXOffset;
	} 
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) 
	{
		showBoxVaakaScrolli = document.body.scrollLeft;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
	{
		showBoxVaakaScrolli = document.documentElement.scrollLeft;
	}
	
	this.showBoxVaakaScrolli = showBoxVaakaScrolli;
	return this.showBoxVaakaScrolli;
}

function ShowBoxHaePystyScrolli()
{
	var showBoxPystyScrolli;

	if(typeof(window.pageYOffset) == 'number') 
	{
		showBoxPystyScrolli = window.pageYOffset;
	} 
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) 
	{
		showBoxPystyScrolli = document.body.scrollTop;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
	{
		showBoxPystyScrolli = document.documentElement.scrollTop;
	}
	
	this.showBoxPystyScrolli = showBoxPystyScrolli;
	return this.showBoxPystyScrolli;
}
