function showOverlay(dv){

    cleanUpOverlay();
    
    var div = $(dv);
    
    if(div.className != "overlay") {
        alert("Element must have the class type of overlay to function.");
    } else {
        div.style.display = "block";
    
        //reposition the div
        var dw = div.clientWidth;
        var dh = div.clientHeight;
        
        if(dw==0) dw=700;
        if(dh==0) dh=400;
        
        var yLoc = this.mouseY;
        if(document.all) { yLoc += document.documentElement.scrollTop; }
        
        dw = (findLivePageWidth() - dw)/2;
        dh = yLoc - (dh/2);
        
        if(!dh || dh<105) dh = 105;
        if(!dw || dw<0) dw = 0;
        
        div.style.left = dw + "px";
        div.style.top  = dh + "px";
    }
}

function showOverlayXY(dv, x, y){

    cleanUpOverlay();
    
    var div = $(dv);
    
    if(div.className != "overlay") {
        alert("Element must have the class type of overlay to function.");
    } else {
    
        div.style.display = "block";
    
        //reposition the div
        var dw = div.clientWidth;
        var dh = div.clientHeight;
        
        if(dw==0) dw=700;
        if(dh==0) dh=400;
        
        dw = (findLivePageWidth() - dw)/2;
        dh = (findLivePageHeight() - dh)/2;
        
        if(dh<105) dh = 105;
        if(dw<0) dw = 0;
        
        div.style.left = ((x>0)?x:dw) + "px";
        div.style.top  = ((y>0)?y:dh) + "px";
    }
}

function hideOverlay(dv){
    $(dv).style.display = "none";
}

function cleanUpOverlay(){ 
    overlays = document.getElementsByTagName("div");
    for(i=0;i<overlays.length;i++){
        if(overlays[i].className == "overlay" && overlays[i].style.display != "none"){
            hideOverlay(overlays[i].id);
        }
    }
}

function findLivePageHeight() {
    if (window.innerHeight) return window.innerHeight;
    if (document.body.clientHeight) return document.body.clientHeight;
    return (null);
}

function findLivePageWidth() {
    if (window.innerWidth) return window.innerWidth;
    if (document.body.clientWidth) return document.body.clientWidth;
    return (null);
}
