﻿$(document).ready(function() {	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});
 
jQuery(document).ready(function($) {
	$('a[rel*=facebox]').facebox({
		loading_image : 'loading.gif',
		close_image   : 'closelabel.gif'
	})
});

$(document).ready(function(){
	var count = $("#count_blocks").val();
	var count_block = count*75;
	lastBlock = $("#a1");
	maxWidth = 1015-count_block;
	minWidth = 75;
	$("#a1").width(maxWidth);
	$(".jquery-accard li a").hover(	
		function(){			
			$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
			currentBlock = this;				
			lastBlock = this;			
	    }
	);
});

$(document).ready(function(){
	$("#dim").css("height", $(document).height());
	$(window).bind("resize", function(){
		 $("#dim").css("height", $(window).height());
	});
});

function setmenu(id) {
	//menu(id);
	var setm = $("#set_menu").val();
	if (setm!=id) {
		$('.toggle').hide();
	}
	$('#m'+id).slideToggle('slow',set_key(id));
}


function set_key(id) {
	$("#set_menu").val(id);
}

function menu(id) {
	$(".menu_sh").hide();
	$("#cat_sub_"+id).slideToggle('slow');
	
	$("#dim").fadeIn();
	$("#ajax-content").hide();
	
	$.get('/cat/ajax/'+id, null, 
    function(data) {
    		$("#ajax-content").html(data);
			$("#ajax-content").slideToggle("slow");
    	}
	);
	$("#dim").fadeOut();
}

function vote(id,vote) {
	$.get('/vote?id='+id+'&vote='+vote, null,
	function(data) {
			$("#block_marks").hide();
        	$("#block_marks").html(data);
        	$("#block_marks").slideToggle('slow');
    	}
	);
}

function captcha() {
	$.post('/index/captcha', null,
	function(data) {
			$("#recaptcha").hide();
        	$("#recaptcha").html(data);
        	$("#recaptcha").show();
    	}
	);
}

function response(id)
{
	$("#ajax_icon").show();
	$("#form_response").hide();
	
	var data = new Array();
	
	data[0]=$.trim($("input[name='name']").val());
	data[1]=$.trim($("input[name='email']").val());
	data[2]=$.trim($("input[name='phone']").val());
	data[3]=$.trim($("textarea[name='content']").val());
	data[4]=$.trim($("input[name='code']").val());
	
	if (data[3].length > 5) {
		$.post('/response?id='+id+'&data='+data, null,
		function(data) {
			//alert(data);
				if (data=='false') {
					alert('Внимание! Введен неверный код!');
					$("#ajax_icon").hide();
					$("#form_response").show();
				}
				else {
					alert('Спасибо! Ваш отзыв принят и ожидает проверки!');
					$("input[name='name']").val('');
					$("input[name='email']").val('');
					$("input[name='phone']").val('');
					$("textarea[name='content']").val('');
					$("input[name='code']").val('');
					captcha();
					$("#ajax_icon").hide();
					$("#form_response").slideToggle('slow');
				}
	    	}
		);
	} else {
		alert('Напишите хотя бы 6 символов!');
		$("#ajax_icon").hide();
		$("#form_response").show();
	}
}

function shopping_cart(id) {
	$.get('/shopping_cart/add?id='+id+'&cc=1', null,
	function(data) {
        	$("#shopping-cart-box").hide();
			$("#shopping-cart-box").html(data);
			$(document).ready(function(){
				$("#shopping-cart-box").slideToggle("slow");
				$("#shopping-cart-box").show();
			});
    	}
	);
}
