$(document).ready(function(){

	// menu corners	
	//equalHeight($(".list"));
	equalHeight($(".color_img.photo"));
	equalHeight($(".color_img.palitra"));
	
	// промотка превьюшек
	$(".thumbs")
		.append('<a href="#" class="arrow left"></a>')
		.append('<a href="#" class="arrow right"></a>');
	
	$(".arrow").click(function(){
		if ($(this).hasClass("left"))  	 
			var shift = '+=100px';
		if ($(this).hasClass("right"))  	 
			var shift = '-=100px';
			
		$(this).siblings(".scroller").animate({left: shift},800);
		return false;
	});
		
	
	// скрыть - показать поиск моек
	$("form .collapse").click(function(){
		$("form.search").slideUp(1000);
	});

	// скрыть - показать дополнительные параметры в поиске на главной
	$("form .open_more_options").click(function(){
		$(".more_options").slideToggle(1000);
	});	
	
	// обратный звонок
	$('.menu_contact a').click(function() {
		$('.callback').lightbox_me({
			overlayCSS:	{background: 'white', opacity: .6},
			centered: 	true, 
			onLoad: 		function() { 
				$('.callback').find('input:first').focus();
			}
		});
		return false;
	});	
	$('.callback form .submit_callback').click(function(){
		$.ajax({
			type: "POST",
			url: "/scripts/callback.php",
			data: $(".callback form").serialize(),
			dataType: "html",
			beforeSend:	function(){
				//console.log('sending');
				img = "<img src='/scripts/ajax_loading.gif' class='ajax_loading'/>";
				$(".callback .status").text('Отправка запроса...')
				$(img).appendTo(".callback .status");
			},
			success:	function(response){
				//console.log('ok!');
				$(".callback .ajax_loading").hide('slow');
				$(".callback .status").text(response);
			}
		}); // ajax		
	});
	
	$('.mail form .submitm').click(function(){
		$.ajax({
			type: "POST",
			url: "/scripts/mail.php",
			data: $(".mail form").serialize(),
			dataType: "html",
			beforeSend:	function(){
				//console.log('sending');
				img = "<img src='/scripts/ajax_loading.gif' class='ajax_loading'/>";
				$(".mail .status").text('Отправка запроса...')
				$(img).appendTo(".mail .status");
			},
			success:	function(response){
				//console.log('ok!');
				$(".mail .ajax_loading").hide('slow');
				$(".mail .status").text(response);
			}
		});
    });
});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function scroll_thumbs(obj,index,direction) {
	scroll_width = obj.width() + 10;				// width + margin-left
	$(".clients").animate(
		{left: "-="+scroll_width+"px"},			// move div to the left by scroll_width
		2000,
		function(){
			obj.appendTo(".clients"); 				// move first obj to the end
			$(this).css({left: "0"});				// reset position of div
		}
	);
}

