$(function(){
	
	$('img').noContext();
	
	$("#top-search input").example("Search...");
	$("#newsletterInput").example("Email address...");
	
	$("#pg-header-nav-menu").dropmenu({
		subnavHideDelay : 600
	});
	
	/*
	$('#newsletterUnsubscribeLink a').click(function(){
			$this = $(this);
			$newsletterDescription = $('#newsletterDescription');
			$signupType = $('#newsletterForm #signupType');
			if($this.text()=='(click to unsubscribe)'){
				$this.text('(click to subscribe)');
				$signupType.val('unsubscribe');
				$newsletterDescription.text('Unsubscribe from our newsletter:');
			}
			else {
				$this.text('(click to unsubscribe)');
				$signupType.val('subscribe');
				$newsletterDescription.text('Sign up to our newsletter:');
			}
		});
	*/
	$('#newsletterForm')
		.FormFingerprint()
		.submit(function() {
			var emailField = $("#newsletterInput");
			emailField.css("background-color","#fff");
			
			var outputDiv = $("#newsletterFormResponse");    
			outputDiv.hide();
			outputDiv.html("");
			outputDiv.stopTime("hideOutputDivTimer"); //clear any previous timer that may hide the response div
						
			var hasError = false;
			
			if(jQuery.trim(emailField.val())=="") { outputDiv.append("Email address is required.<br>"); emailField.css("background-color","#FFCCCC"); hasError=true; }
			else if(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(jQuery.trim(emailField.val())) == false) { outputDiv.append("Invalid email address format.<br>"); emailField.css("background-color","#FFCCCC"); hasError=true; }      

			var color = (!hasError ? "#000" : "#CC0000");
			outputDiv.css("color",color);

			if (!hasError){
				$(this).ajaxSubmit({
						dataType: "json",
						success: processNewsletterFormJson
				});
			}
			else {
				outputDiv.slideDown(350);
			}
			return false; //important
			
					
			//process the response of the newsletter form submission
			function processNewsletterFormJson(data){ 
				$formResponse = $("#newsletterFormResponse");
				$formResponse.html(data.message);
				var color = (data.success ? "#000" : "#CC0000");
				$formResponse.css("color",color);
				$formResponse.slideDown(350);
				if(data.success){  //only clear form on success
					$('#newsletterInput').addClass('example').val('Your email address...');
					$formResponse.oneTime("5s", "hideOutputDivTimer", function(){ $(this).slideUp(350) });
				} 
			}
		});
		
	$('.addSEOCartProducts').click(function() { 
		$this = $(this);
		$seocart_ProductSubcategoryContainer = $('div.seocart_ProductSubcategoryContainer');
		
		$seocart_productIds = $seocart_ProductSubcategoryContainer.find('input[name^="product_id"]');
		$seocart_productIdData = $seocart_productIds.serialize();

		$.ajax({
			type: "POST",
			url: "/cart",
			data: $seocart_productIdData,
			success: function(){
				location.href='/cart';				
			}
		});
	});
	
	$('#contentShoppingCartPage select[name="billing_cardtype"]').after('<img style="margin-left:5px; vertical-align:bottom; padding:0;" src="/images/managed/credit_card_logos.jpg" alt="Visa, Mastercard, Discover, American Express" border="0">');
	
});
