/************ CSS file linking ***************/
var winW = 0, winH = 0;
if (typeof( window.innerWidth ) == 'number') {
	//Non-IE
	winW = window.innerWidth;
	winH = window.innerHeight;
}
else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	//IE 6+ in 'standards compliant mode'
	winW = document.documentElement.clientWidth;
	winH = document.documentElement.clientHeight;
}
else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
	//IE 4 compatible
	winW = document.body.clientWidth;
	winH = document.body.clientHeight;
}
if (winW > 1045) {
	document.write('<link rel="stylesheet" type="text/css" href="/css/style2.css" />');
}
else {
	document.write('<link rel="stylesheet" type="text/css" href="/css/style.css" />');
}
/*********************************************/


var thisPage = 'foo';
var language = 'fi';

function setLanguage(lang) {
	language = lang;
}

function setThisPage(name) {
	chgImg(name+'_img', name+'-on.gif');
	thisPage = name;
	menuLayers.show(name,null);
}

function chgImg(imgId, filename) {
	var naviImgDir = (language=='en')? '/img/navi_en/' : '/img/navi/';
	var elem = document.getElementById(imgId);
	if (!elem) return false;
	if (imgId != thisPage+'_img') {
		var newSrc = naviImgDir + filename;
		elem.src = newSrc;
	}
}

function subNaviOn(imgId, evt) {
	menuLayers.show(imgId, evt);
}

function subNaviOff(imgId) {
	menuLayers.hide();
}

var menuLayers = {
	timer: null,
	activeMenuID: null,
	show: function(id, e) {
		var mnu = document.getElementById? document.getElementById(id): null;
		if (!mnu) return;
		this.activeMenuID = id;
		if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
		if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
		this.position(mnu);
	},
  
	hide: function() {
		this.clearTimer();
		if (this.activeMenuID && document.getElementById) {
			this.timer = setTimeout("hideMenu('"+menuLayers.activeMenuID+"')", 100);
		}
	},

	position: function(mnu) {
		this.timer = setTimeout("showMenu('"+menuLayers.activeMenuID+"')", 100);
	},

	mouseoutCheck: function(e) {
		e = e? e: window.event;
		var mnu = document.getElementById(menuLayers.activeMenuID);
		var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
		if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
	},

	contained: function(oNode, oCont) {
		if (!oNode) return;
		while ( oNode.parentNode ) {
			oNode = oNode.parentNode;
			if ( oNode == oCont ) return true;
		}
		return false;
	},

	clearTimer: function() {
		if (menuLayers.timer) clearTimeout(menuLayers.timer);
		if (menuLayers.activeMenuID) showMenu(menuLayers.activeMenuID);
	}

}

function showMenu(id) {
	var elem = document.getElementById(id);
	if (!elem) return false;
	elem.style.visibility = "visible";
	if(document.getElementById(id+"_img").onmouseover) document.getElementById(id+"_img").onmouseover.call();
}

function hideMenu(id) {
	var elem = document.getElementById(id);
	if (!elem || id==thisPage) return false;
	elem.style.visibility = "hidden";
	if(document.getElementById(id+"_img").onmouseout) document.getElementById(id+"_img").onmouseout.call();
}

function openDBWin(url) {
	return !window.open(url,'DBWin', '');
}