﻿function $(id)
{
	return document.getElementById(id)
}
DropDownMenu = function()
{
	this.triggerList = new Array()
	this.menuList = new Array()
	this.timeOut = undefined
	
	this.Show = function(MenuID)
	{
		clearInterval(this.timeOut)
		
		for(var i = 0; i < this.menuList.length; i++)
		{
			$(this.menuList[i]).style.display = 'none'
		}
		
		var menu = $(this.menuList[MenuID])
		var Trigger = $(this.triggerList[MenuID])		
		menu.style.position = 'absolute'		
		menu.style.display = ''
	
	menu.style.left = ((screen.width-700)/2)-110+ 'px'
	}
	
	this.Hide = function(MenuID)
	{
		var menu = this.menuList[MenuID]
		eval("this.timeOut = setTimeout(\"$('" + menu + "').style.display = 'none'\", 500)")
	}
	
	this.Initialise = function(MenuID)
	{
		var Trigger = this.triggerList[MenuID]
		var Menu = this.menuList[MenuID]
	
		if(!$(Trigger) || !$(Menu))
		{
			dropDownMenu = this			
			setTimeout('dropDownMenu.Initialise(' + MenuID + ')', 200)
			return
		}
		
		Trigger = $(Trigger)
		Menu = $(Menu)
		
		Trigger.menu = this
		Menu.menu = this
		
		eval("Trigger.onmouseover = function()" +
		"{" +
			"this.menu.Show(" + (MenuID) + ");this.src='img/menu-produtos2.png'" +
		"}")
		
		eval("Trigger.onmouseout = function()" +
		"{" +
			"this.menu.Hide(" + (MenuID) + ");this.src='img/menu-produtos.png'" +
		"}")
		
		eval("Menu.onmouseover = function()" +
		"{" +
		"	this.menu.Show(" + (MenuID) + "); Trigger.src='img/menu-produtos2.png';" +
		"}")
		
		eval("Menu.onmouseout = function()" +
		"{" +
		"	this.menu.Hide(" + (MenuID) + "); Trigger.src='img/menu-produtos.png'" +
		"}")
		
		Menu.style.display = 'none'		
	}

	this.Add = function(Trigger, Menu)
	{
		this.triggerList.push(Trigger)
		this.menuList.push(Menu)
		
		this.Initialise(this.triggerList.length - 1)
	}
}
