
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);

var HoverBox = {
    navUrl : null,
    timeout : null,
    lastSelected : null,
    setSelected : function (obj) {
        setLayer(obj.id,"selected_box");
    },
    showSelected : function (event,obj,url) {
        if (contains(obj, event) && ( (this.lastSelected != obj) || (this.lastSelected == null)) ) {
            // If our mouse pointer is contained within our selected obj and our selected obj is null or 
            // our selected object has changed
            navUrl = url;
            setLayer(obj.id);
            this.lastSelected = obj;
            event.cancelBubble = true; // this will ensure that our parent div will now call onmouseover            
        }
        else // otherwise.. hide the thing
            this.hideSelected();        
    },
    hideSelected : function (lyrname) {
        this.lastSelected = null;
        if (lyrname == null) lyrname = "overlay_box";
        if ($get(lyrname).style.display == 'none') {          
        } else {           
           hideBox();
        }
    },
    navigate : function() {
        if (navUrl != null)
            window.location = navUrl;
        else
            alert('navUrl cannot be null');
    }
}

function setLayer(objId,lyrname){
    var obj = $get(objId);   
	var coors = findPos(obj);
	if (lyrname == null) lyrname = "overlay_box";
	var x = $get(lyrname);
	
	// no change needed right now for the different browsers
	if (browserName == "Netscape" || browserName == "Firefox") {   
        x.style.top = (coors[1]) + 'px';
    } else {
        x.style.top = (coors[1]) + 'px';
    }
	
	x.style.left = (coors[0] -15 )+ 'px';
	
	if (x.style.display == 'none')
	    x.style.display = 'block';

    setSize(obj,lyrname);	    
}

function hideBox(lyrname) {
	if (lyrname == null) lyrname = "overlay_box";
    var box = $get(lyrname);
    box.style.display = 'none';
}

function setSize(obj,lyrname){
    if (lyrname == null) lyrname = "overlay_box";
    var box = $get(lyrname);
    var height = obj.offsetHeight;   
    box.style.height = height + 'px';
}

function findPos(obj) {
	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];
}

function contains(div, event) {    

    var objCoords = findPos(div);
    var objCoord_x = objCoords[0]; // left
    var objCoord_y = objCoords[1]; // top
    var mouse_x = mouseX(event);
    var mouse_y = mouseY(event);
    var divHeight = div.offsetHeight;
    var divWidth = div.offsetWidth;
    
    var max_mouse_x = objCoord_x + divWidth;    
    var max_mouse_y = objCoord_y + divHeight;
    
    if ( ((mouse_x >= objCoord_x) && (mouse_y >= objCoord_y)) &&
        ((max_mouse_x >= mouse_x) && (max_mouse_y >= mouse_y))
       ){    
        return true;
    }  
    return false;
}
function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}
