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 dropdown(args) {
    this.theDoc = document;
    this.menumouse = false;
    this.is_ie = this.theDoc.all ? 1 : 0;
    this.setDelay = 0;
    this.element = args.element;
    this.navelement = args.navelement;
    this.controller = args.controller;

    var thisObject = this;

    this.hilite = function(elem) {
        //elem.style.background = "";
        //elem.style.border = "";
    }
    this.lolite = function(elem) {
        //elem.style.background = "";
        //elem.style.border = "";
    }


    this.hidemenu = function() {
        try { clearTimeout(thisObject.hideTimeout); } catch(e){}
        if (thisObject.menumouse == true) { 
            thisObject.menumouse = false; 
            thisObject.hideTimeout = setTimeout(thisObject.hidemenu,3000); return false; 
        } else {
            if (thisObject.setDelay == 1) {
                thisObject.element.style.display = 'none';
            }
            thisObject.menumouse = false;
            thisObject.checkChatOut();
        }
    };

    this.checkChatIn = function() {
        try {
            if (!this.is_ie) {
                if (this.theDoc.getElementById('sidebarIframe')) {
                    if (this.navelement.id == 'myaccountnav') {
                        $('sidebarIframe').scrolling='no';
                        $('sidebarIframe').contentDocument.getElementById('handlesearch').style.width='210px';
                    } else if (this.navelement.id == 'blogsnav' || thisObject.navelement.id == 'videopagenav') {
                        $('chatbodyIframe').contentDocument.getElementById('chatlog').scrolling='no';
                    }
                } else if (this.theDoc.getElementById('chatroom')) {
                    if (this.navelement.id == 'myaccountnav') {
                        $('handlesearch').style.width='210px';
                    } else if (this.navelement.id == 'blogsnav' || thisObject.navelement.id == 'videopagenav' || thisObject.navelement.id == 'groupnav') {
                        $('chatroom').style.overflow='hidden';
                    }
                }
            }
        } catch(e) {}
    };

    this.checkChatOut = function() {
        try {
            if (!thisObject.is_ie) {
                if (thisObject.theDoc.getElementById('sidebarIframe')) {
                    if (thisObject.navelement.id == 'myaccountnav') {
                        $('sidebarIframe').contentDocument.getElementById('handlesearch').style.width='150px';
                        $('sidebarIframe').scrolling='no';
                    } else if (thisObject.navelement.id == 'blogsnav' || thisObject.navelement.id == 'videopagenav') {
                        $('chatbodyIframe').contentDocument.getElementById('chatlog').scrolling='';
                    }
                } else if (thisObject.theDoc.getElementById('chatroom')) {
                    if (thisObject.navelement.id == 'myaccountnav') {
                        $('handlesearch').style.width='150px';
                    } else if (thisObject.navelement.id == 'blogsnav' || thisObject.navelement.id == 'videopagenav' || thisObject.navelement.id == 'groupsnav') {
                        $('chatroom').style.overflow='auto';
                    }
                }
            }
        } catch(e) {}
    };

    this.mouseoutHandler = function() {
        if (thisObject.menumouse == false) {
            thisObject.lolite(thisObject.element);
        }
        thisObject.setDelay = 1;
        thisObject.moTimeout = setTimeout(thisObject.hidemenu,500);
    };
    this.mouseoverHandler = function() {
        thisObject.element.style.display = 'block';
        thisObject.menumouse = true;
        thisObject.hilite(thisObject.navelement);
        thisObject.setDelay = 0;
        thisObject.checkChatIn();

    };
    this.navmouseout = function() {
        thisObject.setDelay = 0;
        if (thisObject.menumouse == true) { thisObject.menumouse = false; this.navmoTimeout = setTimeout(thisObject.navmouseout,3000); return false; };
        thisObject.menumouse = false;
        thisObject.element.style.display='none';
        thisObject.lolite(thisObject.navelement);
        thisObject.checkChatOut();
    };

    this.show = function() {
        try { clearTimeout(this.navmoTimeout); } catch(e){}
        try { clearTimeout(this.moTimeout); } catch(e){}
        try { clearTimeout(this.hideTimeout); } catch(e){}
        this.hilite(this.navelement);
            this.setDelay = 0;
            if (this.controller.currMenu) {
                this.controller.currMenu.onmouseout=null;
                this.controller.currMenu.style.display = 'none';
                try { clearTimeout(this.controller.elements[this.controller.currMenu.id].navmoTimeout); } catch(e){}
                try { clearTimeout(this.controller.elements[this.controller.currMenu.id].moTimeout); } catch(e){}
                try { clearTimeout(this.controller.elements[this.controller.currMenu.id].hideTimeout); } catch(e){}
                this.controller.elements[this.controller.currMenu.id].menumouse = false;
                this.controller.elements[this.controller.currMenu.id].navelement.onmouseout();
            }
            this.controller.currMenu = this.element;

            this.checkChatIn();

            this.element.style.display = 'block';
			//begin browser sniffer
	        if (navigator.userAgent.indexOf("MSIE")!=-1){
            this.element.style.left = this.navelement.offsetLeft + 20 + 'px';
			}
			else{
			this.element.style.left = this.navelement.offsetLeft + 5 + 'px';
			}
			//end browser sniffer
            var arr = findPos(this.navelement);
            var offsetHeight = $('navbar').offsetHeight;
            this.element.style.top = (arr[1] + offsetHeight - 4) + 'px';
 

        this.navelement.onmouseout = this.navmouseout;
        this.element.onmouseout = this.mouseoutHandler;
        this.element.onmouseover = this.mouseoverHandler;
    };
    if (this.navelement.addEventListener) {
        this.navelement.addEventListener('mouseover', function() {thisObject.show()}, false);
    } else {
        this.navelement.onmouseover = function() { thisObject.show() };
    }
};



function dropdowns(elementNameList) {
    this.currMenu = null;
    this.elements = new Array();
    for (var i=0;i<elementNameList.length;i++) {
        var pair = elementNameList[i];
        try {
            var dd = new dropdown({ 
                controller: this, 
                navelement: $(pair[0]), 
                element: $(pair[1])
            });
            this.elements[pair[0]] = dd;
            this.elements[pair[1]] = dd;
        } catch(e) {}
    }
}




