/*
меняю sim_menu под hitech-gildia
*/

window.SIM.close_all_nodes_old = window.SIM.close_all_nodes;

window.SIM.close_all_nodes = function()
{
	window.SIM.close_all_nodes_old()
	SIM.changeback();
}

window.SIM.change = function(item_obj)
{
	if (hasClass(item_obj, 'p'))
	{
		SIM.changeback();
		newClass = 'ch' + item_obj.id.charAt(1);
		var re =  /(^|\s)(p)(\s|$)/       // находим "p"
           item_obj.className = item_obj.className.replace(re, '$1'+newClass+'$3')  // меняем "p" на newClass
	}
	//для меню на главной странице
	if(document.getElementById("indexPage"))
	{
		if(item_obj.id !== '') 
		{
			document.getElementById(item_obj.id).style.backgroundImage = "url(/data/media/images/index/menu/"+ item_obj.id + ".gif)"; 
		}
	}
		
}
window.SIM.changeback = function()
{
	i = 0;
	j = i+1;
	var rr = [];
	while(document.getElementById('p'+j))
	{    
	    id= 'p'+j;
		rr[i] = document.getElementById(id);
		rr[i].className = "sim_item nobg p";
		//для главной страницы
		if(document.getElementById("indexPage")) 
		{ rr[i].style.backgroundImage = "url(/data/media/images/index/menu/first/"+ id + ".gif)"; }
		i++;
		j++;			
	}
}
window.SIM.itemover = function(item_obj) 
{
	SIM.change(item_obj);
	var sub_obj = this.relations[item_obj.sim_id]['submenu'];
	var parent_obj = this.relations[item_obj.sim_id]['parent'];
	
	while (this.opened_nodes.length)
	{
		if (parent_obj && parent_obj.sim_id == this.opened_nodes[this.opened_nodes.length-1].sim_id) {break;} 
		this.hide_show_selects(this.opened_nodes[this.opened_nodes.length-1], false);
		this.opened_nodes[this.opened_nodes.length-1].style.display = 'none';
		this.opened_nodes.pop();
	}
	
	this.hide_show_selects(parent_obj, true);
	
	if (sub_obj)
	{
		var orientation = sub_obj.getAttribute('orientation');
		var new_left = 0; var new_top = 0;
		if (orientation == 'bottom') { new_left = this.get_left(item_obj); new_top = (this.get_top(parent_obj) + parent_obj.offsetHeight); }
		//добавил отступа слева
		else { new_left = (this.get_left(parent_obj) + 10 + parent_obj.offsetWidth); new_top = this.get_top(item_obj); }
		sub_obj.style.left = new_left + 'px';
		sub_obj.style.top = new_top + 'px';
		this.hide_show_selects(sub_obj, true);
		this.opened_nodes.push(sub_obj);
		sub_obj.style.display = 'block';
		/* Ширина вложенных блоков
		if (sub_obj.offsetWidth < parent_obj.offsetWidth) { sub_obj.style.width = (parent_obj.offsetWidth) + 'px'; }
		else { sub_obj.style.width = (sub_obj.offsetWidth) + 'px'; }*/
	}
}

function hasClass(elem, className) 
{
	return new RegExp("(^|\\s)"+className+"(\\s|$)").test(elem.className) 
}


