/**********/
/*  VARS  */
/**********/

var productStartRow = 0;
var storeStartRow = 0;

/***************/
/*  FUNCTIONS  */
/***************/

/***************/
/*  PAGE INIT  */
/***************/

$(document).ready(function() {
						   
	/***********************/
	/*  FEATURED PRODUCTS  */
	/***********************/  
	
	$(".featured-product").hide(function() {
		$("#featured-product-left").load("/includes/rpc.php?get=featuredProducts&productStartRow=" + productStartRow, function() {
			$(this).fadeIn("normal");
		});
		$("#featured-product-mid").load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 1), function() {
			$(this).fadeIn("normal");
		});
		$("#featured-product-right").load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 2), function() {
			$(this).fadeIn("normal");
		});
	});
	
	$("#featured-products-arrow-left").click(function() {
		productStartRow = productStartRow - 3;
		if (productStartRow < 0) {
			productStartRow = 0;
		}; //end if
		$("#featured-product-left").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + productStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#featured-product-mid").fadeTo("slow", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 1), function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#featured-product-right").fadeTo("slow", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 2), function() {
				$(this).fadeTo("normal", 1);
			});
		});
	});
	
	$("#featured-products-arrow-right").click(function() {
		productStartRow = productStartRow + 3;
		if (productStartRow > productCount - 1) {
			productStartRow = 0;
		}; //end if
		$("#featured-product-left").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + productStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#featured-product-mid").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 1), function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#featured-product-right").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=featuredProducts&productStartRow=" + (productStartRow + 2), function() {
				$(this).fadeTo("normal", 1);
			});
		});
	}); //end function
	
	/***********************/
	/*  ON SALE PRODUCTS   */
	/***********************/  
	
	$(".sale-product").hide(function() {
		$("#sale-product-left").load("/includes/rpc.php?get=saleProducts&productStartRow=" + productStartRow, function() {
			$(this).fadeIn("normal");
		});
		$("#sale-product-mid").load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 1), function() {
			$(this).fadeIn("normal");
		});
		$("#sale-product-right").load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 2), function() {
			$(this).fadeIn("normal");
		});
	});
	
	$("#sale-products-arrow-left").click(function() {
		productStartRow = productStartRow - 3;
		if (productStartRow < 0) {
			productStartRow = 0;
		}; //end if
		$("#sale-product-left").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + productStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#sale-product-mid").fadeTo("slow", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 1), function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#sale-product-right").fadeTo("slow", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 2), function() {
				$(this).fadeTo("normal", 1);
			});
		});
	});
	
	$("#sale-products-arrow-right").click(function() {
		productStartRow = productStartRow + 3;
		if (productStartRow > productCount - 1) {
			productStartRow = 0;
		}; //end if
		$("#sale-product-left").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + productStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#sale-product-mid").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 1), function() {
				$(this).fadeTo("normal", 1);
			});
		});
		$("#sale-product-right").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=saleProducts&productStartRow=" + (productStartRow + 2), function() {
				$(this).fadeTo("normal", 1);
			});
		});
	}); //end function
	
	/*****************************/
	/*  NEWSLETTER SUBSCRIPTION  */
	/*****************************/
	
	$("#newsletter-form").submit(function() {
		email = $("#newsletter-form-input").val();
		$("#newsletter-notice").fadeTo("normal", 0, function() {
			$("#newsletter-notice").load("/includes/rpc.php?get=newsletter&email=" + email, function() {
				$("#newsletter-notice").fadeTo("normal", 1);
			});
		});
	});
	
	/*******************/
	/*  STORE LOCATOR  */
	/*******************/
	
	$("#active-store").hide(function() {
		$("#active-store").load("/includes/rpc.php?get=store&storeStartRow=" + storeStartRow, function() {
			$(this).fadeIn("normal");
		});
	});
	
	$("#store-locator-arrow-left").click(function() {
		storeStartRow--;
		if (storeStartRow < 0) {
			storeStartRow = storeCount - 1;
		}; //end if
		$("#active-store").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=store&storeStartRow=" + storeStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
	});
	
	$("#store-locator-arrow-right").click(function() {
		storeStartRow++;
		if (storeStartRow > storeCount - 1) {
			storeStartRow = 0;
		}; //end if
		$("#active-store").fadeTo("normal", 0, function() {
			$(this).load("/includes/rpc.php?get=store&storeStartRow=" + storeStartRow, function() {
				$(this).fadeTo("normal", 1);
			});
		});
	});
	
});
