
var timeOn = null;

var offsetleft = 0;
var offsettop = 5;
var delay = 400;
var tempbgcolor;
var lastitem;
var allitems = Array();

// MENU MOUSE OVER 
function menuOver(id, parent, subid) 
{	
	if (lastitem != parent)
	{
		//alert(lastitem);
		if (lastitem)
		{
			changeObjectVisibility(lastitem, 'none');
		}
		//hide(lastitem);
		if (parent == 'undefined')
		{
			hideAllMenus();
		}
	}
	
	if(subid)
	{
		displaySubmenu(id,subid);
		if(allitems.indexOf(subid) === -1)
		{
			allitems.push(subid);
		}
		lastitem = subid;
	}
	clearTimeout(timeOn);
}

// MENU MOUSE OVER RIGHT
function menuOverRight(id, parent, subid) 
{	
	if (lastitem != parent)
	{
		//alert(lastitem);
		if (lastitem)
		{
			changeObjectVisibility(lastitem, 'none');
		}
		//hide(lastitem);
		if (parent == 'undefined')
		{
			hideAllMenus();
		}
	}
	
	if(subid)
	{
		displaySubmenuRight(id,subid);
		if(allitems.indexOf(subid) === -1)
		{
			allitems.push(subid);
		}
		lastitem = subid;
	}
	clearTimeout(timeOn);
}

// MENU MOUSE OUT 
function menuOut(eDiv) 
{
 	timeOn = setTimeout("hideAllMenus()", delay);
}
	 
function displaySubmenu(eParent,subid)
{
	var x = getElementLeft(eParent) + offsetleft;
	var y = getElementTop(eParent) + getElementHeight(eParent) + offsettop;
	moveXY(subid, x, y); 

    getObject(subid).style.zIndex = 501;

	changeObjectVisibility(subid, 'block');
    
    if(MSIE)
	{
        resizeFixMSIE('FixMSIE', subid);
    }  
}

function displaySubmenuRight(eParent,subid)
{
	var x = getElementLeft(eParent) + offsetleft;
	var y = getElementTop(eParent) + getElementHeight(eParent) + offsettop;
    x -= 120; 
	moveXY(subid, x, y); 
    
    getObject(subid).style.zIndex = 501;

	changeObjectVisibility(subid, 'block');
    
    if(MSIE)
	{
        resizeFixMSIE('FixMSIE', subid);
    }  
}

function hideAllMenus()
{
    hideFixMSIE();  
	for (i=0; i<allitems.length; i++)
	{
        getObject(allitems[i]).style.zIndex = 500;
		changeObjectVisibility(allitems[i], 'none');
	}
}



/* Get the last element from the array */
if (typeof Array.prototype.getLast == "undefined") {
    Array.prototype.getLast = function() {
        return this[this.length-1];
    }
}


/* Finds the index of the first occurence of item in the array, or -1 if not found */
if (typeof Array.prototype.indexOf == "undefined") {
    Array.prototype.indexOf = function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return i;
            }
        }
        return -1;
    }
}

/* Check whether array contains given string */
if (typeof Array.prototype.contains == "undefined") {
    Array.prototype.contains = function(s) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === s) {
                return true;
            }
        }
        return false;
    }
}