function showLeather(numSwatches){
	var i = 0;
	$('.productOptionPickListSwatch li').each(function(){
		if(i < numSwatches)$(this).show();
		else $(this).hide();
		
		i++;
	});
}
function showNylon(numSwatches){
	var i = 0;
	$('.productOptionPickListSwatch li').each(function(){
		if(i < numSwatches)$(this).hide();
		else $(this).show();
		
		i++;
	});
}
function readySwatch(numSwatches){
	$('.productAttributeLabel label span.name').each(function(){
		if($(this).text().indexOf('Material') > 0){
			var inputID = $(this).parents('label').attr('for');
			inputID = "#"+inputID;
			$(inputID).change(function(){
				var selectedOption = $(inputID).find(':selected').text();
				switch(selectedOption){
					case 'Leather': showLeather(numSwatches[0]);break;
					case 'Nylon': showNylon(numSwatches[1]);break;
					case 'Rainy Nylon': showNylon(numSwatches[1]);break;
					default:break;
				}
			});
		}
	});
}
// Returns an Array w/ (numLeatherSwatches,startNylonSwatches)
// Assuming Swatch Lists start with Leather, and Nylon Swatches 
// go from start to end of list
function numSwatches(page){
	switch(page){
		//Women's Wallets
		case 'checkbook-wallet': return new Array(5,5);break;
		case 'coin-pocket-wallet': return new Array(2,1);break;
		case 'womens-original': return new Array(5,5);break;
		case 'womens-sport': return new Array(5,5);break;
		case 'petite-wristlet': return new Array(5,5);break;
		case 'clip-n-go' : return new Array(5,5);break;
		//International Coin Purse
		case 'coin-purse': return false;break;
		case 'international-wallet-black-leather': return false;break;
		//Inside ID
		case 'inside-id': return new Array(2,1);break;
		//Original Wallet
		case 'original-wallet': return new Array(2,1);break;
		//Card Case
		case 'card-case': return new Array(2,1);break;
		//Outside ID
		case 'outside-id': return new Array(1,0);break;
		//Sport Wallet
		case 'sport-wallet': return new Array(2,1);break;
		//Traveler Wallet
		case 'traveler-wallet': return new Array(2,1);break;
		default:return false;break;
	}
	return false;
}
function readyProductPage(){
	var page = window.location.href;
	page = page.substr(23,(page.length-24));
	var swatches = numSwatches(page);
	if(swatches instanceof Array){
		readySwatch(swatches);
		showLeather(swatches[0]);
	}
}
function printPrice(element,nylonPrice){
	var priceEM = $(element).find('.ProductPriceRating em');
	priceEM.prepend('Leather: ');
	priceEM.append('<br/>'+nylonPrice);
}
function linkListItem(element, name){
	$(element).wrap("<a href=\"http://www.all-ett.com/"+name+"/\" ></a>");
}
function printPricesSwitch(element){
	var name = $(element).find('.ProductDetails a').attr('href');
    name = name.substr(23,(name.length-24));
	linkListItem(element, name);
	
    switch(name){
		//Women's Wallets
		case 'checkbook-wallet':printPrice(element,'Rainy Nylon: $32.95');break;
		case 'coin-pocket-wallet':printPrice(element,'Nylon: $24.95');break;
		case 'womens-original':printPrice(element,'Rainy Nylon $26.95');break;
		case 'womens-sport':printPrice(element,'Rainy Nylon: $14.95');break;
		case 'petite-wristlet':printPrice(element,'Rainy Nylon $24.95');break;
		case 'clip-n-go' :printPrice(element,'Rainy Nylon: $17.95');break;
		//International Coin Purse
		case 'coin-purse':printPrice(element,'Nylon: $9.95');break;
		case 'international-wallet-black-leather':printPrice(element,'Nylon: $19.95');break;
		//Inside ID
		case 'inside-id':printPrice(element,'Nylon: $19.95');break;
		//Original Wallet
		case 'original-wallet':printPrice(element,'Nylon: $19.95');break;
		//Card Case
		case 'card-case':printPrice(element,'Nylon: $7.95');break;
		//Outside ID
		case 'outside-id':printPrice(element,'Nylon: $19.95');break;
		//Sport Wallet
		case 'sport-wallet':printPrice(element,'Nylon: $14.95');break;
		//Traveler Wallet
		case 'traveler-wallet':printPrice(element,'Nylon: $19.95');break;		
		default:console.log(name);break;
	}
}
function readyContinueButton(){
	$('#CheckoutStepShippingProvider input[value=Continue]').click(function(){
		setTimeout('$(\'div:contains("Hear From Us Via Email")\').last().hide();',750);
	});
}
function readyShippingButton(){
	$('#CheckoutStepShippingAddress input.shippingButton').click(function(){
		setTimeout('readyContinueButton();',750);
	});
}
function readyCheckout(){
	//Repositioning Email Addr. in Billing Fields
	$('dl dt:eq(0)').insertAfter('dd:eq(2)');
	$('dl dd:eq(0)').insertAfter('dt:eq(2)');
	//Repositioning Country in Billing Fields
	$('#CheckoutStepBillingAddress dl dt:eq(8)').insertAfter('#CheckoutStepBillingAddress dd:eq(10)');
	$('#CheckoutStepBillingAddress dl dd:eq(8)').insertAfter('#CheckoutStepBillingAddress dt:eq(10)');
	//Repositioning Country in Shipping Fields
	$('#CheckoutStepShippingAddress dl dt:eq(7)').insertAfter('#CheckoutStepShippingAddress dd:eq(9)');
	$('#CheckoutStepShippingAddress dl dd:eq(7)').insertAfter('#CheckoutStepShippingAddress dt:eq(9)');
	//Adjusting Credit Card Font Size
	$('#provider_list label').css('font-size','14pt');
	//Hiding Spam Option
	$('#CheckoutStepBillingAddress input.billingButton').click(function(){
		if($(this).val().indexOf('Ship') > 0)setTimeout('readyContinueButton();',750);
		else setTimeout('readyShippingButton();',750);
	});
}
$(document).ready(function(){
	readyProductPage();
	
	$('#CategoryContent ul.ProductList li').each(function(){
		printPricesSwitch(this);
	});
	$('#HomeFeaturedProducts ul.ProductList li').each(function(){
		printPricesSwitch(this);
	});
	$('#SideTopSellers ul.ProductList li').each(function(){
		printPricesSwitch(this);
	});
	
	//Checkout Page
	if(window.location.href.indexOf("checkout.php") >= 0){
		setTimeout('readyCheckout();',750);
	}
	
});




