$(document).ready(function() {
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.1, /* 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: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});

$(document).ready(function(){
	$(".enterbox").colorbox();
});

function check_comps(id)
{
	$.blockUI({ message: '<h1 style="margin:10px;padding:0;font-size:16px;">Подождите...</h1>' });
	$.get('/comp/counts_comps?id='+id, null,
	function(data) {
			var counts = parseInt(data);
			if (counts>0)
			{
				var form_params_groups = $('#form_params_groups').val();
				location = '/comp?params_groups='+form_params_groups;
			}
			else
			{
				$.blockUI({ message: '<h1 style="margin:10px;padding:0;font-size:16px;">Не выбрано ни одного элемента для сравнения</h1>' });
				setTimeout('$.unblockUI()',2000);
				return false;
			}
    	}
	);
}

jQuery(document).ready(function($) {
	$('a[rel*=facebox]').facebox({
		loading_image : 'loading.gif',
		close_image   : 'closelabel.gif'
	})
});

function menu(id) {
	$(".menu_sh").hide();
	$("#m"+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();
	
	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('Спасибо! Ваш отзыв принят и ожидает проверки!');
					$.fn.colorbox.close();
					$("input[name='name']").val('');
					$("input[name='email']").val('');
					$("input[name='phone']").val('');
					$("textarea[name='content']").val('');
					$("input[name='code']").val('');
					captcha();
					$("#ajax_icon").hide();
				}
	    	}
		);
	} 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();
			});
    	}
	);
}

function comp(id)
{
	$.blockUI({ message: '<h1 style="margin:10px;padding:0;font-size:16px;">Подождите...</h1>' });
	$.get('/comp/add?id='+id, null,
	function(data) {
			$.blockUI({ message: '<h1 style="margin:10px;padding:0;font-size:16px;">'+data+'</h1>' });
			$.get('/comp/counts?id='+id, null,
			function(data) {
					$("#comps").html(data);
					setTimeout('$.unblockUI()',1000);
		    	}
			)
    	}
	);
}


function viewinfo(place,id)
{
	$.get('/cat/viewinfo?id='+id, null,
	function(data) {
			if (data.length!=0)
			{
				$('#view'+place).html(data);
			}
    });
}

function comp_refer(id)
{
	comp(id);
	window.location=document.location;
}

function checkmail(email) {
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
	return (reg.exec(email)!=null)
}

$(function(){
$("#tabs").tabs();
});
