$(document).ready(function(){
	
	$(".price_select").selectbox({
		animationSpeed:"fast",
		width: 153
		//hideSelected: true
	});
	
	// after reload page - set checkboxes to default values
	$(".custom-radio input:radio").removeAttr("checked");
	$(".myradio input:radio").attr('checked', "checked");
	//$(".select-format input:first, .select-type input:first, .select-addr input:first").attr('checked', "checked");
	//$("input#includeStamp").attr('checked', "checked");
	
	$(".addr-types div.price-select").hide();
	$(".addr-types div.jquery-selectbox").hide();
	// ---
	
	$("#show-shipping-buttons a.info").hover(
	  function () {$("#stampcost-info").show();},
	  function () {$("#stampcost-info").hide();}
	);

	$("#show-shipping-info a.info").hover(
	  function () {$("#gratis-verzending").show();},
	  function () {$("#gratis-verzending").hide();}
	);
	
	$(".calc-button").hover(
	  function () {$(this).css("border", "2px solid #80d7f7");},
	  function () {$(this).css("border", "1px solid #cccccc");}
	);
	
	$(".select-format label").click(function () { 
		var curClass = $(this).attr("class");
		
		if(curClass != 'disabled') {
			$(".select-format label").removeClass("myradio").removeClass("onactive");
			$(this).addClass("myradio");
			$(".select-format").children("input[name='size']:radio").removeAttr("checked");
			$(this).children("input[name='size']:radio").attr('checked', "checked");
		}	
	});	
	
	$(".select-type label").click(function () { 		
		var curClass = $(this).attr("class");
		
		if(curClass != 'disabled') {
			$(".select-type label").removeClass("myradio").removeClass("onactive");
			$(this).addClass("myradio");
		}	
	});
	
	$(".select-addr label").click(function () { 
		$(".select-addr label").removeClass("myradio").removeClass("onactive");
		$(this).addClass("myradio");
		$(".select-addr").children("input[name='type']:radio").removeAttr("checked");
		$(this).children("input[name='type']:radio").attr('checked', "checked");
	});
	
	$(".select-shipcost label").click(function () { 
		$(".select-shipcost label").removeClass("myradio").removeClass("onactive");
		$(this).addClass("myradio");
	});
	
	$(".custom-radio label").mouseover(function(){$(this).not(".myradio, .disabled").addClass("onactive");});
	$(".custom-radio label").mouseout(function(){$(this).removeClass("onactive");});
	
	/** FROM OLD PRICE PAGE	*/
	
	disable_sq10();
	disable_sq14();
	disable_single();
	hide_box_list();
	
	$("input[name='size']").click(function(){
		disable_single();
	});
	$("input[name='sides']").click(function(){
		disable_sq14();
		disable_sq10();
	});
	$("input[name='type']").click(function(){
		hide_box_list();
	});
	
	$("input[name='count']").keyup(function(e){
		if ( $("input[name='type']:radio:checked").val() == 'dir' ) {
			$("input[name='count']").val($("input[name='count']").val().replace(/^0+|[^0-9]/g,''));
		};
	});
	
	$("input[name='calculate']").click(function(){
		calc_price();
	});
	
	$("[name='include_stamp_cost']").click(function(){
		calc_price();
	});
	
	function calc_price() {
		if ( $("input[name='type']:radio:checked").val() == 'dir' ) {
			var count = $("input[name='count']").val();
		} else {
			var count = $("select[name='count']").val();
		};
		var cust_pr = get_price($("input[name='size']:radio:checked").val(), $("input[name='sides']:radio:checked").val(), $("input[name='type']:radio:checked").val(), count, $("input[name='include_stamp_cost']:radio:checked").val());
		$("#big_total").text(print_num(cust_pr.logged));
		$("#big_total_not_logged").text(print_num(cust_pr.not_logged));
		$("#small_total").text(print_num(cust_pr.not_logged - cust_pr.logged));
		return false;
	}

	function disable_sq10() {
		if ( $("input[name='sides']:radio:checked").val() == 0 ) {
			$("#size_sq10").parent().attr("class", "disabled");
			$("#size_sq10").attr("disabled", "disabled");
		} else {
			$("#size_sq10").parent().removeClass("disabled");
			$("#size_sq10").removeAttr("disabled");
		};
	};
	
	function disable_sq14() {
		if ( $("input[name='sides']:radio:checked").val() == 0 ) {
			$("#size_sq14").parent().attr("class", "disabled");
			$("#size_sq14").attr("disabled", "disabled");
		} else {
			$("#size_sq14").parent().removeClass("disabled");
			$("#size_sq14").removeAttr("disabled");
		};
	};
	
	function disable_single() {
		var curVal = $("input[name='size']:radio:checked").val();
		if ( (curVal == 'sq14') || (curVal == 'sq10') ) {
			$("#sd_single").parent().attr("class","disabled");
			$("#sd_single").attr("disabled","disabled");
		} else {
			$("#sd_single").parent().removeClass("disabled");
			$("#sd_single").removeAttr("disabled");
		};
	};
	
	function hide_box_list() {
		if ( $("input[name='type']:radio:checked").val() == 'dir' ) {
			$("input[name='count']").show();
			$(".addr-types div.price-select").hide();
			$(".addr-types div.jquery-selectbox").hide();
			$("#show-shipping-buttons").show();
			$("#show-shipping-info").hide();
		} else {
			$("input[name='count']").hide();
			$(".addr-types div.price-select").show();
			$(".addr-types div.jquery-selectbox").show();
			$("#show-shipping-buttons").hide();
			$("#show-shipping-info").show();
		};
	};
	
	function print_num(x) {
		return x.toFixed(2).replace(/\./g, ',');
	};
});
