// When the user selects a different quantity, foil, gloss and shipping prices all change
// spot gloss, then decorative foil, then shipping

$(document).ready(function(){

	$("input#quantity-01").click(function(){
		
		var cardsizeprices = [ "0", "30", "30", "220", "160", "320" ];
		var spotglossarr = [ "0", "35", "45" ];
		var decorativefoil = "50";
		var shippingprices = [ "0", "35", "45", "45", "45", "50", "50", "50" ];
		var metallicink = "50";
		var roundedcorners = [ "0", "45", "45"];		
		
		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);		
		$.shippingPricing(shippingprices);
		
	});
	
	$("input#quantity-02").click(function(){
		
		var cardsizeprices = [ "0", "20", "20", "220", "170", "320" ];
		var spotglossarr = [ "0", "35", "45" ];
		var decorativefoil = "50";
		var shippingprices = [ "0", "45", "50", "55", "55", "55", "60", "60" ];
		var metallicink = "50";
		var roundedcorners = [ "0", "45", "45"];		

		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);				
		$.shippingPricing(shippingprices);
		$.roundedCorners(roundedcorners);
		
	});
	
	$("input#quantity-03").click(function(){
		
		var cardsizeprices = [ "0", "30", "30", "350", "220", "450" ];
		var spotglossarr = [ "0", "45", "55" ];
		var decorativefoil = "70";
		var shippingprices = [ "0", "65", "65", "80", "80", "85", "85", "90" ];
		var metallicink = "70";
		var roundedcorners = [ "0", "55", "55"];		

		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);		
		$.shippingPricing(shippingprices);
		$.roundedCorners(roundedcorners);

	});
	
	$("input#quantity-04").click(function(){
		
		var cardsizeprices = [ "0", "30", "30", "425", "205", "525" ];
		var spotglossarr = [ "0", "65", "75" ];
		var decorativefoil = "95";
		var shippingprices = [ "0", "80", "85", "105", "105", "110", "115", "115" ];
		var metallicink = "95";
		var roundedcorners = [ "0", "65", "65"];		
	
		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);		
		$.shippingPricing(shippingprices);
		$.roundedCorners(roundedcorners);

	});
	
	$("input#quantity-05").click(function(){
		
		var cardsizeprices = [ "0", "30", "30", "500", "200", "600" ];
		var spotglossarr = [ "0", "85", "95" ];
		var decorativefoil = "115";
		var shippingprices = [ "0", "95", "100", "125", "135", "135", "140", "150" ];
		var metallicink = "115";
		var roundedcorners = [ "0", "75", "75"];		
		
		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);		
		$.shippingPricing(shippingprices);
		$.roundedCorners(roundedcorners);

	});

	$("input#quantity-06").click(function(){
		
		var cardsizeprices = [ "0", "30", "30", "600", "230", "700" ];
		var spotglossarr = [ "0", "85", "95" ];
		var decorativefoil = "135";
		var shippingprices = [ "0", "110", "120", "145", "165", "165", "175", "180" ];
		var metallicink = "135";
		var roundedcorners = [ "0", "85", "85" ];		
		
		$.cardSizePricing(cardsizeprices);
		$.spotGloss(spotglossarr);
		$.decorativeFoilPricing(decorativefoil);
		$.metallicInkPricing(metallicink);		
		$.shippingPricing(shippingprices);
		$.roundedCorners(roundedcorners);

	});
	
	// Sets Card Size Pricing on an individual basis
	$.cardSizePricing = function(cardsizearr){
		
		// Iterates through the array //
		$.each(cardsizearr, function(index, price){
			
			// Uses index to find individual <inputs> and <divs>
			$(".cardsizecalc #cardsize-0" + (index+1)).attr("calc", price + ".00");
			
			if( price == "0" ){
				price = "+free";
			} else {
				price = "+$" + price;
			}
			$(".cardsizedisplay #cardsize-0" + (index+1)).text(price);
		 });
	};
	
	$.spotGloss = function(spotglossarr){
				
		$.each(spotglossarr, function(index, price){									  
			$(".spotglosscalcprice #spotgloss-0" + (index+1)).attr("calc", price + ".00");
			if( index != "0" ){
				$(".spotglossdisplayprice #spotgloss-0" + (index+1)).text("+$" + price);
			}
		});
	};
	
	$.roundedCorners = function(roundedcorners){
				
		$.each(roundedcorners, function(index, price){									  
			$(".rcornerscalc #roundedcorners-0" + (index+1)).attr("calc", price + ".00");
			if( index != "0" ){
				$(".rcornersdisplay #roundedcorners-0" + (index+1)).text("+$" + price);
			}
		});
	};
	
	$.decorativeFoilPricing = function(decorativefoil){
		
		$(".decorativefoilprice input").each(function(){
			$(this).attr("calc", decorativefoil + ".00");
		});
		$(".foildisplayprice").text(decorativefoil);
	
	};
	
	$.metallicInkPricing = function(metallicink){
		
		$(".metallicinkcalc input").each(function(){
			$(this).attr("calc", metallicink + ".00");
		});
		$(".metallicinkdisplay").text(metallicink);
	
	};

	
	$.shippingPricing = function(shippingPrices){
		$.each(shippingPrices, function(index, price){
			$(".shippinglocation #shipping-0" + (index + 1)).attr("calc", price + ".00");
			
			if( price == "0" ){ 
				price = "+free" 
			} else { 
				price = "+$" + price;
			};
			
			$(".shippingdisplayprice #shipping-0" + (index+1)).text(price);

		});
	}
		
				   

					
// Begin standard page JS					
					$('#cards').innerfade({
						speed: 750,
						timeout: 7000,
						type: 'sequence',
						containerheight: '372px',
						containerwidth: '568px'
					});
					
					$("#buttons-area ul li a").append("<span class='hover'></span>");
					
					
					$("#buttons-area ul li a span.hover").hover(
						function () {
						
							$(this).animate( { opacity:"1" }, { queue:false, duration:500 } );
														
						}, 
						function () {
							
							$(this).animate( { opacity:"0" }, { queue:false, duration:500 } );

						}
					);
										
					$("#buttons-area ul li a span.hover").append("<span class='click'></span>");
					
					$("#buttons-area ul li a span.hover").mouseup(function(){

						$(this).find("span.click").animate( { opacity:"0" }, { queue:false, duration:250 } );				
							
					}).mousedown(function(){
		
						$(this).find("span.click").animate( { opacity:"1" }, { queue:false, duration:250 } );
						
					});

					$("input, textarea").focus(function() {
						var inputCheck = $(this).attr("value");
						
						if(inputCheck == $(this).attr("defaultfield"))	{							
							$(this).attr("value", "");
						}
					});									 
					
					$("input, textarea").blur(function() {
						if($(this).attr("value") == "") {
							$(this).attr("value", $(this).attr("defaultfield"));
						}
					});
					
					$("input").click(function() {
					
						if($(this).attr('calc') != "") {
							var totalCost = 0.00;
							var addToTotal = 0.00;
							$('input[type="radio"]:checked, input[type="checkbox"]:checked').each(function() {
								
								addToTotal = $(this).attr('calc') - 0;
								
								totalCost += addToTotal;
							});
							
							$('span.total').html(totalCost + ".00");
							$('input[name="price"]').attr("value", totalCost + ".00");
						}
					});	


});

