
var B_NS4 = (document.layers) ? true : false;
var B_IE = (document.all) ? true : false;
var B_DOM = (document.getElementById) ? true : false;
var B_MAC = (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? true : false);
var dElements = new Array();
var dElementOn = null;
var dLinkOn = null;
var dLinkImg = null;
var HDiv = 0;
var openInfoWindow;


function imgChgWCtrOn(Obj, naviObj, onImageUrl, offImageUrl){

        if(dLinkOn == Obj) {
		clearInterval(HDiv);
		return;
	}

        imgChg(Obj, onImageUrl);

        ctrDivOn(naviObj);
//		lastMenuItem = Obj;

	dLinkOn = Obj;
	dLinkImg = offImageUrl;

        /* hack for hiding the navi select in ie */
		if (B_IE && (typeof(document.forms['topNaviForm'])=="object") && ((Obj=="link0") || (Obj=="link1")))
                document.forms['topNaviForm'].style.visibility="hidden";

}

function imgChgWCtrOff(naviObj){
        ctrDivOff(naviObj);
}


function imgChg(Obj, imageUrl){
		TImg = document.images['linkImg'+Obj.replace("link","")];
		if(TImg) {
			TImg.src=imageUrl;
		}
}	


function hideDiv(Obj) {
        clearInterval(HDiv);
        setVar(Obj,'visibility','"hidden"');
        if (typeof(document.forms['topNaviForm'])=="object")
			document.forms['topNaviForm'].style.visibility="inherit";
        clearLink();
        dElementOn = null;
}

function clearLink() {
	if(dLinkOn == null)
		return;
	imgChg(dLinkOn, dLinkImg);
	dLinkOn = null;
	dLinkImg = null;
}


function setVar(ele,val,val2) {
	switch(val) {
		case "top" : val = (document.all ? "pixelTop" : "top");
			break;
		case "left" : val = (document.all ? "pixelLeft" : "left");
			break;
		default : val="visibility";
			break;
	}
	eval("document."+(B_IE ? "all." : (B_DOM ? "getElementById('" : ""))+ele+(B_DOM && !B_IE ? "')" : "")+(B_DOM || B_IE ? ".style" : "")+"."+val+"="+val2);
}

function getVarInt(ele,val) {
	switch(val) {
		case "top" : val = (document.all ? "pixelTop" : "top");
			break;
		case "left" : val = (document.all ? "pixelLeft" : "left");
			break;
		default : val="visibility";
			break;
	}
	if (!B_IE) {
		return(parseInt(eval("document."+(B_IE ? "all." : (B_DOM ? "getElementById('" : ""))+ele+(B_DOM && !B_IE ? "')" : "")+(B_DOM || B_IE ? ".style" : "")+"."+val).replace("px","")));
	}
	else {
		return(parseInt(eval("document."+(B_IE ? "all." : (B_DOM ? "getElementById('" : ""))+ele+(B_DOM && !B_IE ? "')" : "")+(B_DOM || B_IE ? ".style" : "")+"."+val)));
	}
}

function mouseOnElement(parent, thisElement, thisElementNo, colorOn) {
	/* user has mouse on some navigation element. Make sure parent element stays visible */
	clearInterval(HDiv);
	dElementOn = parent;
	changeColorScheme(thisElement, thisElementNo, colorOn);
}

function mouseOffElement(parent, thisElement, thisElementNo, colorOff, image, imageUrl) {
	/* user took mouse off some navigation element. Make parent element disappear quickly */
	dElementOn = parent;
	HDiv = setInterval('hideDiv("'+parent+'", "'+image+'", "'+imageUrl+'")',450);
	changeColorScheme(thisElement, thisElementNo, colorOff);
}

function setDElement(Obj){
	dElements[dElements.length] = Obj;	
}

function dLoadElements(){
	var i;
	for (i = 0;i < dElements.length; i++) {
		dLoad(dElements[i]);
	}
}	

/* processing to be done when page loads or is resized. With current fixed layout, 
no specific need but kept here for the sake of ease of expansion later*/
function dLoad(Obj) {
	setVar(Obj,'visibility','"hidden"');				 				 																									
}

function ctrDivOn(Obj) {
	/* shut down previously lit menu */
	if (dElementOn != null) {
		setVar(dElementOn,'visibility','"hidden"');
		if (typeof(document.forms['topNaviForm'])=="object")
			document.forms['topNaviForm'].style.visibility="inherit";
	        clearLink();
	}
	clearInterval(HDiv);
	/* set this visible and register it for shutdown */
	setVar(Obj,'visibility','"inherit"');
	dElementOn = Obj;
}

