function clearDefaultValue() {
	if (this.value == this.defaultValue) this.value = '';
	$(this).css('color','#3c3933');
}
function replaceDefaultValue() {
	if (!this.value.length) this.value = this.defaultValue;
	$(this).css('color','#777');
}
function openEmailSignUpForm() {
	var email = $('#emailSignUp input[name=emailAddr]').attr('value');
	tb_show("Sign-Up for our Email Newsletter","/store/features/EmailSignUp?KeepThis=true&email="+email+"&TB_iframe=true&height=400&width=375",null);
	$("#emailSignUp form").blur();
	return false;
}


google.load("jquery","1.2");		
google.setOnLoadCallback(function() {
	$(document).ready(function() {
		$('input[type=text][value!=]').focus(clearDefaultValue).blur(replaceDefaultValue);
		
		$("#emailSignUp form").submit(openEmailSignUpForm);
		$("#emailSignUp form a").click(openEmailSignUpForm);
		
		$("#deliveryArea form").submit(function(){
			var zipCode = $('#deliveryArea input[name=zipCode]').attr('value');
			if (zipCode == 'Your Zip Code') zipCode = 'Not Specified';
			else zipCode = zipCode.substr(0,5);
			tb_show("Delivery Area Lookup: <strong>"+zipCode+"</strong>","/store/features/DeliveryCheck?KeepThis=true&zipCode="+zipCode+"&TB_iframe=true&height=250&width=375",null);
			this.blur();
			return false;
		});
		$('#prodInfo .buttons a:first').click(function() {
			$.get(this,function(data, status){
				$('#prodInfo .buttons a:first img').attr('src','/images/buttons/shoppingList_off.gif');
				$('#messageBox, #errorBox').remove();
				var waitStr = "$('#prodInfo .buttons a:first img').attr('src','/images/buttons/shoppingList.gif');";
				
				if (status == 'success') {
					
					var itemStr = $('#shoppingListInfo p strong').text();
					var itemCount = new Number(itemStr.substring(0,(itemStr.indexOf(' ')))) +1;
					var endStr = " item";
					if (itemCount != 1) endStr = endStr + "s";
					
					$('#shoppingListInfo p strong').text(itemCount+endStr);
					waitStr = waitStr + " $('#content').prepend($('<p id=\"messageBox\">This item was added to your <a href=\"/store/features/ShoppingList\">Shopping List</a>.</p>'));"
				} else {
					waitStr = waitStr + " $('#content').prepend($('<p id=\"errorBox\">We're sorry, but this item could not be added to your <a href=\"/store/features/ShoppingList\">Shopping List</a>. Please try again later.</p>'));"
				}
				setTimeout(waitStr,750);
			});
			return false;
		});
	});
});