// -*-c-*-
var g_timer_id;

function onTimeOut(id) {
	elm = document.getElementById(id);
	elm.style.visibility='hidden';
}

function resetTimeout () {
	 try{
		window.clearTimeout(g_timer_id);
		g_timer_id = 0;
	} catch (ex) {}
}

function startTimeout (id, timeOut) {
	 g_timer_id = window.setTimeout("onTimeOut('" + id + "');", timeOut);
}

function showThumb(window_id, sender, content, url, width)  {
	/*
	 * string window_id  - id til hover-vinduet
	 * object sender     - elementet som skal ha hoved vindu
	 * string content    - innhold i hoved-vinduet
	 * string url        - url ved klikk i vindu
	 *
	 */
      
	if (g_timer_id) {
		resetTimeout ();
	}
     elm = document.getElementById(window_id);
     elm.style.visibility='hidden';

     elm.style.left  = 100 + "px";
     elm.style.top   = 100 + "px";
     // elm.style.width = width  + "px";
 	
     sender.onmouseout = function () { startTimeout(window_id, 150)  };
     
     var ihtml = "<div style=\"valign: top;\"  ";
     // var ihtml = "<div style=\"valign: top; x-width: " + width + "px\" ";
     ihtml = ihtml + "onMouseOut=\"startTimeout('" + window_id +  "', 150);\" ";
     ihtml = ihtml + "onMouseOver=\"resetTimeout();\" ";
     
     if (url.length > 0) {
          ihtml = ihtml + "onClick=\"window.open('"+ url +"', '_self');\" ";
     }
     
     ihtml = ihtml + '><img align="top" src="/delt/ikon/venstre.gif"><img style="border: 2px solid #a0a0a0;" src="'+ content +'"/></div>';
     
     elm.innerHTML = ihtml;
     
     var oBo = compute_bbox (sender);
     var oBp = compute_bbox (elm);
     
     // Under
     //elm.style.left = (oBo.l) + "px";
     //elm.style.top =  (oBo.b+2)  + "px";
       
     // venstre
     //elm.style.border = '2px solid lightgray';
     elm.style.left = (oBo.r + 5   ) + "px";
     elm.style.top =  (oBo.t )  + "px";

     elm.style.visibility = '';

}

function bbox(x,y,w,h)
{
     this.l=x;
     this.r=x+w;
     this.t=y;
     this.b=y+h;
}

function compute_bbox(o)
{
     var b=new bbox(0,0,0,0);
     if(!o) return b;
     var x=0,y=0,p=o;
     while(p) {
          x+=p.offsetLeft;
          y+=p.offsetTop;
          p=p.offsetParent;
     }
     b.l=x;
     b.t=y;
     b.r=x+o.offsetWidth;
     b.b=y+o.offsetHeight;
     return b;
}