function ctrDivOff(Obj) {
	/* set automatic shutdown, give enough time for the user to move mouse on top of nav bar */
	dElementOn = Obj;
	HDiv = setInterval('hideDiv("'+Obj+'")',850);
}


function changeColorScheme(layerID, layerNo, bgColor) {
	layer = getLayerReference(layerID,"document.layers['" + layerNo + "']");
	if (B_DOM || B_IE) {
		layer.style.backgroundColor = bgColor;
	}
 	if (B_NS4) {
 		layer.bgColor = bgColor;
	}
}

function getLayerReference(layerID, referenceNS) {
	var layer;

	/* For IE5 and NS6 */
	if (B_DOM) {
		layer = document.getElementById(layerID);
	/* For NS4 */
	} else if (B_NS4) {
		if (referenceNS.length == 0) {
			layer = findNSLayer(document, layerID);
			if (layer == -1) layer = null;
		}	else layer = eval(referenceNS);
	/* For IE4 */
	} else if (B_IE) {
		layer = eval("document.all['" + layerID + "']");
	}
	
	return layer;
}


function findNSLayer(doc, id) {
	var idCounter=0;
	var returnVal=-1;
	var thisId;
	var re;
	
	re = new RegExp("^" + id + "$");
	
	while( (returnVal == -1) && (idCounter < doc.layers.length) ) {	
		thisId = doc.layers[idCounter].id;
		if (re.test(thisId) == true) {
			returnVal = eval(doc.layers[idCounter]);
		} else {
			returnVal = findNSLayer(doc.layers[idCounter].document, id);
		}
		idCounter++;
	}
	
	return returnVal;
}

function openGalleryPop(title, width, height, screenX, screenY, openerjsp, picOid, collectionOid, picWidth, picHeight) {

	var features =
		'width='        + width +
		',height='      + height +
		',screenX='		+ screenX +
		',left='		+ screenX +
		',screenY='		+ screenY +
		',top='			+ screenY +
		',directories=' + 'no' +
		',location='    + 'no' +
		',menubar='     + 'no' +
		',scrollbars='  + 'no' +
		',status='      + 'no' +
		',toolbar='     + 'no' +
		',resizable='   + 'no';
      
	var location = 
		openerjsp + 
		'?picOid=' + picOid + 
		'&collOid=' + collectionOid + 
		'&picWidth=' + picWidth + 
		'&picHeight=' + picHeight;

	window.open(location,title,features);
}


function openInfoPop(title, width, height, screenX, screenY, targetpage) {

        width = 370;
        height = 370;

	var features =
		'width='        + width +
		',height='      + height +
		',screenX='		+ screenX +
		',left='		+ screenX +
		',screenY='		+ screenY +
		',top='			+ screenY +
		',directories=' + 'no' +
		',location='    + 'no' +
		',menubar='     + 'no' +
		',scrollbars='  + 'yes' +
		',status='      + 'no' +
		',toolbar='     + 'no' +
		',resizable='   + 'yes';
        
	var location = targetpage + '?wHeight=' + height;

	if (typeof(openInfoWindow) == "object")
		openInfoWindow.close();
		
	openInfoWindow = window.open(location,title,features);
}

function openJobPop(url) {
	var nw = window.open(url,'hakemus','width=650,height=650,screenX=21,screenY=40,scrollbars=yes,toolbar=yes');
}

function openPopUp(location, name, width, height, screenX, screenY) {

	var features =
		'width='        + width +
		',height='      + height +
		',screenX='		+ screenX +
		',left='		+ screenX +
		',screenY='		+ screenY +
		',top='			+ screenY +
		',directories=' + 'no' +
		',location='    + 'no' +
		',menubar='     + 'no' +
		',scrollbars='  + 'no' +
		',status='      + 'no' +
		',toolbar='     + 'no' +
		',resizable='   + 'no';
      

	window.open(location,name,features);
}
function openPopUpScroll(location, name, width, height, screenX, screenY) {

	var features =
		'width='        + width +
		',height='      + height +
		',screenX='		+ screenX +
		',left='		+ screenX +
		',screenY='		+ screenY +
		',top='			+ screenY +
		',directories=' + 'no' +
		',location='    + 'no' +
		',menubar='     + 'no' +
		',scrollbars='  + 'yes' +
		',status='      + 'no' +
		',toolbar='     + 'no' +
		',resizable='   + 'yes';
      

	window.open(location,name,features);
}

