/* Menu functions */

function initMenu(oTarget, sPrefix, aItems, picLoc)
{
	
    if(document.getElementById(oTarget)) {	/* Lasse added 17.8.2006  */

	oTarget = document.getElementById(oTarget);		

	// Disable link
	oTarget.childNodes[0].onclick = function(){return false;};
	
	var oMenuTemp	= document.createElement('div');
	oMenuTemp.className	= "divMenu " + oTarget.id;
	
	//	Valikot ylempänä Mozillaa varten
	/*
	if (!document.all && !window.opera && document.getElementById)
		oMenuTemp.style.top	= "10px";
	*/
		
	oMenuTemp.id	= oTarget.id +"Menu";
	
	for (var iI=0;iI<aItems.length;iI++)
	{
		var	oTemp	= document.createElement('a');
		oTemp.className	= "aMenu";
		if (iI == aItems.length - 1) {
			oTemp.className	+= " last";
		}
		
		if(aItems[iI][1].substring(0,7) == "http://")
		{
			oTemp.href	= aItems[iI][1];
			oTemp.target = "_blank";
		}
		else
		{
			oTemp.href	= sPrefix + aItems[iI][1];
		}
		
		if(aItems[iI][1].indexOf("/virtEs") != -1)
		{
			oTemp.onclick = (function(){if (this.href.indexOf("grand") != - 1)
																		open(this.href,'oW','');
																	else
																		open(this.href,'oW','width=641,height=440');
																	return false;});
		}
		
		oTemp.title	= aItems[iI][0];
		oTemp.onmouseover	= handleTimeout;
		oTemp.onmouseout	= function(e)
		{
			handleMenu(e,oMenuTemp);
		}
		if(aItems[iI][2] != null)
		{
			oTempImg = document.createElement('img');
			oTempImg.src = picLoc + aItems[iI][2];
			oTempImg.alt = aItems[iI][0];
			oTemp.appendChild(oTempImg);
		} else {
			oTemp.appendChild(document.createTextNode(aItems[iI][0]));
		}
		
		oMenuTemp.appendChild(oTemp);
	}
	
	if(oTarget.parentNode.parentNode.id == "navi") {
		oTarget.parentNode.appendChild(oMenuTemp);
	}
	else {
		oTarget.appendChild(oMenuTemp);
	}
	
	oTarget.onmouseover	= function (e)
	{
		handleMenu(e,oMenuTemp);
	}
	oTarget.onmouseout	= function (e)
	{
		handleMenu(e,oMenuTemp);
	}
    }
}

function handleTimeout()
{
	try
	{
		clearTimeout(toOver);
	}
	catch(e)
	{
		return false;
	}
}

function handleMenu(e,oMenuTemp)
{
	oMenu	= oMenuTemp;
	
	// Nasty hack to hide old menu
	try
	{
		if(oMenu != oOldMenu)
		{
			oOldMenu.style.display	= "none"
		}
	}
	catch(e) {}
	
	oOldMenu = oMenu;
	
	var e	= (document.all)?window.event:e;

	if (e.type == 'mouseover')
	{
		setOver(true);
		handleTimeout();
	}
	else
	{
		handleTimeout();
		toOver	= setTimeout('setOver(false)',250);
	}
}

function setOver(bIsOver)
{
	oMenu.style.display	= (bIsOver)?"block":"none";
}


/* window onload function */

function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
	  	oldonload(); 
			func(); 
	  } 
	} 
}

function printPage(){

	if(window.print()) 
		window.print();
	/*

	document.getElementById("top").style.display = "none";
	document.getElementById("navi").style.display = "none";
	if(document.getElementById("tulostusHattu"))
		document.getElementById("tulostusHattu").style.display = "block";

	// hide RR_Logo
	if(document.getElementById("RRLogo"))
		document.getElementById("RRLogo").style.display = "none";


	//resize #header, #container, #produced
	var printWidth = "725px";
	
	if(document.getElementById("header"))
		document.getElementById("header").style.width = printWidth;	
	if(document.getElementById("container"))
		document.getElementById("container").style.width = printWidth;
	if(document.getElementById("produced"))
		document.getElementById("produced").style.width = printWidth;
		
	if(document.getElementById("bottom"))
		document.getElementById("bottom").style.marginLeft = "0px";	
	
	if(window.print()) 
		window.print();

	// REFRESH CONTENTS
	// document.location = document.location;

	*/
}
