/* 
	All Source Code is Copyright (2008) ShopDev: http://www.shopdev.co.uk
	All Rights Reserved.
	You are prohibited from copying or making derivitive works from any code herein without prior written permission of ShopDev.
*/

// START: document.ready
$(document).ready(function() {
	// START: Side Boxes
		// CATEGORIES --> Check For Current State
		var catNav=$.cookie('catNav');
		if (catNav=='off'){
		$('.toggleCategories').css("display","none");
		$('.boxTitleExpanded').css("display","none");
		$('.boxTitleCollapsed').css("display","block");
		}
		else {
		$('.toggleCategories').css("display","block");
		$('.boxTitleCollapsed').css("display","none");
		$('.boxTitleExpanded').css("display","block");
		}
	  
		// CATEGORIES --> When boxTitleExpanded Button Is Clicked:
		$('.boxTitleExpanded').click(function() {
		// Change The Button:
		$('.boxTitleExpanded').css("display","none");
		$('.boxTitleCollapsed').fadeIn(400);
		// Perform The Action:
		$('.toggleCategories').slideToggle(400);
		// Set The Cookie
		$.cookie('catNav', 'off');
		return false;
		});
	
		// CATEGORIES --> When boxTitleCollapsed Button Is Clicked:
		$('.boxTitleCollapsed').click(function() {
		// Change The Button:
		$('.boxTitleCollapsed').css("display","none");
		$('.boxTitleExpanded').fadeIn(400);
		// Perform The Action:
		$('.toggleCategories').slideToggle(400);
		// Set The Cookie
		$.cookie('catNav', 'on');
		return false;
		});
		
		// FEATURED PRODUCTS --> Check For Current State
		var featuredNav=$.cookie('featuredNav');
		if (featuredNav=='off'){
		$('.toggleFeatured').css("display","none");
		$('.boxTitleExpanded-featured').css("display","none");
		$('.boxTitleCollapsed-featured').css("display","block");
		}
		else {
		$('.toggleCategories-featured').css("display","block");
		$('.boxTitleCollapsed-featured').css("display","none");
		$('.boxTitleExpanded-featured').css("display","block");
		}
	  
		// FEATURED --> When boxTitleExpanded Button Is Clicked:
		$('.boxTitleExpanded-featured').click(function() {
		// Change The Button:
		$('.boxTitleExpanded-featured').css("display","none");
		$('.boxTitleCollapsed-featured').fadeIn(400);
		// Perform The Action:
		$('.toggleFeatured').slideToggle(400);
		// Set The Cookie
		$.cookie('featuredNav', 'off');
		return false;
		});
	
		// FEATURED --> When boxTitleCollapsed Button Is Clicked:
		$('.boxTitleCollapsed-featured').click(function() {
		// Change The Button:
		$('.boxTitleCollapsed-featured').css("display","none");
		$('.boxTitleExpanded-featured').fadeIn(400);
		// Perform The Action:
		$('.toggleFeatured').slideToggle(400);
		// Set The Cookie
		$.cookie('featuredNav', 'on');
		return false;
		});	
		
		// POPULAR PRODUCTS PRODUCTS --> Check For Current State
		var popularNav=$.cookie('popularNav');
		if (popularNav=='off'){
		$('.togglePopular').css("display","none");
		$('.boxTitleExpanded-popular').css("display","none");
		$('.boxTitleCollapsed-popular').css("display","block");
		}
		else {
		$('.toggleCategories-popular').css("display","block");
		$('.boxTitleCollapsed-popular').css("display","none");
		$('.boxTitleExpanded-popular').css("display","block");
		}
	  
		// POPULAR PRODUCTS --> When boxTitleExpanded Button Is Clicked:
		$('.boxTitleExpanded-popular').click(function() {
		// Change The Button:
		$('.boxTitleExpanded-popular').css("display","none");
		$('.boxTitleCollapsed-popular').fadeIn(400);
		// Perform The Action:
		$('.togglePopular').slideToggle(400);
		// Set The Cookie
		$.cookie('popularNav', 'off');
		return false;
		});
	
		// POPULAR PRODUCTS --> When boxTitleCollapsed Button Is Clicked:
		$('.boxTitleCollapsed-popular').click(function() {
		// Change The Button:
		$('.boxTitleCollapsed-popular').css("display","none");
		$('.boxTitleExpanded-popular').fadeIn(400);
		// Perform The Action:
		$('.togglePopular').slideToggle(400);
		// Set The Cookie
		$.cookie('popularNav', 'on');
		return false;
		});
		
		// MAIL LIST PRODUCTS --> Check For Current State
		var mailNav=$.cookie('mailNav');
		if (mailNav=='off'){
		$('.toggleMail').css("display","none");
		$('.boxTitleExpanded-mail').css("display","none");
		$('.boxTitleCollapsed-mail').css("display","block");
		}
		else {
		$('.toggleCategories-mail').css("display","block");
		$('.boxTitleCollapsed-mail').css("display","none");
		$('.boxTitleExpanded-mail').css("display","block");
		}
	  
		// MAIL LIST --> When boxTitleExpanded Button Is Clicked:
		$('.boxTitleExpanded-mail').click(function() {
		// Change The Button:
		$('.boxTitleExpanded-mail').css("display","none");
		$('.boxTitleCollapsed-mail').fadeIn(400);
		// Perform The Action:
		$('.toggleMail').slideToggle(400);
		// Set The Cookie
		$.cookie('mailNav', 'off');
		return false;
		});
	
		// MAIL LIST --> When boxTitleCollapsed Button Is Clicked:
		$('.boxTitleCollapsed-mail').click(function() {
		// Change The Button:
		$('.boxTitleCollapsed-mail').css("display","none");
		$('.boxTitleExpanded-mail').fadeIn(400);
		// Perform The Action:
		$('.toggleMail').slideToggle(400);
		// Set The Cookie
		$.cookie('mailNav', 'on');
		return false;
		});	
	// END: Side Boxes

	// START: Sale Items Showcase
		$('.showCase').cycle({ 
		fx:    'fade', 
		pause:  1,
		timeout:  4000
		});
		$('.showCase').hover(function() {
		$('.showCase').cycle('pause');
		$('.paused').fadeIn(400);
		},function(){
		$('.showCase').cycle('resume');
		$('.paused').fadeOut(400);
		return false;
		});
	// END: Sale Items Showcase

	// START: AJAX Add To Cart - Copyright ShopDev.co.uk 
		$("#ajaxCart").load('ajaxCart.php' + '?nocache=' + Math.random());
	// END: AJAX Add To Cart - Copyright ShopDev.co.uk 
	
	// START: Run Checkout Message
		checkoutMessage();
	// END: Run Checkout Message
	
	
});
// END: document.ready
	
	// START: AJAX Add To Cart - Copyright ShopDev.co.uk 
		var options = { 
			beforeSubmit: showRequest,
			success: showResponse
		}; 
		function doAddToCart(productID) { 
			$('#myForm'+productID).ajaxSubmit(options); 
			return false; 
		}; 
		
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 
			var formElement1 = jqForm[0]; 
			var prodID1 = formElement1[0].value;
			$('#AJAX-confirm-'+prodID1).css("display","none");
			$('#AJAX-process-'+prodID1).css("display","block");
			$('#buy-'+prodID1).css("background-position","0% -111px");
			return true; 
		} 
						  
		function showResponse(formData, jqForm, $form, options)  { 
			var formElement2 = $form[0]; 
			var prodID2 = formElement2[0].value;
			var opt = formElement2[2].value;
			if (opt == 1) {
				$('#AJAX-process-'+prodID2).remove();
				$('#AJAX-opt-'+prodID2).show();
				$('#buy-'+prodID2).css("background-position","0% -37px");
				$('#AJAX-options-'+prodID2).show();
				var noItems = $.cookie('noItems');
				var noItemsUpdated = noItems++;
				$.cookie('noItems', noItemsUpdated);
				var path = 'ajaxCart.php' + '?nocache=' + Math.random();
				$("#ajaxCart").load(path);
			}
			else {
			$('#AJAX-process-'+prodID2).remove();
			$('#AJAX-confirm-'+prodID2).show();
			$('#buy-'+prodID2).css("background-position","0% -74px");
			var noItems = $.cookie('noItems');
			var noItemsUpdated = noItems++;
			$.cookie('noItems', noItemsUpdated);
			var path = 'ajaxCart.php' + '?nocache=' + Math.random();
			$("#ajaxCart").load(path);	
			checkoutMessage();
			}
		}	
	// END: AJAX Add To Cart - Copyright ShopDev.co.uk
	
	// START: Checkout Message
		function checkoutMessage() {
			if($.cookie('noItems') > 0) {
				$("#checkoutNotice").css("display","block");
			}
		}
	// END: Checkout Message
