function MainMenuSelectCat(name,doClick)
{
	var o;
	if( o=getObj("MenuCat"+name))
	{	
		if( o.parent)
		{
			if( doClick && o.parent.m_url)
				window.location.href = o.parent.m_url;
			else
			if (o.parent.m_isSelected == false)
			{
		
				MainMenuUnselectAllCat();
				o.parent.M_select();
			}
		}	
	}
}
function MainMenuCategoryClick(name)
{
	MainMenuSelectCat(name,true);

}


function MainMenuCatOver()
{	if(this.parent){
		if (this.parent.m_isSelected == false)
			$(this).addClass = 'over';
	}
}

function MainMenuCatOut()
{
	if(this.parent){
		if (this.parent.m_isSelected == false)
			$(this).removeClass = 'over';
	}
}



function MainMenuUnselectAllCat()
{
	var i;
	for (i=0;i<mainMenuCatList.length;i++)
		mainMenuCatList[i].M_unselect();

}




function MainMenuCategory(name,icArray,url)
{
	this.m_id = "MenuCat"+name;
	this.m_el 			= getObj(this.m_id);
	this.m_items 		= getObj(this.m_id + "_items");
	if( this.m_el) this.m_isSelected 	= $(this.m_el).is("on") ? true : false;
	this.m_itemsList	=  icArray;
	this.m_url			= url;

	/*
	var i,itemsLi;
	itemsLi  =  (this.m_items.getElementsByTagName("ul"))[0].getElementsByTagName("li");

	for(i=0;i<icArray.length; i++)
	{
		icArray[i].M_init(this,itemsLi[i]);
	}
	*/
		
	
	// Install handlers for category
if(this.m_el)
{
	this.m_el.parent		= this;
	this.m_el.onmouseover 	= MainMenuCatOver;	
	this.m_el.onmouseout 	= MainMenuCatOut;	
	this.m_el.onclick		= MainMenuCategoryClick;
}
	// M_select
	this.M_select = function()
	{
		if(this.m_el)
		{
			$(this.m_el).addClass("on");
			this.m_isSelected = true;
			this.m_items.style.display = "block";
		}	
	}

	// M_unselect
	this.M_unselect = function()
	{
		if(this.m_el)
		{
		$(this.m_el).removeClass("on");
		this.m_isSelected	= false;
		this.m_items.style.display = "none";
		}
	}

	// M_selectItem
	this.M_selectItem = function(id)
	{	var s,i
		for(i=0;i<this.m_itemsList.length; i++)
		{	if (o=this.m_itemsList[i])
			{	if(o.item && (o.item.m_id==id))
				{	o.className 	= 'menuSelected';
					o.isSelected	= true;
					o.item.M_show(true);
				}
			}
		}
	}
}
function MainMenuItem(id,title,link)
{
	this.m_id		= id;
	this.m_title	= title;
	this.m_cat		= null;
	this.m_obj		= null;
	this.M_init		= function(cat,obj)
	{	
		this.m_cat	= cat;
		this.m_obj	= obj;
		var as,a
		if( as=this.m_obj.getElementsByTagName("a")) {a=as[0];}
		if(a)
		{	a.obj = this;
		}
	}
	this.M_click = function()
	{
		alert('click '+this.m_title);
	}
}
function ItemClick(a)
{
	alert(a);
	if(a.obj)
		a.obj.M_click();
}
