var menu =
{
	'timer' : false,
	'visible' : false,
	'trigger' : false,
	'classname' : false,
	'block' :  false,
	'initialised' : false,
	'show' : function (the_trigger, the_drop_down)
	{
		this.init(the_trigger);
		
		ref = document.getElementById(the_drop_down);

		if (ref)
		{
			ref.style.display = 'block';
		}

		if (document.getElementById(the_trigger))
		{
			if (this.trigger.parentNode.className.indexOf('hi') == -1)
			{
				document.getElementById(the_trigger).parentNode.className += 'hi';
			}
		}
	},
	'hide' : function (the_drop_down)
	{
		ref = document.getElementById(the_drop_down);

		if (ref)
		{
			ref.style.display = 'none';
			menu.off();
		}
	},
	'set_timeout' : function (the_drop_down)
	{
		this.timer = window.setTimeout('menu.hide("'+the_drop_down+'")', 500);
	},
	'clear_timeout' : function (the_trigger)
	{
		this.init(the_trigger);
		this.on();
		window.clearTimeout(this.timer);
	},
	'on' : function ()
	{
		if (this.trigger.parentNode.className.indexOf('hi') == -1 && !this.block)
		{
 			this.trigger.parentNode.className += ' hi';
		}
	},
	'off' : function ()
	{
		if (!this.block && this.trigger)
		{
			if (this.trigger.parentNode)
			{
				this.trigger.parentNode.className = this.classname;
			}
		}

		this.initialised = false;
	},
	'init' : function (the_trigger)
	{
		if (!this.initialised)
		{
			this.trigger = document.getElementById(the_trigger);
			this.classname = document.getElementById(the_trigger).parentNode.className;
			this.block = (this.trigger.parentNode.className.indexOf('hi') > -1) ? true : false;
			this.initialised = true;
		}
	}
};

var menu_rules = {
	'a#trigger-nav-buy' : function (element)
	{
		element.onmouseover = function ()
 		{
			menu.hide('nav-rent');
			menu.hide('nav-rent-buy');
			menu.hide('nav-bg-info');
			menu.clear_timeout(element.id);
			menu.show(element.id, 'nav-buy');
		}

		element.onmouseout = function ()
		{
			menu.set_timeout('nav-buy');
		}
	},

	'a#trigger-nav-rent' : function (element)
	{
		element.onmouseover = function ()
 		{
			menu.hide('nav-buy');
			menu.hide('nav-rent-buy');
			menu.hide('nav-bg-info');
			menu.clear_timeout(element.id);
			menu.show(element.id, 'nav-rent');
		}

		element.onmouseout = function ()
		{
			menu.set_timeout('nav-rent');
		}
	},

	'a#trigger-nav-rent-buy' : function (element)
	{
		element.onmouseover = function ()
 		{
			menu.hide('nav-buy');
			menu.hide('nav-rent');
			menu.hide('nav-bg-info');
			menu.clear_timeout(element.id);
			menu.show(element.id, 'nav-rent-buy');
		}

		element.onmouseout = function ()
		{
			menu.set_timeout('nav-rent-buy');
		}
	},

	'a#trigger-nav-bg-info' : function (element)
	{
		element.onmouseover = function ()
 		{
			menu.hide('nav-buy');
			menu.hide('nav-rent');
			menu.hide('nav-rent-buy');
			menu.clear_timeout(element.id);
			menu.show(element.id, 'nav-bg-info');
		}

		element.onmouseout = function ()
		{
			menu.set_timeout('nav-bg-info');
		}
	},

	'a.menu-item' : function (element)
	{
		element.onmouseover = function ()
		{
			menu.clear_timeout('trigger-'+element.parentNode.parentNode.parentNode.id);
		}

		element.onmouseout = function ()
		{
			menu.set_timeout(element.parentNode.parentNode.parentNode.id);
		}
	 }
};

Behaviour.register(menu_rules);
