var global_ilto = false;
var global_illto = false;


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function hand(obj){
	obj.style.cursor = 'pointer';
}



// CHANGED: showInfoGrafik
function showInfoGrafik(elem, header, content, link, additionalCSSClass, alignLeft) {
	if(global_ilto){
		window.clearTimeout(global_ilto);
	}
	if(global_illto){
		window.clearTimeout(global_illto);
	}
	
	function findPos(obj){ // find xy on screen
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
	        curleft = obj.offsetLeft;
	        curtop = obj.offsetTop;
	        while (obj = obj.offsetParent) {
	            curleft += obj.offsetLeft;
	            curtop += obj.offsetTop;
	        }
	    }
	    return [curleft,curtop];
	};
	
	var koo = findPos(elem);
	var x = koo[0]+(0) + (alignLeft ? -265 : elem.offsetWidth + 5) + 'px';
	var y = koo[1]+(7) +  'px';
		
	text = '<div class="info_grafik_layer ' + (additionalCSSClass ? additionalCSSClass : '') + '"><div class="info_grafik_layer_top"><img src="/sources/img/meta/transparent.gif" height="27" width="257"></div><div class="info_grafik_layer_center"><div class="info_grafik_layer_content">';
	text += content;
	text += '</div></div><div class="info_grafik_layer_header">';
	text += header;
	text += '</div>';
if(link!=""){
	text += '<div class="info_grafik_layer_link">';
	text += link;
	text += '</div>';
}
	text += '<div class="info_grafik_layer_bottom"><img src="/sources/img/meta/transparent.gif" height="17" width="257"></div></div>';	
	
	MM_changeProp('infoBoxLayer','','style.top',y,'DIV');
	MM_changeProp('infoBoxLayer','','style.left',x,'DIV');
	MM_changeProp('infoBoxLayer','','style.visibility','visible','DIV');
	MM_changeProp('infoBoxLayer','','innerHTML', text, 'DIV');	
	
	var iblayer = document.getElementById('infoBoxLayer');
	
	elem.onmouseout = function(){
		global_ilto = window.setTimeout(function(){closeInfoGrafik()}, 500);
	}
	
   	iblayer.onmouseover = function(){
		if(global_ilto){
			window.clearTimeout(global_ilto);
			this.onmouseover = function(){
				if(global_illto){
					window.clearTimeout(global_illto);
				}
			}
		}
		
		this.onmouseout = function(e){
			// http://www.quirksmode.org/js/events_mouse.html
			if (!e) var e = window.event;
			//	var tg = (window.event) ? e.srcElement : e.target;
			var tg = this;
			if (tg.nodeName != 'DIV') return;
				var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
				if(reltg && reltg.nodeName != "xul:nativescrollbar"){
				while (reltg != tg && reltg.nodeName != 'BODY'){				
					reltg= reltg.parentNode
					if (reltg== tg) return;
				
			}	
			// Mouseout took place when mouse actually left layer
			// Handle event
			global_illto = window.setTimeout(closeInfoGrafik, 500);
		}
	}        

}	
}

function closeInfoGrafik(){
	//onmouseout
	MM_changeProp('infoBoxLayer','','style.visibility','hidden','DIV');
}



function showInfoBox(image_filename, header, content) {
		
	//y = (positionY < 400) ? 400 + "px" : positionY + "px";
	
	if (document.all){
		y = (positionY+10+document.body.scrollTop) + "px";
		x = (positionX+10+document.body.scrollLeft) + "px";
	}
	else{
		y = (positionY+10) + "px";
		x = (positionX+10) + "px";
	}
	
	
	if(window.location.href.indexOf("tarifoptionen") != -1){
		var firstParentTop = document.getElementById('bestCountryInfo').offsetParent.offsetTop;
		var secondParentTop = document.getElementById('bestCountryInfo').offsetParent.offsetParent.offsetTop;
		var firstParentLeft = document.getElementById('bestCountryInfo').offsetParent.offsetLeft;
		var secondParentLeft = document.getElementById('bestCountryInfo').offsetParent.offsetParent.offsetLeft;
		var tipTopSpacing = 19;
		var tipLeftSpacing = 36;
		
		y = firstParentTop+secondParentTop+tipTopSpacing+"px";
		x = firstParentLeft+secondParentLeft+tipLeftSpacing+"px";
	}

	/*text = '<div class="infoBoxDivJS">';

	if ( image_filename != null && image_filename.substr(image_filename.lastIndexOf('/')+1) != '' ) {
				text = '<div style="margin-bottom: 10px;border:solid 1px #666666; background-color:#F7F7F7; width:171px;"><img src="' +image_filename+ '"><div style="padding: 5px;">';
		}
	text += '<div class="boldInfo">'+header+'</div><div class="content">'+content+'</div>';
	text += '</div></div>';*/

	text = '<div class="top"></div>';
	text += '<div class="content">';
	if ( image_filename != null && image_filename.substr(image_filename.lastIndexOf('/')+1) != '' ) {
		text += '<img src="' +image_filename+ '">';
	}
	text += '<h3>'+header+'</h3>';
	text += '<p>'+content+'</p>';
	text += '<div style="display:none;">x: '+x+'; y: '+y+'; '+window.location.href+'</div>';
	text += '</div><div class="bottom"></div>';

	MM_changeProp('infoBoxLayer','','style.top',y,'DIV');
	MM_changeProp('infoBoxLayer','','style.left',x,'DIV');
	MM_changeProp('infoBoxLayer','','style.visibility','visible','DIV');
	MM_changeProp('infoBoxLayer','','innerHTML', text, 'DIV');	
}

