$(function(){
	
	Cufon.replace('h2.script', {
		fontFamily: 'bickham',
		textShadow: '#826e6f 0px 1px 5px, #fce6e6 0px -1px'
	});
	Cufon.replace('h2.normal, h3',{
		fontFamily: 'futura'
	});
	// Cufon.replace('h2', { fontFamily: 'Bickham Script Pro' });
	// Cufon.replace('h2.normal', { fontFamily: 'Futura Book Normal' });
	
	/* Add 'focus' class to input wrappers
	----------------------------------------------*/
	$('input, textarea').focus(function(){
		$(this).parent().addClass('focus');
	});
	$('input, textarea').blur(function(){
		$(this).parent().removeClass('focus');
	});
	/* !end */
	
	
	$('#navigation li:last-child').addClass('last-child');
	$('#navigation li:first-child').addClass('first-child');
	$('#menu-footer li:last-child').addClass('last-child');
	$('table#cart-list td:first-child, table#cart-list th:first-child').addClass('first-child');
	
	/* Clear the search input box
	----------------------------------------------*/
	var search_initial = $('form#search input#searchterm').val();
	$('form#search input#searchterm').focus(function(){
		if( $(this).val() == search_initial ){
			$(this).val('');
		}
	});
	$('form#search input#searchterm').blur(function(){
		if( $(this).val() == '' ){
			$(this).val(search_initial);
		}
	});
	/* !end */
	
	var productOptions = false;
	var productIdSelect = false;
	$('#product #productId').each(function(){
		productSelectClone = this.cloneNode(true);
		productOptions = productSelectClone.getElementsByTagName("option");
		productIdSelect = this;
	});
	$("#colours li a").click(function(){
		// update the selected color
		$("#colours li.selected").removeClass("selected");
		$(this).parent().addClass("selected");
		
		// remove all options from the select, then append any that match class names
		while (productIdSelect.options.length) { productIdSelect.remove(0); }
		var pattern2 = new RegExp("( |^)(" + $(this).attr('class') + ")( |$)");
		for (var i = 0; i < productOptions.length; i++) {
			if (productOptions[i].className.match(pattern2)) {
				productIdSelect.appendChild(productOptions[i].cloneNode(true));
			}
		}
		productIdSelect.selectedIndex = 0;
		
		// update the selected color htmnl
		var colourDesc = $(this).parent().find("span").html();
		$("#colour-status").html("Your selected colour is "+colourDesc);
		return false;
	});
	$("#colours li.selected a:first-child").click();
	
	$('#print-page').click(function(){
		window.print();
		return false;
	});
	
	/* Sigh...
	----------------------------------------------*/
	$('.cart-checkout-login label[for=user_email]').html('Please provide your email address').addClass('user-email');
	$('.cart-shipping-estimate form').prepend('<p>Please select your delivery region.</p>');
	$('#cart-list .cart-item-code').prepend('Style number ');
	$('#different_billing_address').parent().addClass('different_billing_address');
	$('#checkout-payment-ccform').prepend('<h4>Credit Card</h4>');
	$('#checkout-payment-details p:first label:first').text('Please select one of the following payment options.');
	$('#member-delivery-details').append('<div class="clear">&nbsp;</div>');
	$('#member-delivery-details').prepend('<h3>Order Details</h3>');
	/*!end */
	
	$('#checkout-payment-ccform p strong').parent().remove();
	$('#checkout-payment-ccform').append('<input type="hidden" value="" name="cc_type" id="cc_type">');
});
