$(document).ready(function(){
	setTimeout(showMoon, 1200);
	setTimeout(showEarth, 800);
	setTimeout(shadowEarth, 1500);
	$('#header .refresh').click(function(){
		$('.wrapper .main-block').fadeOut(400);
		$.ajax({
		   type: "GET",
		   url: '/ru/ajax/content/promo/',
		   success: function(msg){
			 $('.wrapper').prepend(msg);
			promo();
		   }
		});
	});
		
	var boxHeight=$(window).height()-$('.footer').height()-$('#header').height();
	$('.content').css('minHeight', boxHeight-20);
	$('.container').css('minHeight', boxHeight-135);
	$('#header .menu li a').click(function(){
		$(this).parent().addClass('active');
	});
	
	$('.sponsored a').hover(function(){
		$('.sponsored .icon').stop(true).animate({right: '0px'}, 1000);
		$('.sponsored .exhaust span').fadeIn(400);
		$('.sponsored .exhaust').stop(true).animate({top:'-70px'}, 1000);
	},	function(){
			$('.sponsored .exhaust span').hide();
			$('.sponsored .icon').stop(true).animate({right: '90px'}, 600, function(){
				$('.sponsored .exhaust').css('top', '3px');																			
			});
	});
	
	$('.search-form, .search form').submit(function() {
			
			var val = $(this).find('input').val().replace(/\s\s+/g, ' ');
			if(val=='') return false;
			window.location.href = $(this).attr('action') + val;
			return false;
	});
	$('#header .menu .search input').focus(function(){ $(this).parent().addClass('typing');});
	$('#header .menu .search input').blur(function(){ $(this).parent().removeClass('typing');});
	$('.vacancies .item h2').click(function(){
		$(this).toggleClass('expanded');
		$(this).next().stop(true, true).slideToggle();
	});
		
	var $size=$('.portfolio ul li').size();
	portfolioResize();
	
	$(window).resize(function(){
		portfolioResize();						  
	});
	function portfolioResize(){
		//alert($size);
		if($size<4){return false;}
		var box=$('.portfolio .layout').width();
		var count=Math.floor((box*1)/260);
		$('.portfolio ul').width(count*260);			
	}
	$('.categories .show-text').click(function(){
		if($(this).hasClass('active')){
			$('.portfolio .text').hide();
			$(this).removeClass('active');
		}
		else{
			$('.portfolio .text').show();
			$(this).addClass('active');
		}
		$.ajax({
		   type: "GET",
		   url: '/ru/ajax/content/textlabels/',
		   success: function(msg){
			 //location.reload(true);
		   }
		 });
		return false;
	});

	categories();
	$(window).scroll(function(){
		categories();
	});
	function categories(){
		if($(window).scrollTop()>235){
				$('.cat-line').addClass('fixed');
				//$('.cat-line .shadow').fadeIn();
			}
		if($(window).scrollTop()<235){
				$('.cat-line').removeClass('fixed');
				//$('.cat-line .shadow').hide();
		}
	}
	//alert($(window).scrollTop());
	$('.button').click(function(){
		if(!$(this).hasClass('show-text'))$(this).addClass('active');
	});
	$('#header .blocks .scadaplan').hover(function(){
		$(this).stop(true, true).animate({height: '110px'}, 'fast');									  
	}, function(){
		$(this).animate({height: '90px'},'fast');
	});
});
function showMoon(){
	$('.moon-block .moon').animate({bottom : '-20px'},600);
}
function showEarth(){
	$('.moon-block .earth').animate({top : '0px'}, 800);
}
function shadowEarth(){
	$('.moon-block .shadow').animate({top : '0px'}, 800);
}
function promo(){
	$('#header .refresh').css('top', '-30px');
	$('.wrapper .block').fadeIn('slow', function(){
		$(this).children().fadeIn(1000, function(){
			setTimeout(hideBlock, 1000);
		});	
	});
}
function hideBlock(){
	$('.wrapper .block').fadeOut(500, function(){
		$(this).remove();
		setTimeout(showMain, 100);
	});
}

function showMain(){
	$('.wrapper .main-block').fadeIn(1000, function(){
		$('#header .refresh').animate({top: '10px'});
	});
	
}
function showMainBlock(){
	$('.wrapper .main-block').show();
}

