//***************************
// DropdownMenu Constructor *
//***************************
function CS_DropdownMenu(menu_wrapper_node, timer_interval)
{
	// settings
	this.timer_interval	= !timer_interval ? 0 : timer_interval;
	
	// get id's
	this.menu_wrapper	= document.getElementById(menu_wrapper_node);
	this.menu			= this.menu_wrapper.getElementsByTagName('ul')[0];

	// set strings
	this.hover_class	= 'cs_hover';
	this.active_class	= 'active';
	
	this.stored_class	= '';
	
	// initialize menu object
	this.init();
}

//***************************
// Function initialize menu *
//***************************
CS_DropdownMenu.prototype.init = function()
{
	var _this = this;
	
	for (a=0; a<this.menu.childNodes.length; a++)
	{
		var item_node = this.menu.childNodes[a];
		
		if (item_node.nodeName == 'LI')
		{
			// call recursive function
			this.toggleSubMenu(item_node);
		}
	}
}

//**************************
// Function toggle submenu *
//**************************
CS_DropdownMenu.prototype.toggleSubMenu = function(submenu_item_node)
{
	var _this = this;
	
	var submenu = submenu_item_node.getElementsByTagName('ul')[0];
	
	if(submenu)
	{
		submenu_item_node.onmouseover = function()
		{
			if (this.className.length > 0)
			{
				_this.stored_class = this.className;
			}
			
			// show submenu
			this.className	= _this.hover_class;
			
			// set active anchor
			var anchor_node	= this.getElementsByTagName('a')[0];
			if (anchor_node) anchor_node.className	= _this.active_class;
		}
		
		submenu_item_node.onmouseout = function()
		{
			
			// hide submenu
			this.className = _this.stored_class.length > 0 ? _this.stored_class : '';
			
			// set in-active anchor
			var anchor_node	= this.getElementsByTagName('a')[0];
			if (anchor_node) anchor_node.className	= '';
			
			_this.stored_class = '';
		}
		
		// check for sub child items
		var submenu_items 		= submenu.getElementsByTagName('li');
		var total_submenu_items	= submenu_items.length;
		
		if (total_submenu_items)
		{
			for (b=0; b<total_submenu_items; b++)
			{
				var submenu_item = submenu_items[b];
				
				var subsubmenu = submenu_item.getElementsByTagName('ul')[0];
				
				if(subsubmenu)
				{
					submenu_item.onmouseover = function()
					{
						// show submenu
						this.className	= _this.hover_class;
						
						// set active anchor
						var anchor_node	= this.getElementsByTagName('a')[0];
						if (anchor_node) anchor_node.className	= _this.active_class;
					}
					
					submenu_item.onmouseout = function()
					{
						// hide submenu
						this.className = '';
						
						// set in-active anchor
						var anchor_node	= this.getElementsByTagName('a')[0];
						if (anchor_node) anchor_node.className	= '';
					}
				}
				
				// call recursive function
				//this.toggleSubMenu(submenu_item);
			}
		}
	}
}
