var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0
var mouseX;
var mouseY;
var pageBottom;
var tooltip= "tooltip";

function getpos(e)
{
    if(!e)
    {
        var e = window.event||window.Event;	
    }
        
	if(!ie) 
	{				
		if('undefined'!=typeof e.pageX)
		{
			mouseX = e.pageX;
			mouseY = e.pageY;
		}	
		else 
		{
			mouseX = e.clientX + document.body.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop;		
		}

	} 	
	else 
	{
		// Explorer	
		mouseX = e.pageX; 

        if ('undefined' == typeof mouseX)
            mouseX = event.clientX;
            
		if ('undefined' == typeof mouseX)
		    mouseX = event.screenX;
	    
		if( document.body && document.body.scrollTop ) 
		{
		    //DOM compliant
		    mouseY = e.clientY + document.body.scrollTop;
		}
		else if( document.documentElement && document.documentElement.scrollTop ) 
		{
            //IE6 standards compliant mode
            mouseY =  e.clientY + document.documentElement.scrollTop;           
        }
        else
        {
            mouseY = e.clientY;
        }

	}


//    if(document.getElementById(tooltip).style.visibility == 'visible') {
//		// Flytter
//		document.getElementById(tooltip).style.top = flip(document.getElementById(tooltip).clientHeight,mouseY);
//		document.getElementById(tooltip).style.left = mouseX+15;
//	}
	
}

// You need to tell Mozilla to start listening:
if(window.Event && document.captureEvents) 
{  
    document.captureEvents(Event.MOUSEMOVE);
}
	
// Then assign the mouse handler
document.onmousemove = getpos;


function flip(h,m) 
{
    pageBottom=document.body.offsetHeight + document.body.scrollTop;
	 	
	var elementBottom = m + h;
	
	if( elementBottom >  pageBottom)
	{
	    m = m - h;
	}
	
	return m;
}

function Activate()
{
	document.getElementById(tooltip).style.top = flip(document.getElementById(tooltip).clientHeight, mouseY) + "px";
	document.getElementById(tooltip).style.left = (mouseX + 15) + "px";
	document.getElementById(tooltip).style.visibility = 'visible';	

	//setOpacity(document.getElementById(tooltip), 0);
    fadeIn(tooltip,0);
}

function deActivate()
{
    document.getElementById(tooltip).style.visibility = 'hidden';
}

function EnterContent(o,t)
{
	TTitle = o;
	TContent = t;
    ContentInfo = '<div class="div-tooltip-wrapper">'+    
    '<div class="div-popup-heading">' + TTitle + ':' + '</div>' +
    '<div class="div-popup-content">' + TContent + '</div>';
    

    document.getElementById(tooltip).innerHTML = ContentInfo;
}


function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function fadeIn(objId,opacity) 
{
  if (document.getElementById) 
  {
    obj = document.getElementById(objId);
    if (opacity <= 100) 
    {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 1);
    }
  }
}
