/*----- JS for rolo-img -----*/
function getPos(elm) {
    for(var zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
    return {x:zx,y:zy}
	}
function skjulBillede(){
	document.getElementById("imgbox").visibility="hidden";
	document.getElementById("imgbox").innerHTML ="";
	SwitchVisibility('filterControl_itemGroupDropDownList', 'false');
	SwitchVisibility('filterControl_timeDropDownList', 'false');
	SwitchVisibility('filterLinkListControl_filterDataList', 'false');
}
function VisBillede(obj,sti,myWidth,myHeight){
	var position = getPos(obj);
	var ib = document.getElementById("imgbox");
	ib.style.visibility="visible";
	ib.style.position="absolute";
	ib.style.left = position.x + "px";
	ib.style.top = CalcTopPos(position.y, obj, myWidth, myHeight) + "px";
	ib.innerHTML= " <img src=" + sti + " class='roloimg' width='"+myWidth+"' height='"+myHeight+"' />";
}
function CalcTopPos(yPos, obj, myWidth, myHeight){
	var availHeight = getWindowHeight();
	//var imgPopHeight = getPopupHeight(obj.height, obj.width, myWidth);
	var imgPopHeight = myHeight;
	var scrollY = getScrollY();
	var sum = yPos + obj.height + imgPopHeight - scrollY;
	//alert('yPos + obj.height + imgPopHeight - scrollY\n'+ yPos +' '+ obj.height +' '+ imgPopHeight +' '+ scrollY);
	if (sum > availHeight) {
		//hide filterboxes if popup image covers them 
		if (document.getElementById('filterControl_itemGroupDropDownList') != null) {
			var filterBox = document.getElementById('filterControl_itemGroupDropDownList');
			var posFilterBox = getPos(filterBox);
			if ((yPos - imgPopHeight) < posFilterBox.y) {
				SwitchVisibility('filterControl_itemGroupDropDownList', 'true');
				SwitchVisibility('filterControl_timeDropDownList', 'true');
			}
		}
		return yPos - imgPopHeight;
	}
	else {
		//hide myLists if they are visible and lowest popup image covers it
		if (document.getElementById('filterLinkListControl_filterDataList') != null) {
			var myListBox = document.getElementById('filterLinkListControl_filterDataList');
			var posMyListBox = getPos(myListBox);
			if ((yPos + obj.height + imgPopHeight) > posMyListBox.y) {
				SwitchVisibility('filterLinkListControl_filterDataList', 'true');
			}
		}
		return yPos + obj.height;//136 GKW!!
	}
}
function getPopupHeight(imgHeight, imgWidth, myMaxBottleneck){
	var rel = imgHeight / imgWidth;
	var imgPopHeight;
	
	var imgPopWidth;
	if(imgWidth > imgHeight){
		imgPopWidth = myMaxBottleneck;
		imgPopHeight = (imgPopWidth / imgWidth)*imgHeight;
	}else{
		imgPopHeight = myMaxBottleneck;
		imgPopWidth = (imgPopHeight / imgHeight)*imgWidth;
	}
	/*
	if (imgWidth == 60) {
		imgPopHeight = rel * 160;
	}
	else if (imgWidth == 160) {
		imgPopHeight = rel * 300;
	}
	else {
		//do nothing as its an illegal height
		imgPopHeight = 0;
	}
	*/
	return imgPopHeight;
}
function getWindowHeight() {
	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 myHeight;
}
function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function SwitchVisibility(element, hide) {
	if (document.getElementById(element) != null) {
		if (hide == 'true') {
			document.getElementById(element).style.visibility = 'hidden';
		}
		else {
			document.getElementById(element).style.visibility = 'visible';
		}
		
	}
}
/*-----\JS for rolo-img\-----*/