

$(document).ready(function(){

if ($("#edit").attr("class") != 'act') {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			showTitle: false,
			theme: 'facebook' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		});
		
		$('a.plus').click(function(event) {
			event.preventDefault();
			var images = [];
			$("a[rel^='prettyPhoto']").each(function(){
				images.push($(this).attr('href'));
			});
			$.prettyPhoto.open(images);
		});
		$(".pp_hoverContainer").click(function(){
			$.prettyPhoto.close();
		});
}


	if($.cookie("advanced")) {
		$(".filter .advanced").attr("class", "advanced");
		$(".all_params a").html("Базовые параметры");
	}
	if($.cookie("manufactures")) {
		$(".manufactures .advanced").attr("class", "advanced");
		$(".manufactures a").html("Основные производители");
	}
	
	checkStep();
	table_markup_zebra('more_info');
	mCartItemAddedPopup();
});

//Проверка формы в корзине
function checkStep() {
	$('#checkStep .delivery input').click(function() {
		var input_value = parseInt($(this).attr("value"));
		switch (input_value) {
		case 27230:
			setInputEnabled();
			$('#checkStep .payment input#pay_302421').attr('disabled', 'disabled');
			$('#checkStep .payment input#pay_28283').attr('checked', 'checked');
			break
		case 27233:
			setInputEnabled(this);
			$('#checkStep .payment input#pay_302421').attr('disabled', 'disabled');
			$('#checkStep .payment input#pay_28283').attr('checked', 'checked');
			break
		case 32417:
			setInputEnabled(this);
			$('#checkStep .payment input#pay_28283').attr('disabled', 'disabled');
			$('#checkStep .payment input#pay_302421').attr('checked', 'checked');
			break
		}
	});
}

function setInputEnabled() {
	$('#checkStep .payment input').each(function(index) {
		$(this).removeAttr('disabled');
		$(this).removeAttr('checked');
	  });
}



// Доп параметры фильтра
function advans_param() {
	if ($(".filter .advanced").attr("class") == "advanced none") {
		$(".filter .advanced").attr("class", "advanced");
		$(".all_params a").html("Базовые параметры");
		$.cookie("advanced", 'param');
	}
	else {
		$(".filter .advanced").attr("class", "advanced none");
		$(".all_params a").html("Все параметры");
		$.cookie("advanced", null);
	}
}

function advans_manufac() {
	if ($(".manufactures .advanced").attr("class") == "advanced none") {
		$(".manufactures .advanced").attr("class", "advanced");
		$(".manufactures a").html("Основные производители");
		$.cookie("manufactures", 'param');
	}
	else {
		$(".manufactures .advanced").attr("class", "advanced none");
		$(".manufactures a").html("Показать всех");
		$.cookie("manufactures", null);
	}
}

function short_bask_status() {
	alert();	
}

function table_markup_zebra(className) {
	$('.' + className + ' table tr').each(function(i) {
		if ((i % 2) == 0) {
			$(this).addClass('zebra');
		}
	});
}

function mCartItemAddedPopup() {
	var aCookies = document.cookie.split(';'), i, aCookie;
	for (i = 0; i < aCookies.length; i++) {
		if (aCookies[i].indexOf('is_cart_item_added') != -1) {
			aCookie = aCookies[i].split('=');
			if (aCookie[1]) {
				alert("Товар успешно добавлен в корзину.");
				document.cookie = 'is_cart_item_added=;path=/';
			}
			break;
		}
	} 
}

