/*
Copyright (c) 2010, Ideal Computer Systems, Inc. All rights reserved.
Author: Wendell Malpas
*/

var IE = /MSIE/.test(navigator.userAgent);
var MOZ = !IE && navigator.product == "Gecko";

var Ideals = {Dropdown:{}};

/**
 * Menu Dropdown
 */
Ideals.Dropdown = {
	isDropDown: false,
    obj: false,
    timeout: 200,
    closetimer: 0,
    ddmenuitem: 0,
	objMenuImg: false,
	objMenuImgPath: false,
	objMenuImgPathHover: false,
    
	show: function(o, contId, menuImgId, menuImgPath, menuImgPathHover) {
		
        this.cancelCloseTime();
        
        if(this.ddmenuitem) this.ddmenuitem.style.display = 'none';
        
        this.ddmenuitem = document.getElementById(o.id + '-list');
        
        var oCont = document.getElementById(contId);
        var oContTop;
        var oContLeft;
        
        if(oCont) {
            oContTop = oCont.offsetTop - oCont.scrollTop;
            oContLeft = oCont.offsetLeft - oCont.scrollLeft;
        }
        else {
            oContTop = 0;
            oContLeft = 0;
        }
        
        if(this.ddmenuitem) {
            this.ddmenuitem.style.display = 'block';
            
            var offsetTop = Math.max(0, (o.offsetTop + 10 + oContTop));
            var offsetLeft = Math.max(0, (o.offsetLeft - this.ddmenuitem.offsetWidth + oContLeft));
            
			this.ddmenuitem.style.top = (IE ? offsetTop + 22 : offsetTop + 3) + "px";
            this.ddmenuitem.style.left = (offsetLeft + 161) + "px";
			
			Ideals.Dropdown.objMenuImgPath = menuImgPath;
			Ideals.Dropdown.objMenuImgPathHover = menuImgPathHover;
            Ideals.Dropdown.objMenuImg = document.getElementById(menuImgId);
			
            this.ddmenuitem.onmouseover = function() {
				Ideals.Dropdown.objMenuImg.src = Ideals.Dropdown.objMenuImgPathHover;
                Ideals.Dropdown.cancelCloseTime();
            }
            this.ddmenuitem.onmouseout = function() {
                Ideals.Dropdown.hide();
            }
            this.ddmenuitem.onmousedown = function() {
                Ideals.Dropdown.hide();
            }
        }
    },
    
    hide: function() {
        this.closetimer = window.setTimeout('Ideals.Dropdown.closemenuitem()', Ideals.Dropdown.timeout);
    },
    
    closemenuitem: function() {
        if(this.ddmenuitem) {
            this.ddmenuitem.style.display = 'none';
			Ideals.Dropdown.objMenuImg.src = Ideals.Dropdown.objMenuImgPath;
        }
    },
 
    cancelCloseTime: function() {
        if(this.closetimer) {
            window.clearTimeout(this.closetimer);
        }
    }
};

/**
 * Extending string prototype
 */
String.prototype.equalsIgnoreCase = function(arg) {
	return (new String(this.toLowerCase())==(new String(arg)).toLowerCase());
}
 
String.prototype.equals = function(arg) {
	return (this.toString()==arg.toString());
}
 
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
}


