$(document).ready(function(){
	// $("._server_status_body").show().data("height", $("._server_status_body").get(0).offsetHeight ).css("height", "0px");
	setTimeout(function(){$("#slogan").animate({ top: "0px" }, 1000); }, 1000);
	$(function() {$('.nav_menu1').menu_1()});
	
	$("._server_status_name").click(function(){
		$("._server_arrow").toggle();    		
		toggleServerStatus();
	});	
	
	$(".vote_block:last .poll_body").css("display","none");
	$(".poll_name").click( function(){
		 $(this).parent().find(".poll_body").toggle(600);
	});	
	
	
	$(".sbmt").hover(function(){ this.src = this.src.replace(/\_(.)+.png/, "_hover.png"); }, function (){ this.src = this.src.replace(/\_hover.png/, "_norm.png"); } );
	$(".sbmt").click(function(){ this.src = this.src.replace(/\_hover.png/, "_pressed.png"); });	
	
	SetCookie('can_vote',1,1);
	
	my_init();
});


function init_vote(id)
{
	var cid = "vote_" + id;
	var c = readCookie(cid);
	if(c == 1)
		$("#results_block_" + id).show();
	else
		$("#vote_block_" + id).show();
}

function slogan_close()
{
	$('#slogan').animate({ top: '-113px' }, 1000);
}

$.fn.menu_1 = function()
{
	var ele = $('.hide');
	
	var IE='\v'=='v';

	var mouse = "off"
	var status = "closed"
	var timer = 0;

	function show(e)
	{	
		mouse = "on"
		clearTimeout(timer);
		if(status == "closed")
		{
			if(IE)
				$("#_menu_clouds").animate({top: "0px", height: "168px"},700);
			else
      			$("#_menu_clouds").animate({top: "0px", height: "168px", opacity: 1},700);
      			
  			ele.show("blind", { direction: "vertical" }, 800);
  			$(".menu_title").css("border-bottom", "0px solid  #046c82").find("a").css("text-decoration", "underline");
  			
  			status = "opened";
  		}
		$(".day_tips_full").css("display", "none");
		$(".day_tips").css("display", "block");
	}
	

	function hide(e)
	{
		mouse = "off"
        if ( status="opened" )
        {	
	      	timer = setTimeout(function() 
	      	{
	        	if ( mouse == "off" ) 
          		{ 	
          			if(IE)
          				$("#_menu_clouds").animate({ height: "1px", top: "168px"},500);
          			else
          				$("#_menu_clouds").animate({ height: "1px", top: "168px", opacity: 0},500);
          				
          			ele.hide("blind", { direction: "vertical" },500);  
          			$(".menu_title").css("border-bottom", "1px dashed #046c82").find("a").css("text-decoration", "none");
          			status = "closed";
          		}
	        }, 500);
	    }	
    }
	$(".menu_title", this).hover( show, hide );
	$(".hide", this).hover( show, hide );
	
};


$.fn.news = function()
{
	$(".news_block", this).each(function() {
		
	
		var news = this;
		
		$(".news_anonce", news).css("display", "block");
			var h = $(".news_anonce", news).get(0).offsetHeight;	
		$(".news_anonce", news).data("height", h);
		$(".news_anonce", news).css("height", "0px");
		
		function myclick()
		{
			if($(".news_anonce", news).css("height")== "0px")
			{
				h = $(".news_anonce", news).data("height");
				$(".news_anonce", news).animate( { height: h + "px"}, 1000);	
			}
			else
			{
				$(".news_anonce", news).animate( { height: "0px"}, 1000);	
			}

		}
		
		$("._news_name", this).click(myclick);
	});
};

function _showImageFrame(url)
{
	var document_height = getDocumentHeight();
	var frame_top = getBodyScrollTop() + 50;
	var h = document_height;// + frame_top;
	if($("#image_show_layer").css("display") == 'none')
		$("#image_show_layer").css({ height: ( h ) + 'px', display: 'block'} )

	var url= $(this).attr("href");
	
	$(".image_show").css({display :"block", top: (frame_top ) + 'px'}).find(".full_img").attr("src","/images/blank.gif").attr("src", url);
		var height = this.height + frame_top + 155 ; // Отступ сверху и блок снизу
		if(height > h)
			$("#image_show_layer").css({ height: ( height ) + 'px', display: 'block'});
		
	return false;
}

function _closeImageFrame()
{
	$(".image_show").find(".full_img").attr("src", "/images/blank.gif");
	$("#image_show_layer").css({display: 'none'} );
	$(".image_show").css("display","none").find(".full_img").attr("src", "/images/blank.gif");
}

function ShowFullImage(url)
{
	var document_height = getDocumentHeight();
	var frame_top = getBodyScrollTop() + 50;
	var h = document_height;// + frame_top;
	if($("#image_show_layer").css("display") == 'none')
		$("#image_show_layer").css({ height: ( h ) + 'px', display: 'block'} )
	
	$("#common_show_image").css({display :"block", top: (frame_top ) + 'px'}).find("#full_img").attr("src", url);
		var height = this.height + frame_top + 155 ; // Отступ сверху и блок снизу
		if(height > h)
			$("#image_show_layer").css({ height: ( height ) + 'px', display: 'block'});
		
	return false;
}

