var current, block, toHide;

$( document ).ready( function() {
	// определяем текущий развернутый блок 
	current = $( "#" + $( "div.menu_inner:visible" ).attr( "id" ).replace( "block_", "elem_" ) );
	current.find( "img:first" ).attr( "src", "/images/ukaz_up.gif" );
	
	//меняем картинку на "-" для развернутого блока под-меню
	$( "div.sub_menu:visible" ).parent().find( "img:first" ).attr( "src", "/images/minus.gif" );
	
	$( "tr.top_expander" ).click( function() {
		// Обработка клика на разделе меню
		// блок, на который кликнулм
		block = $( "#" + $(this).attr( "id" ).replace( "elem_", "block_" ) );
		
		if( block.css( "display" ) == "none" ) {
			// если свернут - разворачиваем
			// прячем развернутый список
			toHide = $( "#" + current.attr( "id" ).replace( "elem_", "block_" ) );
			current.find( "img:first" ).attr( "src", "/images/ukaz_niz.gif" );
					
			toHide.slideUp( 
				500, 
				function() { 
					// сворачиваем все развернутые списки под-меню
					current = $( "#" + block.attr( "id" ).replace( "block_", "elem_" ) ); 
					$( this ).find( "img.expander" ).parent().find( "div.sub_menu" ).css( "display", "none" );
					$( this ).find( "img.expander" ).attr( "src", "/images/plus.gif" );
			} );
			
			// открываем тот, на который кликнули
			block.slideDown( 500 );
			$( this ).find( "img:first" ).attr( "src", "/images/ukaz_up.gif" );
		}
		else {
			// прячем блок, на который кликнули
			block.slideUp( 
				500, 
				function () {
					// сворачиваем все развернутые списки под-меню
					$( this ).find( "img.expander" ).parent().find( "div.sub_menu" ).css( "display", "none" );
					$( this ).find( "img.expander" ).attr( "src", "/images/plus.gif" );
			} );
			
			$( this ).find( "img:first" ).attr( "src", "/images/ukaz_niz.gif" );
		}
	} );
	
	
	$( "img.expander" ).click( function() {
		// обработкак клика на под-меню
		var expander = $( this ).parent();
		
		if( expander.find( "div.sub_menu" ).css( "display" ) == "none" ) {
			// разворачиваем, если был свернут
			expander.find( "div.sub_menu" ).slideDown( "slow" );
			expander.find( "img:first" ).attr( "src", "/images/minus.gif" );
		}
		else {
			// сворачиваем, если был развернут
			expander.find( "div.sub_menu" ).slideUp( "slow" );
			expander.find( "img:first" ).attr( "src", "/images/plus.gif" );
		}
	} );
	
	$( "a.expander" ).click( function() {
		$( this ).parent().find( "img.expander" ).trigger( 'click' );
	} );
	
	// обработка элемента меню текущей страницы
	$( "a.selected" ).attr( "href", "javascript:void();" );
	$( "a.selected" ).css( "color", "#f00" );
} );






 function cssmenuhover()
{
        if(!document.getElementById("cssmenu"))
                return;
        var lis = document.getElementById("cssmenu").getElementsByTagName("LI");
        for (var i=0;i<lis.length;i++)
        {
                lis[i].onmouseover=function(){this.className+=" iehover";}
                lis[i].onmouseout=function() {this.className=this.className.replace(new RegExp(" iehover\\b"), "");}
        }
}
if (window.attachEvent)
        window.attachEvent("onload", cssmenuhover);
