function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

jQuery(document).ready(function($){
	$('#search-input,#footer-bottom form .textbox').click(function() {
		$(this).val("");
	});
	
	$("a[rel='lightbox']").colorbox({transition:"fade"});
	
	jQuery('#mainmenu-nav').accordion({
	selectedClass: 'selected',
	navigation: true,
	autoHeight: false,
	active: '.selected',
	alwaysOpen: false
	});

	// free shipping text
	var re = /1st Class/gi;
	var myStr = $("#shipping-select option:selected").text();
	var myNumber = Number(myStr.replace(/[^0-9\.]+/g,""));
	if (myNumber == "0.001"){
		//only replace text with FREE if shipping rate is £0.00
		var newStr = myStr.replace(re, "FREE");
		$("#shipping-select option:selected").text(newStr);
	}

	var configuration = {path: '/', domain: shopDomain};

	$("#haggle-now a, #ship-quote a").click(function(){
		var productTitle = 'Item '+jQuery('#product-meta p:first span').text()+' - '+jQuery('h1#product-title').text();
		jQuery.cookie('doeandhope_offer', productTitle, configuration);
	});

	$("#haggle-now a").colorbox({width:"600px", height:"80%", iframe:true});
	$("#ship-quote a").colorbox({width:"600px", height:"80%", iframe:true});
	
	$("#footer-bottom form .submit").click(function(){
		var textboxVal = $("#footer-bottom form .textbox").val();
		if (textboxVal) {
			if (isValidEmailAddress(textboxVal)){
				alert ("Thanks, we've added you to our list");
			} else {
				alert ("Please enter a valid email address.");
				return false;
			}
		} else {
			alert ("Please enter your email address");
			return false;
		}
	});
	
	
});