/* Copyright (c) 2008 Astronim* (astronim.com) */

$(document).ready(function(){
	initMenuVars();		
		menuTopChange(); /////////////////////

	// расскраска таблицы
	//$("#content table.tbl tr > td:last-child").addClass("last");
	$("#content tr:nth-child(even)").addClass("chet");

	$('#poll .inner1 .header').click(
		function(){
			if (!$('#poll .inner2').is(':visible')){
				$('#poll').addClass( 'opened' );
			} else {
				$('#poll').removeClass( 'opened' );
			}
			if ($('#search .inner2').is(':visible')){
				$('#search').removeClass( 'opened' );
			}
		return false;
	});
	
	$('#search .inner1 .header').click(
		function(){
			if (!$('#search .inner2').is(':visible')){
				$('#search').addClass( 'opened' );
			} else {
				$('#search').removeClass( 'opened' );
			}
			
			if ($('#poll .inner2').is(':visible')){
				$('#poll').removeClass( 'opened' );
			}
			
		return false;
	});
						   
			
});

/*
$(window).resize(function(){
	initMenuVars();		
});
*/
function initMenuVars(){
	menuFirstHeight = $('#menuFirst').height(); // запоминаем высоту менюшки    !обновлять после ресайза окна
	menuSecondHeight = $('#menuSecond').height(); // запоминаем высоту менюшки    !обновлять после ресайза окна
	menuFirstLengthHalf = parseInt($('#menuFirst td').length/2); // вычислять  кол-во пунктов в меню, делить на 2 и округлять
	menuSecondLengthHalf = parseInt($('#menuSecond td').length/2); // вычислять  кол-во пунктов в меню, делить на 2 и округлять
			
	$('#menuFirst .item ul').css('top', menuFirstHeight-15); // позиционируем подменюшки.    !обновлять после ресайза окна
	$('#menuSecond .item ul').css('top', menuFirstHeight-15); // позиционируем подменюшки.    !обновлять после ресайза окна
	
}


function menuTopChange(){
	var widthT = $("#menuFirst table").width();
	var widthA = 0;
	var count = $("#menuFirst .item>a").length;

	$("#menuFirst .item>a").each(function(){
        widthA += $(this).width();
    });

	var paddingTd = (widthT-widthA)/count;

	$("#menuFirst td").each(function(){
        $(this).width( $('.item>a', this).width()+paddingTd);
    });

	//
	var widthT = $("#menuSecond table").width();
	var widthA = 0;
	var count = $("#menuSecond .item>a").length;

	$("#menuSecond .item>a").each(function(){
        widthA += $(this).width();
    });

	var paddingTd = (widthT-widthA)/count;

	$("#menuSecond td").each(function(){
        $(this).width( $('.item>a', this).width()+paddingTd);
    });

}


function OpenFirstMenu (  ) {
	$('#sloganFirst').animate({left :0}, 0);
	$('#sloganFirst').addClass( "current" );
	$('#sloganSecond').removeClass( "current" );
	
	$('#menuFirst').show();
	$('#menuSecond').hide();
	
	$('#visCenter').hide();
}


function OpenSecondMenu (  ) {
	$('#sloganSecond').animate({right :0}, 0);
	$('#sloganFirst').removeClass( "current" );
	$('#sloganSecond').addClass( "current" );
	
	$('#menuFirst').hide();
	$('#menuSecond').show();
	
	$('#visCenter').hide();
}

function wo(link,ww,hh,title) {
	w=window.open(link,'',(ww ? 'width='+ww+',' : '')+(hh ? 'height='+hh+',' : '')+'toolbar=0,scrollbars=0,resizable=yes');
	if (link.indexOf('.html')==-1) {
		if (document.layers) title='';
		w.document.open();
		w.document.write('<html><head><title>'+title+'</title><meta http-equiv=Content-Type content="text/html; charset=windows-1251"></head>');
		w.document.write('<body bgcolor=white marginwidth=0 marginheight=0 topmargin=0 leftmargin=0><table width=100% height=100% border=0 cellspacing=0 cellpadding=0><tr><td align=center><img src='+link+' width='+ww+' height='+hh+' border=0 alt=""></td></tr></table></body></html>');
		w.document.close();
	}
	w.focus();
}

