jQuery(function()
{
	
	// шаблон в snippets/_under_top_menu.html - формируется подменю
	// при загрузке стр. скрываю все подменюшки  
	$('.SubMenuContainer div').hide();
	
	// показываем подменю пункта выбранного в главным меню
	$(document).ready(function(){
		var idmain = $('.MenuContainer li.active').attr("rel");
		var hidemenu = '.SubMenuContainer div[rel=\''+ idmain +'\']';
		$(hidemenu).show();
		});
	
	$('#top_logo').click(function(){
		each_li_menu();
		
	});
	// находит все выделенные пункты меню и передает их this на ф-цию которая гасит подсветку
	function each_li_menu() {
		$(".MenuContainer li[rel].active").each(function(i,elem) {
			del_sel_menu(this);
	    })
	} 
	
	// подсветка менюшки, указанного пункта меню
	function sel_menu(obj) {
		var text1 = $(obj).children('a').html();
		$(obj).children('a').html('');
		var new_a = '<div class="MiddleMenu"><div class="LeftMenu"><div class="RightMenu">' + text1 + '</div></div></div>';
		$(obj).children('a').append(new_a);
		$(obj).removeClass("nonactive");
		$(obj).addClass("active");
	}
	
	// убираем подсветку указанного пункта меню
	function del_sel_menu(obj) {
		var text2 = $(obj).children('a').find('.RightMenu').html();
		var texth = $(obj).children('a').attr("href");
		$(obj).removeClass("active");
		$(obj).addClass("nonactive");
		$(obj).children('a').children('div').remove();
		$(obj).children('a').html(text2);
	}
	
	// ховер по ГЛАВНОМУ МЕНЮ
	$(".MenuContainer li[rel]").hover(
	function(){
		// убираем подсветку всех пунктов меню
		each_li_menu();
		/*  отображаю тот див с подмею в котором rel == rel в основном меню */
		var idmain = $(this).attr("rel");
		var hidemenu = '.SubMenuContainer div[rel!=\''+ idmain +'\']';
		$(hidemenu).hide();
		var hidemenu = '.SubMenuContainer div[rel=\''+ idmain +'\']';
		$(hidemenu).show();
		// подсветка меню под шапкой
		if ($(this).attr("class") == 'nonactive' ) {
			sel_menu(this);
		}
	},
	function(){
			del_sel_menu(this);
	}		
	
	);
	
	// ховер на подменю
	$('.SubMenuContainer div').hover(
	function(){     
		$(this).show();
		var idmain = $(this).attr("rel");
		var hidemenu = '.MenuContainer li.nonactive[rel=\''+ idmain +'\']';
		var obj = $(hidemenu);
		sel_menu(obj);
	}, 
	function(){
				//$(this).fadeOut();
				//$('.SubMenuContainer').hide();
			}
	)
	
	// левая менюшка 
	
	$(function(){
		$("#accordion").accordion({
			collapsible: true, 
		    active: false, 
		    autoHeight: false,
		    event: 'onclick',
			navigation: true,
			animated: false
		});	
	});
	 

});

function wop(url, width, height)
{
//	width = width + 30;
//	height = height + 30;
	var w = window.open('', '', 'width=' + width +', height=' + height + ',status=no,menubar=no,resizable=yes,scrollbars=no');
//	width = width - 30;
//	height = height - 30;
	w.document.write('<html><head><title>ФОТО</title></head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><style type="text/css">a img { width: 100%; }</style><table border="0" align="center" height="100%" cellspacing="0" cellpadding="0"><tr><td align=center><a href=\'javascript:window.close();\' ><img border="0" alt="Закрыть окно" src="' + url + '"></a></td></tr></table></body></html>');
	w.focus();
}




