$(document).ready(function() {

	$(document).pngFix();

	var hide_message = function hide_message() {
		if ($("#alert #do_not_close").attr('value'))
			return;
		$("#alert:visible").toggle();
		$(".log_error").attr('class','log_correct');
		$("#log_error_text:visible").toggle();
	};
	
	$promo = 1;
	var change_promo = function change_promo() {
		if ($promo > $('.box-promo-tab').size())
			$promo = 1;
		$('#product-tabs').triggerTab($promo);
		$promo+=1;
	};
	
	setInterval(change_promo, 4000);
	setInterval(hide_message, 8000);

	$("input[type=text],input[type=password]").click(function() {
		if (	$(this).val() == 'login' ||
			$(this).val() == 'password' ||
			$(this).val() == 'Buscar producto' ||
			$(this).val() == 'Tu e-mail'
		)
			$(this).val('');
	});

	$("#buy_button").click(function() {
		$("#buy_form").submit();
	});

	$(".del_product_from_basket").click(function() {
		$(this).parents("form.basket_product_del_form").submit();
	});

	$("#next_step_btn").click(function() {
		$(this).parents("form").submit();
	});

	$("#btn_epay").click(function() {
		$("#form_epay").submit();
	});
/*
	$("#prev_step_btn").click(function() {
		$(this).parents("form").submit();
	});
*/

	$(".change_product_in_basket").click(function() {
		$(this).parents("tr").prev().children("form.basket_edit_form").submit();
	});

	$("#shipment_data_chkbox").click(function() {
		$("#register_shipment_data").slideToggle("slow");
	});

	$("#account-new-btn").click(function() {
		$("div.div_registeration").slideToggle("slow");
	});
	
	$(".buy_choose_button").click(function() {
		$("#detail_name_"+$(this).parent().parent().find("input.detail_name").attr('value')).html($(this).parent().parent().parent().prevAll("div.option-name").html());
		$("#detail_price_"+$(this).parent().parent().find("input.detail_name").attr('value')).html($(this).parent().parent().parent().prevAll("div.option-price").children("span.feature_price").html());
		$("#"+$(this).attr('name')).attr('value', $(this).attr('value'));
		$("#price_"+$(this).attr('name')).attr('value', $(this).parent().parent().parent().prevAll("div.option-price").children("span.feature_price").html());
		$price = parseFloat($("#price_main").attr('value'));
		$('.buy_prices').each(function() {
			$price += parseFloat($(this).val());
		});
/*
		if ($price > 100) {
			$("#div_raty_oblicz").css('display', 'block');
			$("#div_raty_kupuj").css('display', 'none');
		} else {
			$("#div_raty_oblicz").css('display', 'none');
			$("#div_raty_kupuj").css('display', 'block');
		}
*/
		$("#product_price").html($price.toFixed(2));

		$(".overlay:visible").toggle();
	});

	$(".pr-option-change-btn").click(function() {
		$("#pr-option-change_"+$(this).attr('id')).toggle();
	});
	$(".ask-form-pr-btn").click(function() {
		$("#ask-form-pr").toggle();
	});
	$(".add-opinion-form-btn").click(function() {
		$("#add-opinion-form").toggle();
//		$("#add-opinion-form").children("div").children("div").slideToggle("slow");
	});
	$(".add-comment-form-btn").click(function() {
		$("#add-comment-form").toggle();
	});
	$(".add-question-form-btn").click(function() {
		$("#add-question-form"+$(this).attr('id')).toggle();
	});

	$(".term-more").click(function() {
		$("#term-more").toggle();
	});
	$(".delivery-more").click(function() {
		$("#delivery-more").toggle();
	});
	$(".zagiel-more").click(function() {
		$("#zagiel-more").toggle();
	});
/*
	$(".calculate").click(function() {
		$("#calculate").toggle();
	});
*/
	
/*
	$(".print-btn").click(function() {
		$("#print").toggle();
	});
*/
	$(".rec-form-btn").click(function() {
		$("#rec-form").toggle();
	});

	$(".close-overlay-btn").click(function() {
		$(".overlay:visible").toggle();
	});
	$("#login-form-btn").click(function() {
		$("#login-form").toggle();
	});
	$("#basket-form-btn").click(function() {
		$("#basket-form").toggle();
	});

/*	$("#print-btn").click(function() {
		window.open ($(this).attr('href'), $("#product_name").html(), "menubar=1,resizable=1,width=780,height=600");
		return false;
	});
*/

	$("option.shipment_province").click(function() {
//$(".payment_option:checked").next("input.payment_cost").attr('value')
		s_price = 'shipment_cost_'+$(this).attr('value');
		if ($(".payment_option:checked").next("input.payment_cost").attr('value'))
			payment_option = $(".payment_option:checked").next("input.payment_cost").attr('value');
		else
			payment_option = 0;
		$("#delivery-cost span#ship_price").html( (parseFloat($("#"+s_price).attr('value'))+parseFloat(payment_option)).toFixed(2) );

		$("#total-cost span#total_price").html( (parseFloat($("#pr-value span#prod_price").html())+parseFloat($("#delivery-cost span#ship_price").html())).toFixed(2) );
	});

	$(".payment_option").click(function() {
		ship_id = $(this).next().next("input.payment_ship_id").attr('value');
		if ($("select#shipment_province_"+ship_id+" option:selected").attr('value')) {
			s_price = 'shipment_cost_'+$("select#shipment_province_"+ship_id+" option:selected").attr('value');
			$("#delivery-cost span#ship_price").html( (parseFloat($(this).next("input.payment_cost").attr('value'))+parseFloat($("#"+s_price).attr('value'))).toFixed(2) );
		} else {

			s_price = $("#shipment_option_"+ship_id).attr('value');
			$("#delivery-cost span#ship_price").html( (parseFloat($(this).next("input.payment_cost").attr('value'))+parseFloat(s_price)).toFixed(2) );
		}
		$("#total-cost span#total_price").html( (parseFloat($("#pr-value span#prod_price").html())+parseFloat($("#delivery-cost span#ship_price").html())).toFixed(2) );
//		$("#pay_choosen").attr('value', s_price);
//		$("#delivery-cost span#ship_price").html( (parseFloat($(this).next("input.payment_cost").attr('value'))+parseFloat($("#pay_choosen").attr('value'))) );
	});

//	$(".alert").colorbox({width:"765px", inline:true, href:"#alert"});

});

/*
	function RataPrice() {
		return document.getElementById('product_price').innerHTML;
	}
*/

