// JavaScript Document

window.onload=function(){	 
	 init();
}

function init(){
	posMetaNav();
	loadMenu();
}

function posMetaNav(){
	var metanav = document.getElementById('metanav');
	var navcol = document.getElementById('navcol_inner');
	var navcolBtm = findPosY(navcol) + navcol.offsetHeight;
	if(navcol.offsetHeight < 195){
		var metaNavTp = findPosY(navcol) + 195 + 'px';
	}else{
		var metaNavTp = navcolBtm +'px';
	}
	metanav.style.left = 0;
	metanav.style.top = metaNavTp;
	metanav.style.visibility = 'visible';
}

function loadMenu(){
	findMenuitems();
}

function findMenuitems(){
	var menuContainer =  document.getElementById('menu');
	var menuLinks = menuContainer.getElementsByTagName('a');
	addEventsToLinks(menuLinks);
}

var tmr;
function addEventsToLinks(obj){
	for(var i=0; i < obj.length; i++){		
		obj[i].onmouseover=function(){showTitle(this.parentNode.id);};		
		obj[i].onmouseout=function(){tmr = setTimeout(hideTitle,500);};
	}
}

function showTitle(lnk){
	clearTimeout(tmr);
	var titel =  document.getElementById('menu_title');
	var menuLtr=lnk.substr(lnk.length - 1,1).toLowerCase();
	titel.style.backgroundImage = 'url(images/menu/'+menuLtr+'_titel.gif)';
}

function hideTitle(){
	var titel =  document.getElementById('menu_title');
	titel.style.backgroundImage = 'none';
}



function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return[myWidth, myHeight];
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}else if(obj.y){
		curtop += obj.y;
	}
	return curtop;
}
