// JavaScript Document
$(document).ready(function(){

	$('#letter_form #send_letter').click(function(){
		
		var check=true;
		$('#letter_form input:text').each(function(){
			
			if($(this).val()=='')
			{
				check=false;
			}
			
		});
		
		if($('#letter_form textarea').val()=='')
		{
			check=false;
		}
		
		if(check)
		{
			$('#letter_form #send_letter').fadeOut('fast', function(){   
		
				$('#letter_form').append('<span id="status">Идёт отправка сообщения...</span>');
			});
			
			var get_str=$('#letter_form').serialize();
			
			$.get('ajax/send_mail.php?'+get_str, function(data){
			
					$('#letter_form #status').html('Сообщение отправленно.')
			});
		}
		else
		{
			alert('Заполните все поля.');
		}
	});
	
	
	$('#zakaz_kataloga #zakazat').click(function(){
	
		var check=true;
		var galks=false;
		$('#zakaz_kataloga input:text').each(function(){
		
			if($(this).val()=='')
			{
				check=false;
			}
		});
		
		$('#zakaz_kataloga input:checkbox').each(function(){
		
			if(this.checked==true)
			{
				galks=true;
			}
		});
		
		if(galks)
		{
			if(check)
			{
				$('#zakaz_kataloga #zakazat').fadeOut('fast', function(){   
		
					$('#zakaz_kataloga').append('<span id="status">Отправка данных на сервер...</span>');
				});
			
				var get_str=$('#zakaz_kataloga').serialize();
			
				$.get('ajax/zakaz_kataloga.php?'+get_str, function(data){
			
					$('#zakaz_kataloga #status').html('Ваш запрос отправлен.')
				});
			}
			else
			{
				alert('Нужно заполнить все поля.');
			}
		}
		else
		{
			alert('Нужно выбрать хотя бы один каталог.')
		}
	});
	
	$('#ikp #send').click(function(){
		var ikpfields=true;
		$('#ikp input').each(function(){
			if($(this).val()==''){
				ikpfields=false;
			}
		});
		
		if(ikpfields){
			$('#ikp #send').fadeOut('fast', function(){   
		
					$('#ikp').append('<span id="status">Отправка данных на сервер...</span>');
				});
			
				var ikp_str=$('#ikp').serialize();
			
				$.get('ajax/ikp.php?'+ikp_str, function(data){
					$('#ikp #status').html('Ваш запрос отправлен.')
				});
		}else{
			alert('Необходимо заполнить все поля');
		}
		
	});
	
	
	$('.text .photo').each(function(){
	
		$(this).wrap('<ins class="frame"><ins id="top"><ins id="right"><ins id="bottom"><ins id="left"></ins></ins></ins></ins></ins>');
		
	});
	
	setTimeout(show_zanaves, 1000);
	setTimeout(zanaves, 2000);
	
	
	$("a[rel=gallery]").fancybox({
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Изображение ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	
});


function zanaves()
{
	
	$('#zanaves #shtorki #left').animate({backgroundPosition: '-300px'}, 4000);
	$('#zanaves #shtorki #right').animate({backgroundPosition: '300px'}, 4000);
}

function show_zanaves()
{
	$('#zanaves').css('visibility', 'visible');
}
