$(document).ready(function(){
	
	// CONTENT AIMATION
	$('.p_menu li a').click(function(e){
		e.preventDefault();
		var cur = 0;
		$('.p_menu li').each(function(i){
			if ($(this).attr('class')=='active'){
				cur = $(this).attr('id').replace(/p/,'');
				return cur;
			}
		});
		var id = $(this).parent('li').attr('id').replace(/p/,'');
		$('#page'+cur).stop(true).css('position','absolute')
		.animate({'top':-$('#page'+cur).height()-300+'px','opacity':'0'},($('#page'+cur).height()/100)*400,'easeOutQuart');
		
		$('#page'+id).stop(true).css('position','relative')
		.andSelf().stop(true).css('top',0)
		.andSelf().stop(true).delay(500).animate({'opacity':'1'},1300,'easeOutQuart');
		
		$('.p_menu li').removeClass('active');
		$(this).parent('li').addClass('active');
		
	});	
	$('.content_other_page').css({'opacity':'0'});
	$('#page1').css({'opacity':'1','position':'relative'});
	// END CONTENT AIMATION
	
	$('#header #menu li:last').css({'background':'none'});
	
	$('#error').hide();
	$('#senden').hide();
	var w = $(window).width() / 14;
	$('#slides li').each(function(i){
		$(this).animate({
			top: i*40 + ($.browser.msie ? 0 : 25),
			//opacity: 0.25,
			left: i*w});
	});
	var slides = $('#slides li');
	var nodes = $('#nodes li');
		$('#headline, .srch, .pdf, .pdf, #header, #contact, #footer').mouseover(function(){
			$('#slides li p').hide(300);
			$('#slides li p').css({"left": "0px"});
			$('.newBlock').remove();
		});
		$('#slides li').mouseover(function(){
			var curSlide = $(this).attr('class').replace(/s/, "");
			for (var j=1; j<slides.length+1;j++){
				if (curSlide == j) {
					var left = $('.s'+j).offset().left;
					var top = $('.s'+j).offset().top;
					if (j==13) {
						$('.newBlock').remove();
						$('.s'+j+' p').css({"left": "0px"});
						var newBlock = $('.s'+j+' p').html();
						var my_div = $("<div class=\"newBlock\" class=\"s13\"><p>"+newBlock+"</p></div>");
						my_div.css({"left":left+'px'});
						my_div.css({"top":top+'px'});
						my_div.show(100);
						my_div.appendTo("#index").animate({left:'-=221px'},{queue:false, duration:100, easing: 'easeInCirc'});
					}
					else if (j==14) {
						$('.newBlock').remove();
						$('.s'+j+' p').css({"left": "0px"});
						var newBlock = $('.s'+j+' p').html();
						var my_div = $("<div class=\"newBlock\" class=\"s14\"><p>"+newBlock+"</p></div>");
						my_div.css({"left":left+'px'});
						my_div.css({"top":top+'px'});
						my_div.show(100);
						my_div.appendTo("#index").animate({left:'-=221px'},{queue:false, duration:100, easing: 'easeInCirc'});
					}
					else {
						$('.s'+j+' p').show(300);
						$('.s'+j+' p').css({"left": "0px"});
						$('.s'+j+' p').css({"z-index": "2001"});
						$('.newBlock').remove();
						$('.s'+j+' p').animate({left:'+=0px'},{queue:false, duration:300, easing: 'easeInCirc'});
					}
				}
				else {
					$('.s'+j+' p').css({"left": "0px"});
					$('.s'+j+' p').hide(300);
					$('.s'+j+' p').css({"z-index": "0"});
				}
			}
		});
	/*FORM CHECk*/
	$('#send').click(function(){
		var pass='';
		var username = document.getElementById('username');
		var email = document.getElementById('email_i');
		if(username.value == '' || username.value == 'Имя *' ){
			pass = 'Имя не может быть пустым! \n';
			//$('#username').css({"background-color":"#fff1f1"});
		}
		if(!email.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/)){
			pass += 'Некорректно введен e-mail! \n';
			//$('#email').css({"background-color":"#fff1f1"});
		}
		if(pass != ''){
			$('#error').fadeIn();
			$('#error').text(pass);
		}else {
			//$('.contacts form input').css({"background-color":"#fff"});
			$('#error').hide();
			$('#senden').fadeIn();
			setTimeout( function(){
				document.contact_form.submit();
			}, 1000);
		}
		if ($('.contacts form').height() < 521)
			$('.contacts form').animate({height:'+=30px'},{queue:false, duration:100, easing: 'easeInCirc'});
	});
	
	// KONTACTS
	$('#contact_up,.zakaz a').click(function(e){
		$('#up').height($('#content').height()+100).css('opacity','0.7').show();
		var scrOfY = src();
		$('.contacts').css("top", scrOfY + 50 + 'px').fadeIn();
		e.preventDefault();
	});
	$('.window_close').click(function(e){
		$('#up').fadeOut(300);
		$('.contacts').hide();
		e.preventDefault();
	});
	
	function src(){
        scrOfY = 0;
       if( typeof( window.pageYOffset ) == 'number' ) {
               //Netscape compliant
               scrOfY = window.pageYOffset;
       } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
               //DOM compliant
               scrOfY = document.body.scrollTop;
       } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
               //IE6 Strict
               scrOfY = document.documentElement.scrollTop;
       }
	   return scrOfY;
	}
	
	$('.nineseven ul > li').bind('mouseenter',function(){
		var $elem = $(this);
		$elem.find('div.red')
		.stop(true)
		.animate({'opacity':'1'},500)
		.andSelf()
		.find('a')
		.stop(true)
		.animate({'opacity':'1'},200)
		.andSelf()
		.find('div.note')
		.stop(true)
		.delay(300).animate({'width':'189px','top':'20px'},400,'easeOutBack');
	}).bind('mouseleave',function(){
		var $elem = $(this);
		$elem.find('div.red')
		.stop(true)
		.animate({'opacity':'0'},0,'easeOutBack')
		.andSelf()
		.find('a')
		.stop(true)
		.animate({'opacity':'0.5'},200)
		.andSelf()
		.find('div.note')
		.stop(true)
		.animate({'width':'0','top':'0'},300,'easeOutBack');
	});
	$(".nineseven ul li a").fadeTo(200,"0.5");
	
	
	// PORTFOLIO ANIMATION
	$("#masonry-portfolio .hentry div").fadeTo(0,"0");
		$('#masonry-portfolio > div.hentry').bind('mouseenter',function(){
		var $elem = $(this);
		$elem.find('div')
		.stop(true)
		.animate({'opacity':'1'},500);
	}).bind('mouseleave',function(){
		var $elem = $(this);
		$elem.find('div')
		.stop(true)
		.animate({'opacity':'0'},500);
	});

	
	$('.enter a').toggle(function(){
		$('.login').fadeIn();
	},function(){
		$('.login').fadeOut();
	});
	
});


$(window).resize(function(){
	var w = $(window).width() / 14;
	$('#slides li').each(function(i){
		$(this).css({
			top: i*40 + ($.browser.msie ? 0 : 25),
			left: i*w})
	});
});

	/*FORM CHECk*/
function CheckContForm(){
	var pass='';
	if(!document.getElementById('username').value.match(/^[а-яА-Яa-zA-Z-]+$/)){
		pass += 'Ошибка: Некорректно введено имя!\n';
	}
	if(!document.getElementById('phone').value.match(/^[0-9]+$/)){
		pass += 'Ошибка: Укажите полное количество лет!\n';
	}
	if(!document.getElementById('email_i').value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/)){
		pass += 'Ошибка: Некорректно введен e-mail!\n';
	}
	if(document.getElementById('text').value == ''){
		pass += 'Ошибка: Сообщение не может пустым!\n';
	}
	if(pass != ''){
		alert(pass);
	} else {
		//alert('1');
		document.cont_form.submit();
	}
}

/******************SPORTS**************/



