

$(document).ready(function() {

	/* ONLOAD FUNCTIONS */
	
	$("body").addClass("js_enabled");

	$("div.module_main_menu").addClass("js_enabled");
	centerNav();
	growContent();
	
	$('fieldset.delivery').hide();
	$('form#delivery > input#different_delivery').css('marginLeft', '-9999%');
	
	if($('input#different_delivery').attr('checked')) {
		$('fieldset.delivery').show();
	}
	
	$('label[@for=different_delivery]').click(function() {
		if($('input#different_delivery').attr('checked')) {
			hideDeliveryAddress();
		}
		else {
			showDeliveryAddress();
		}
	});
	
	
	/* CLEAR SEARCH BOX WHEN FOCUSED */
	
	$('div.module_search input').inputHint('Search term');
	
	
		
	
	/* HOMEPAGE IMAGE SLIDESHOW */
	
	$('ul.slideshow').cycle({ 
		fx: 'fade', 
		speed: 1500,
		timeout: 7800
		}
	);
	
	
	
	
	
});


//CENTER THE NAV UL WITHIN ITS CONTAINER
function centerNav() {
	var w = $('div.module_main_menu ul').width();	
	var c = $('div.module_main_menu').width();
	var m = Math.round((c - w) / 2);
	$('div.module_main_menu ul').css('margin-left', m);
}

//ENSURE CONTENT DIV IS ALWAYS TALLER THAN ADDITIONAL DIV
function growContent() {
	var h = $('div#additional').height();	
	$('div#homepage').css('min-height', h);
}

//HIDE AND SHOW DELIVERY ADDRESS
function showDeliveryAddress() {
	$("fieldset.delivery").slideDown("slow");
	$('input#different_delivery').removeAttr('checked');
}

function hideDeliveryAddress() {
	$("fieldset.delivery").slideUp("slow");
	$('input#different_delivery').attr('checked', 'checked');
}

$.fn.inputHint = function(val) {
	
	if(this.val() == '') {
		this.val(val);
	}
	
	this.unbind('focus').focus(function() {
		
		if($(this).val() == val) {
			$(this).val('');
		}
		
	})
	.blur(function() {
		
		if($(this).val() == val || $(this).val() == '') {
			$(this).val(val);
		}
		
	});
	
	
}