var popupElm = null;
var menuTimer = null;

function initJS(){
	// preload image
	/*var menuLinkOvrImg = new Image();
	menuLinkOvrImg.src = "img/menu_bluer.gif";

	for(kk=1; kk<6; kk++){
		document.getElementById('menu' + kk).onmouseover = mOvr;
		document.getElementById('menu' + kk).onmouseout = mOut;
		document.getElementById('menu' + kk).onclick = mClk;
	}

	popupElm = document.getElementById('xpopup');
	popupElm.onmouseover = keepVisible;
	popupElm.onmouseout = timeHidePopup;

	document.onclick = hidePopup;
	*/
}

function mOvr(e){
	var srcElm = null;
	try{
		srcElm = event.srcElement;
	}catch(ex){
		srcElm = e.target;
	}
	if(srcElm.tagName!=='DIV' || !srcElm.id) return false;
	srcElm.className = 'menu-link-ovr';

	if(srcElm.id == 'menu3'){
		clearTimer();
		menuTimer = window.setTimeout("showPopup('" + srcElm.id + "');", 300);
	}else{
		timeHidePopup();
	}
}

function mOut(e){
	var srcElm = null;
	try{
		srcElm = event.srcElement;
	}catch(ex){
		srcElm = e.target;
	}

	if(srcElm.tagName!=='DIV' || !srcElm.id) return false;
	srcElm.className = 'menu-link';

	if(srcElm.id=='menu3' && popupElm.style.visibility=='visible'){
		timeHidePopup();
	}
}

function mClk(e){
	var srcElm = null;
	try{
		srcElm = event.srcElement;
	}catch(ex){
		srcElm = e.target;
	}

	hidePopup();

	if(srcElm.tagName!=='DIV' || !srcElm.id) return false;
	location.href = "index.php?pid=" + srcElm.innerHTML.toLowerCase();
}

function showPopup(elmID){
	var elm = document.getElementById(elmID);
	var elmPos = getAbsolutePos(elm);
	popupElm.style.left = (elmPos.x + 152) + 'px';
	popupElm.style.top = (elmPos.y + 9 ) + 'px';
	popupElm.style.visibility = 'visible';
}

function hidePopup(){
	popupElm.style.visibility = 'hidden';
}

function clearTimer(){
	if(menuTimer) window.clearTimeout(menuTimer);
	menuTimer = null;
}

function keepVisible(){
	if(menuTimer) window.clearTimeout(menuTimer);
	menuTimer = null;
}

function timeHidePopup(){
	clearTimer();
	menuTimer = window.setTimeout("hidePopup();", 250);
}

function getAbsolutePos(elm){
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(elm.tagName);
	if(is_div && elm.scrollLeft) SL = elm.scrollLeft;
	if (is_div && elm.scrollTop) ST = elm.scrollTop;
	var r = { x: elm.offsetLeft - SL, y: elm.offsetTop - ST };
	if(elm.offsetParent){
		var tmp = getAbsolutePos(elm.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function printPage(pageID){
	var w = 760;
	var h = 510;
	var ww = Math.floor((screen.width-w)/2);
	var hh = Math.floor((screen.height-h)/2);
	var adr = "print.php?pid=" + pageID;
	window.open(adr, 'fsprint', 'status=yes,resizable=yes,width='+w+',height='+h+',top='+hh+',left='+ww);
}

//functions used for the vertical menu on the left//

function P7_swapClass(){ 
	var i,x,tB,j=0;
	var tA=new Array();
	var arg=P7_swapClass.arguments;
	if(document.getElementsByTagName){
		for(i=4;i<arg.length;i++){
			tB=document.getElementsByTagName(arg[i]);
			for(x=0;x<tB.length;x++){
				tA[j]=tB[x];
				j++;
			}
		}
		for(i=0;i<tA.length;i++){
			if(tA[i].className){
				if(tA[i].id==arg[1]){
					if(arg[0]==1){
						tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];
					}else{
						tA[i].className=arg[2];
					}
				}
				else if(arg[0]==1 && arg[1]=='none'){
					if(tA[i].className==arg[2] || tA[i].className==arg[3]){
						tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];
					}
				}else if(tA[i].className==arg[2]){
					tA[i].className=arg[3];
				}
			}
		}
	}
	//document.location = 'index.php?pid='+arg[1];
}


function P7_writeStyles(a){ 
 var tS="<sty"+"le type=\"text/css\">";
 tS+="\n"+a+"\n<"+"/sty"+"le>";document.write(tS);
}

