﻿// JavaScript Document
var loadingGraphic = '<img src="/assets/images/loading.gif">';

$(document).ready(function() {
	//QuickAdd Form//
	quickOrder.clearData();
	productSearch.clearData();
	emailSubscribe.clearData();
	emailSubscribe.processForm();
	homepagePods.managePods();
});

homepagePods = {
	managePods: function() {
		
		//Show first element//
		$(".homepageFeature").eq(0).css({'display' : 'block'});
		$(".homepageFeatureButton").eq(0).addClass("homepageFeatureButtonActive");
		
		//Set class on last button element as last to remove margin/padding
		$(".homepageFeatureButton:last").addClass("last");
		
		//Set click events on all buttons
		$(".homepageFeatureButton").eq(0).bind("click", function() {
			$(".homepageFeature").css({'display' : 'none'});
			$(".homepageFeature").eq(0).fadeIn("fast").css({'display' : 'block'});	
			$(this).siblings().removeClass("homepageFeatureButtonActive");
			$(this).addClass("homepageFeatureButtonActive");
		})
		$(".homepageFeatureButton").eq(1).bind("click", function() {
			$(".homepageFeature").css({'display' : 'none'});
			$(".homepageFeature").eq(1).fadeIn("fast").css({'display' : 'block'});	
			$(this).siblings().removeClass("homepageFeatureButtonActive");
			$(this).addClass("homepageFeatureButtonActive");
		})
		$(".homepageFeatureButton").eq(2).bind("click", function() {
			$(".homepageFeature").css({'display' : 'none'});
			$(".homepageFeature").eq(2).fadeIn("fast").css({'display' : 'block'});	
			$(this).siblings().removeClass("homepageFeatureButtonActive");
			$(this).addClass("homepageFeatureButtonActive");
		})
		$(".homepageFeatureButton").eq(3).bind("click", function() {
			$(".homepageFeature").css({'display' : 'none'});
			$(".homepageFeature").eq(3).fadeIn("fast").css({'display' : 'block'});	
			$(this).siblings().removeClass("homepageFeatureButtonActive");
			$(this).addClass("homepageFeatureButtonActive");
		})
	}
	
},

quickOrder = {
	clearData: function() {
		$("#quickOrder input").focus(function() {
			$(this).attr('value','');
		});
		$("#quickOrder input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	}
},

productSearch = {
	clearData: function() {
		$("#searchForm input").focus(function() {
			$(this).attr('value','');
		});
		$("#searchForm input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	}
},




emailSubscribe = {
	clearData: function() {
		$("#subscribeForm input").focus(function() {
			$(this).attr('value','');
		});
		$("#subscribeForm input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	},
	processForm: function() {
		$("#subscribeForm form").submit(function(){
			formLabelsAndValues=$("#subscribeForm form").serialize();
			$("#subscribeForm").html(loadingGraphic);
			$.post('/components/subscribe/process.cfm',formLabelsAndValues, function(response) {
				emailSubscribe.formResponse(response);
			});
			return false;
		});	
	},
	formResponse: function(response) {
		$("#subscribeForm").html(response);
		emailSubscribe.processForm();
	}
}




/*
function quickORd
			$("#f-log-email").focus(function() {
				$(this).attr('value','');
			});
			$("#f-log-email").blur(function() {
				if ($(this).val() == "") {
					$(this).val($(this)[0].defaultValue);
				}
			});

								<form method="post" id="quickOrder">
									<input type="text" name="sku" value="sku" style="width: 40px;"> <input type="text" name="quantity" value="1" style="width: 14px; text-align: center;">
									<button class="defaultBtn"><span>Add To Cart</span></button>
								</form>
*/
