﻿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])
		
		var pos = GetElementPosition(Trigger)
		
		menu.style.position = 'absolute'
		menu.style.top = pos.y + pos.height + 'px'
		menu.style.left = pos.x + 'px'
		
		menu.style.display = ''
	}
	
	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) + ")" +
		"}")
		
		eval("Trigger.onmouseout = function()" +
		"{" +
			"this.menu.Hide(" + (MenuID) + ")" +
		"}")
		
		eval("Menu.onmouseover = function()" +
		"{" +
		"	this.menu.Show(" + (MenuID) + ")" +
		"}")
		
		eval("Menu.onmouseout = function()" +
		"{" +
		"	this.menu.Hide(" + (MenuID) + ")" +
		"}")
		
		Menu.style.display = 'none'
		Menu.style.position = 'absolute'
	}

	this.Add = function(Trigger, Menu)
	{
		this.triggerList.push(Trigger)
		this.menuList.push(Menu)
		
		this.Initialise(this.triggerList.length - 1)
	}
}