function hideInfoBox(infoBoxId)
{
	//onmouseout
	MM_changeProp('infoBoxLayer','','style.visibility','hidden','DIV');
}

var positionY = 0;
var positionX = 0;
function Mausbewegung (Ereignis) {
	if (!Ereignis) {
		Ereignis = window.event;
	}
	if (document.all) {
		positionY  = document.documentElement.scrollTop + Ereignis.clientY;
		positionX  = document.documentElement.scrollLeft + Ereignis.clientX;
	} 
	else { 
		if (document.getElementById) {
    			positionY  = Ereignis.pageY;
    			positionX  = Ereignis.pageX;
  		}
	}
}

document.onmousemove = Mausbewegung;






function showInfoGrafikOnKlickmap(elem, header, content, top, left) {
	if(global_ilto){
		window.clearTimeout(global_ilto);
	}
	if(global_illto){
		window.clearTimeout(global_illto);
	}
	
	function findPos(obj){ // find xy on screen
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
	        curleft = obj.offsetLeft;
	        curtop = obj.offsetTop;
	        while (obj = obj.offsetParent) {
	            curleft += obj.offsetLeft;
	            curtop += obj.offsetTop;
	        }
	    }
	    return [curleft,curtop];
	};
	
	var koo = findPos(elem);;
	var x = koo[0]+(10)+left + 'px';
	var y = koo[1]+(7)-(10)+top + 'px';	
		
	text = '<div class="info_grafik_layer"><div class="info_grafik_layer_top"><img src="/sources/clear.gif" height="27" width="257"></div><div class="info_grafik_layer_center"><div class="info_grafik_layer_content">';
	text += content;
	text += '</div></div><div class="info_grafik_layer_header">';
	text += header;
	text += '</div>';
	text += '<div class="info_grafik_layer_bottom"><img src="/sources/clear.gif" height="17" width="257"></div></div>';	

	MM_changeProp('infoBoxLayer','','style.top',y,'DIV');
	MM_changeProp('infoBoxLayer','','style.left',x,'DIV');
	MM_changeProp('infoBoxLayer','','style.visibility','visible','DIV');
	MM_changeProp('infoBoxLayer','','innerHTML', text, 'DIV');	
	
	var iblayer = document.getElementById('infoBoxLayer');
	
	elem.onmouseout = function(){
		global_ilto = window.setTimeout(function(){closeInfoGrafik()}, 500);
	}
	
   	iblayer.onmouseover = function(){
		if(global_ilto){
			window.clearTimeout(global_ilto);
			this.onmouseover = function(){
				if(global_illto){
					window.clearTimeout(global_illto);
				}
			}
		}
		
		this.onmouseout = function(e){
			// http://www.quirksmode.org/js/events_mouse.html
			if (!e) var e = window.event;
			//	var tg = (window.event) ? e.srcElement : e.target;
			var tg = this;
			if (tg.nodeName != 'DIV') return;
				var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
				if(reltg && reltg.nodeName != "xul:nativescrollbar"){
				while (reltg != tg && reltg.nodeName != 'BODY'){				
					reltg= reltg.parentNode
					if (reltg== tg) return;
				
			}	
			// Mouseout took place when mouse actually left layer
			// Handle event
			global_illto = window.setTimeout(closeInfoGrafik, 500);
		}
	}        

}	
}
