itm = 0;
topMenu = 0;
lft = 0;
inr_div_height = 190;
is_showed = 0;
var AC_FL_RunContent = 0;
$(document).ready(function(){


	/*footer && loader height*/
	setHeight();

	/*I HATE YOU, BILL!!!*/
	if (navigator.userAgent.search("MSIE")!=-1){
		$(document).pngFix();
	}


	$("#loader").animate({
		opacity: 0.8
	});


	if (navigator.userAgent.search("MSIE 7")!=-1){
		$("#body #container").css('height', $("#second #content").height()+280+'px');
	}

	if (navigator.userAgent.search("MSIE 6")!=-1){

		$("#loader").hide();
	}
	else{

		$("#loader").fadeOut('normal');
	}

	/*Menu*/

	$("#menu #level1 li div.menu").hover(function(){
		is_showed = 1;
	},
	function(){
		if (is_showed==1){
			hideMenu();
		}
	}
	);

	$("#menu #level1 li>a").click(function(){
		if (itm != $(this).parent('li').attr('class')){
			$(this).addClass('selected');
			hideMenu();

			itm = $(this).parent('li').attr('class');

			if (navigator.userAgent.search("MSIE 6")!=-1){
				$(this).parent('li').find('div.menu_bg').show();
				$(this).parent('li').find('div.menu').show();

			}
			else{
				$(this).parent('li').find('div.menu_bg').fadeIn('fast');
				$(this).parent('li').find('div.menu').fadeIn('fast');

			}
		}
		else{
			$(this).removeClass('selected');
			$("#menu #level1 li>div").hide();
			itm = 0;
		}


	});

	/*Move submenu*/
	$("#menu #level1 li div.up>a").click(function(){
		if (topMenu >= 0){
			return;
		}

		topMenu+=50;
		/*if (navigator.userAgent.search("MSIE 6")!=-1){
		$(this).parent("div").next("div.inner").children('div').css('margin-top', topMenu+'px');
		}
		else{*/
		$(this).parent("div").next("div.inner").children('div').animate({
			marginTop: topMenu+"px"
		}, 750 );
		//}



	});

	$("#menu #level1 li div.down>a").click(function(){
		var inr;
		inr = ($("#menu #level1 li."+itm+">div.menu>div.inner>div").height());
		
		if ((inr-inr_div_height+topMenu) < 0){
			return;
		}
		topMenu-=50;
		/*if (navigator.userAgent.search("MSIE 6")!=-1){
		$(this).parent("div").prev("div.inner").children('div').css('margin-top', topMenu+'px');
		}
		else{*/
		$(this).parent("div").prev("div.inner").children('div').animate({
			marginTop: topMenu+"px"
		}, 750 );
		//}

	});


	/*Ajax*/
	$("a.ajax").click(function(){
		return goPage(this);
	});


	/*search*/

	$("#search input.s_button").click(function(){
		goSearch(this);
		return false;

	});


});

function setHeight(){
	var h;
	var i;
	var i2;
	var c;
	h = screen.height-285;

	if ($("#body #container #main #inner").height()){
		setMenu(0);

		/*Ебанный ie7 не выравнивает по высоте*/
		if (navigator.userAgent.search("MSIE 7")!=-1){
			$("#body #container").css('height', $("#second #content").height()+100+'px');
		}

		i = h-($("#body #container #main #inner").height()+302);
		if (i<0){
			return;
		}
		$("#body #container #main #footer").css('padding-top', i+'px');

	}
	else{
		setMenu(-5);

		/*Ебанный ie7 не выравнивает по высоте*/
		if (navigator.userAgent.search("MSIE 7")!=-1){
			$("#body #container").css('height', $("#second #content").height()+280+'px');
		}


		i2 = h-($("#second #content").height()+100);
		if (i2<0){
			return;
		}
		$("#body #container #second #inner_footer").css('padding-top', i2+'px');


	}





	if (navigator.userAgent.search("MSIE 7")!=-1 || navigator.userAgent.search("MSIE 6")!=-1)
	{

		$("#body #container #main").css('height', h+'px');


	}
	else{
		$("#body #container #main").css('min-height', h+'px');

	}


	$("#body #container #loader").css('height', h-100+'px');


}
function goPage(el){
	var to;
	hideMenu();

	$("#loader").show();
	$('#main').html('');

	to = $(el).attr('href');

	$.post(to,{direct:'false'},function(data){
		$('#main').html(data.page);

		/*fucking microsoft*/
		if (navigator.userAgent.search("MSIE")==-1)
		{
			$("title").html(data.title);
		}

		showPage();


	}, "json");

	return false;
}

function goSearch(){
	var to;
	hideMenu();

	if ($("#head #search #textsearch").val().length<=3){
		alert (mes_no_search);
		return false;
	}


	to = $("#head #search form").attr('action');
	$("#loader").show();
	$('#main').html('');

	$.post(to,{direct:'false', textsearch:$("#head #search #textsearch").val()},function(data){
		$('#main').html(data.page);

		/*fucking microsoft*/
		if (navigator.userAgent.search("MSIE")==-1)
		{
			$("title").html(data.title);
		}
		showPage();

	}, "json");

}

function hideMenu(){
	if (itm!=0){
		$("#menu #level1 li."+itm+" div.inner>div").css('margin-top', 0);
		topMenu = 0;


		$("#menu #level1 li."+itm+">a").removeClass('selected');
		$("#menu #level1 li."+itm+">div").hide();

		itm = 0;
	}
}

function showPage(){
	if (navigator.userAgent.search("MSIE")!=-1){
		$(document).pngFix();
	}

	setHeight();
	$("#main a.ajax").click(function(){
		return goPage(this);
	});

	if (navigator.userAgent.search("MSIE 6")!=-1){
		$("#loader").hide();
	}
	else{
		$("#loader").fadeOut('normal');
	}

}

function setMenu(corr){
	$("#menu #level1 li").each(function(){
		lft = $(this).offset().left + 9 + corr;
		$(this).find('div.menu_bg').css('left', lft+'px');
		$(this).find('div.menu').css('left', lft+'px');
	});
}

function ShowBanner(src, w, h)
{
	//alert ('ok!');
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', w,
		'height', h,
		'src', src,
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'exactfit',
		'wmode', 'opaque',
		'devicefont', 'false',
		'id', 'stan_tv',
		'bgcolor', '#ffffff',
		'name', 'stan_tv',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'wmode', 'opaque',
		'allowScriptAccess', 'always',
		'movie', src,
		'salign', ''
		); //end AC code
	}
}