$(document).ready(function() {

	/* ON LOAD FUNCTIONS */

	$("form input").addClass("default");
	$("form fieldset.delivery").hide();






	/* ADD FOCUS STYLES TO FORM ELEMENTS */

	$("form input").focus(function () {
		$(this).addClass("focus");
		}
	);
	
	$("form input").blur(function () {
		$(this).removeClass("focus");
		}
	);

	$("form textarea").focus(function () {
		$(this).addClass("focus");
		}
	);
	
	$("form textarea").blur(function () {
		$(this).removeClass("focus");
		}
	);
	





	/* REMOVE DEFAULT FORM VALUES ON FOCUS */
	
	$(".module_search input").inputHint('Search Term');




	/* TOGGLE DELIVERY ADDRESS VISIBILITY */

/*
	$("form input#different_delivery").toggle(function () {
		$(this).attr("checked","checked");
		$("form fieldset.delivery").slideDown("slow");
		},
		function () {
			$(this).attr("checked","");
			$("form fieldset.delivery").slideUp("fast");
			} 
	);
*/

	
	$('input#different_delivery').click(function() {
		if($(this).attr('checked')) {
			showDeliveryAddress(false);
		}
		else {
			hideDeliveryAddress(false);
		}
	});
	
	$('label[@for=different_delivery]').click(function() {
		
		if($('input#different_delivery').attr('checked')) {
			hideDeliveryAddress(true);
		}
		else {
			showDeliveryAddress(true);
		}
		
	});


});

$.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);
		}
		
	});
	
}

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

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