$(function() {
			
			
			function supports_input_placeholder() {
  				var i = document.createElement('input');
  				return 'placeholder' in i;
			}
		
			if (!supports_input_placeholder()) {
				var $search = $('#search-box');
				var placeholder = $search.attr('placeholder');
				$search.css({ color: '#999' }).val(placeholder);
				$search.click(function() { $(this).val('').css({ color: '#333' }); });
			}
		
			/* Checkout page */
    		$('#new_customer').change(function() {
        		$(this).is(':checked') ?
        		($('#password_form').slideUp(), $('#your-details-button').html('Create account')) :
        		($('#password_form').slideDown(), $('#your-details-button').html('Log me in'));
    		});

    		$('.terms-and-conditions').click(function(e) {
				e.preventDefault();
				$('.terms-and-conditions').after('<div id="terms-conditions-text" />');
				$('#terms-conditions-text').hide().load('cms.php?pid=4 #content', function(data) {
				   $(data).appendTo('#terms-conditions');
				   $(this).slideDown();
				});
			});
    		
    		/* Helps user to get their address accross into a delivery address */
    		/*$('#same-as-billing-address').click(function(e) {
    			e.preventDefault();
	    		var address = ['input[name=address1]', 'input[name=address2]', 'input[name=address3]', 'input[name=postcode]'].join(',');
				var del_address = ['input[name=del_address1]', 'input[name=del_address2]', 'input[name=del_address3]', 'input[name=del_postcode]'];
				/* Iterate through address pushing the value accross to the devliery field */
				/*$(address).each(function(i) {
	    			$(del_address[i]).val($(this).val());
				});
			});*/
			
			/* End */
			
			
			/* Products */
			
			$('.product-image-thumbnails').find('a').click(function(e) {
        		e.preventDefault();
        		var thumb = $(this).attr('href');
        		$('.product-image').find('img').attr('src', thumb);
    		});
			
			/* End */
			
			
			/* Product Reviews */
		
			$(".product-reviews").hide();
			//$("#see-reviews").click(function(event) {
			//	event.preventDefault();
				$("#see-reviews").toggle(
					function() {
						$(".product-reviews").show();
						$("#see-reviews").html("Hide product reviews");
					}, function() {
						$(".product-reviews").hide();
						$("#see-reviews").html("Product reviews");
					}
				);
			
			/* End */
			

			/* Products list */

			$("#show-products").click(function(event) {
				event.preventDefault();
				$("#categories-list").toggle();
			});
			
			
			/* End */
			
			
			/* Product request */
			
			
			$(".bg").css("height", $(document).height());
			$("#product-request").click(function(event) {
				event.preventDefault(); 
 
				$("#box").load("productrequest.html");
				$("#box").append();
				$(".bg").fadeIn("fast");
			});
		
		
		$("#close-product-request").live("click", function(e) { 
			e.preventDefault();
			$(".bg").fadeOut("fast");
		});
		
		$(document).keypress(function(e) {
			if (e.keyCode == '27') {
				$(".bg").fadeOut("fast");
			}
		});
		
		/* END */
			
	/* Postage Expense */
	if ($('#expensive-postage').length) {
    	$('#expensive-postage').wrapInner('<a href="#" />');
    	$('#expensive-postage-info').hide();
    	$('#expensive-postage').click(function(e) {
    		e.preventDefault();
    		$('#expensive-postage-info').slideToggle('fast');
		});
	}
	
	/* End */
	
	/*
	For the top link
	Check how high the page is then enter a link to the top if needed :)
	*/
	
	($('#content').height() > $('document').height()) && $('#content').append('<a href="#" id="go-to-top">Top ^</a>');
			
});
