﻿
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){

    var screenTop;
    var screenBottom;

    // Get Screen Top
    if( self.pageYOffset ) {
        screenTop= self.pageYOffset;
    } 
    else if( document.documentElement && document.documentElement.scrollTop ) {
        screenTop = document.documentElement.scrollTop;
    } else if( document.body ) {
        screenTop = document.body.scrollTop;
    }

    // Get Screen Bottom
    if( self.innerHeight ) {
        screenBottom = screenTop + self.innerHeight;
    } 
    else if( document.documentElement && document.documentElement.clientHeight ) {
        screenBottom = screenTop + document.documentElement.clientHeight;
    } 
    else if( document.body ) {
        screenBottom = screenTop + document.body.clientHeight;
    }

    if (document.getElementById){
    var subobj=document.getElementById(subobjstr)
    subobj.style.display=(subobj.style.display!="block")? "block" : "none"
    var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
    var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : -1 * subobj.offsetHeight)



    if (opt_position!="undefined" && opt_position.indexOf("bottom")!=-1){
        if (ypos + subobj.offsetHeight > screenBottom){
            ypos = getposOffset(curobj, "top") + (-1 * subobj.offsetHeight)
        }    
    }
    else {
        if (ypos < screenTop){
            ypos = getposOffset(curobj, "top") + curobj.offsetHeight
        }    
    }

    subobj.style.left=xpos+"px"
    subobj.style.top = ypos + "px"
    subobj.style.zIndex = 9999
    return false
    }
    else
    return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