function CloseFullImage()
{
	$("#full_img").attr("src", "/images/blank.gif");
	$("#common_show_image").hide();
	$("#image_show_layer").hide();
}

function toggleServerStatus()
{
	var h = $("._server_status_body").data("height");
	if( $("._server_status_body").css("height") == "0px"){
		$("._server_status_body").animate( { height: h + "px" }, 600);
	}
	else{
		$("._server_status_body").animate( { height: 0 + "px" }, 600 );
	}
}

function my_init()
{
	$(".zebra_table tr:nth-child(even)").addClass("bg");
}


//  Переключение дивов с "затуханием".
// id_parent - внешний блок, id_1, id_2 - переключаемые блоки c 1 на 2,  speed - скорость в милисек.
function switch_div(id_parent, id_1, id_2, speed)
{
	$("#" + id_parent).animate({opacity: 0.1}, speed);
	setTimeout(function(){
		$("#" + id_1).css("display","none");
		$("#" + id_2).css("display","block");
		$("#" + id_parent).animate({opacity: 1}, speed);
	}, speed);
}

function init_day_tips()
{
	$(".link").click(function(){
		$(".day_tips").css("display", "none");
		$(".day_tips_full").css("display", "block");
	});
	
	$(".day_tips_full").click(function(){
		$(".day_tips_full").css("display", "none");
		$(".day_tips").css("display", "block");
	}); 
}

function ShowDivOneClasses( id ) {
	var b = document.getElementById( id );
	var flag=0;
	if (b.className=='normal') {
		flag=1;
	}
	
	for (var i in OneClasses) {
		var a = document.getElementById( i );
		if ( a ) a.className = ( i == id ? 'active' : 'normal' );
	}
	if (flag==1) {
	$("#OneClassesInfo").fadeOut("slow", function() {
		$(this).html( OneClasses[ id ] );
//		$("._gallery_pic").click(_showImageFrame);
		$(this).fadeIn("slow");
	});
	}
return false;
}

function ShowDivTwoClasses( id ) {
	var b = document.getElementById( id );
	var flag = 0;
	if (b.className=='normal') {
		flag=1;
	}
	for (var i in TwoClasses) {
		var a = document.getElementById( i );
		if ( a ) a.className = ( i == id ? 'active' : 'normal' );
	}
	
	if (flag==1) {
	$("#TwoClassesInfo2").animate({opacity: 0.01}, "slow", function() {
		$(this).html( TwoClasses[ id ] );
//		$("._gallery_pic").click(_showImageFrame);
		$(this).animate({opacity: 1}, "slow");

	});
	}
return false;
}


/* regions */
var ClickFlagSelect = false;

jQuery(function( $ ){	
	$('.LinkForDisk').click(function(){
		if ( $('.HowToGet').css('display')=='none' ) {
			$('.HowToGet').slideDown('slow');
		} else {
			$('.HowToGet').hide();
		}
	});
		
	$('.HowToGetTheDisc').click(function(){
		var ClassId=$(this).attr('id');
		if ( $('#'+ClassId+' > .SelectDiv').css('display')=='none' ) {
			ClickFlagSelect=true;
			$('.SelectDiv').slideUp('slow');
			$('#'+ClassId+' > .SelectDiv').slideDown('slow');
		} else {
			ClickFlagSelect=false;
			$('#'+ClassId+' > .SelectDiv').slideUp('slow');
		}
	});
	
	$('#HowToGetTheDiscCountry > .SelectDiv > .SelectCenter > .SelectCenterText').click(function(){
		var Country=$(this).attr('title');
		var ShowCountry=$(this).attr('id');
		ShowCountry=ShowCountry.substr(4);
		var Region;
		Region=$('#'+ShowCountry+' > .SelectCenterText').attr('title');
		$('#Country').html(Country);
		$('#Region').html(Region);
		$('.SelectCenterCountry').hide();
		$('#'+ShowCountry).show();
		$('#HowToGetTheDiscRegion').slideDown('slow');
		ClickFlagSelect=true;
	});
	
	$('#HowToGetTheDiscRegion > .SelectDiv > .SelectCenter > .SelectCenterText').click(function(){
		var Region=$(this).attr('title');
		$('#Region').html(Region);
		var ShowRegion=$(this).attr('id');
		ShowRegion=ShowRegion.substr(12);
		$('.HowToGetTheDiscAddress').slideUp('slow');
		$('#'+ShowRegion).slideDown('slow');
		ClickFlagSelect=false;
	});

	$('body').click(function(){
		if ( $('#HowToGetTheDiscRegion > .SelectDiv').css('display')=='block' && ClickFlagSelect!=true || $('#HowToGetTheDiscCountry > .SelectDiv').css('display')=='block' && ClickFlagSelect!=true ) {
			$('.SelectDiv').slideUp('slow');
		}
		ClickFlagSelect=false;
	});
});