// JavaScript Document
// used on item_detail09 and viewcart09 so far 
//  function add to cart
$(document).ready(function() {
		function addToBag() {
		$('#addToCart').livequery('click', function() {
		$('#addFormError').append('<div id="form_error"></div>');											
		var queryString = $('#buy_main').serialize(); 
		
	 	$(this).find('#addToCart').before('<img src="ajax-loader.gif" class="loader" />');
				$.ajax({
			'type': "GET",
			'url': "addToCart.php",
			'data': queryString,
			'success': function(html){
				
				$('#form_error').html(html);
				$('this img.loader').fadeOut(500,function(){$(this).remove()});
				$('#form_error').fadeOut(5000,function(){$(this).remove()});
				$('#bagReplace').html('<span class="quickView">Quick View</span>');
				
				openMiniBag();
			 }			
		});  
			
			return false;
		});
	  }
	

	  
	  function openMiniBag() { 
		$('#bagReplace').livequery('click', function() {
			
				$('#hiddenBag').fadeIn('slow')
				 .animate({opacity: 1.0}, 3000)
				 .fadeOut('slow');
				$.ajax({
					'type': "GET",
					'url': "miniBag09.php",
					'success': function(html){	
					
			    $("#hiddenBag").html(html);
											 }
						});  
				return false;
			
				
				});
	
	}
	
		
	 	addToBag();
	
		 });
						  
//update mini basket on rollover
$(document).ready(function() {
		$('#bagReplace').livequery('click', function() {
			
				$('#hiddenBag').fadeIn('slow')
				 .animate({opacity: 1.0}, 3000)
				 .fadeOut('slow');
				$.ajax({
					'type': "GET",
					'url': "miniBag09.php",
					'success': function(html){	
					
			    $("#hiddenBag").html(html);
				
											 }
						});  
				return false;
			
				
				});
		
	});	 
			



 //try update cart form with jQuery
 
 $(document).ready(function() {
	 $('[id^=update_delete]').livequery('submit', function() { 
	
	 var queryString = $(this).serialize(); 
	 $(this).find('#spin').before('<img src="ajax-loader.gif" class="loader" />');
	 
			$.ajax({
			'type': "POST",
			'url': "update_cart09.php",
			'data': queryString,
			'success': function(html){										   
				$("#cartRefresh").html(html)
				$('this img.loader').fadeOut(500,function(){$(this).remove()});
				$('#cartRefresh .discountMsg, .msg2').fadeOut(5000,function(){$(this).remove()});
				
				$.ajax({
			'type': "GET",
			'url': "subTotal.php",
			
			'success': function(html){										   
				$("#rewriteTotal").html(html);
			}
					   });
			 }
			
		});  return false;
		});
	 
		});								   

// for promobox
$(document).ready(function(){

	$('#openDiscount').click(function(){
	  $('#discountBox').slideToggle("slow");
	   $('#discountBox').removeClass('displayNone');
	});

});

// check promo
$(document).ready(function() {
	 $('#checkPromo').click(function() {
			$('#checkPromo').before('<img src="ajax-loader.gif" class="loader" />')
			.attr('disabled','disabled');
		$.ajax({
			'type': "POST",
			'url': "update_cart09.php",
			'data': {'promo_code2':$('#promo_code2').val()},
			'success': function(html){
				$("#cartRefresh").html(html);
					
				$.ajax({
			'type': "GET",
			'url': "subTotal.php",
			
			'success': function(html){										   
				$("#rewriteTotal").html(html);
			}
					   });
				$('#checkPromo').removeAttr('disabled');
				$('#discountBox img.loader').fadeOut(500,function(){$(this).remove()});
				 $('#discountBox').slideUp("slow");
			}
		});return false;
		});
		});

////shipping rollover is this overKill?
$(document).ready(function() {
$('#shippingStick').mouseover(function() { 
			if($('#shippingInfo').hasClass('displayNone')){
				$('#shippingInfo').toggle();
				$('#shippingInfo').removeClass('displayNone');
				$('#shippingInfo').addClass('displayNormal');
				$('#shippingInfo').load('shipping.html');
				
			}
				else {
						 $('#shippingInfo').removeClass('displayNormal');
						$('#shippingInfo').addClass('displayNone');
						$('#shippingInfo').toggle();
					   }
				});
$('#shippingStick').mouseout(function() { 
			if($('#shippingInfo').hasClass('displayNormal')){
				$('#shippingInfo').toggle();
				$('#shippingInfo').removeClass('displayNormal');
				$('#shippingInfo').addClass('displayNone');
			
			}
				else {
						 $('#shippingInfo').removeClass('displayNone');
						$('#shippingInfo').addClass('displayNormal');
						$('#shippingInfo').toggle();
					   }
				});
						   });

$(document).ready(function() {
$('#returnStick').mouseover(function() { 
			if($('#shippingInfo').hasClass('displayNone')){
				$('#shippingInfo').toggle();
				$('#shippingInfo').removeClass('displayNone');
				$('#shippingInfo').addClass('displayNormal');
				$('#shippingInfo').load('returns.html');
				
			}
				else {
						 $('#shippingInfo').removeClass('displayNormal');
						$('#shippingInfo').addClass('displayNone');
						$('#shippingInfo').toggle();
					   }
				});
$('#returnStick').mouseout(function() { 
			if($('#shippingInfo').hasClass('displayNormal')){
				$('#shippingInfo').toggle();
				$('#shippingInfo').removeClass('displayNormal');
				$('#shippingInfo').addClass('displayNone');
			
			}
				else {
						 $('#shippingInfo').removeClass('displayNone');
						$('#shippingInfo').addClass('displayNormal');
						$('#shippingInfo').toggle();
					   }
				});
						   });
//show warehousetip added 27 feb 09
 $(document).ready(function() {
			$('#warehouseSale a.wTip').mouseover(function() {
				$('#wTip').html('Clicking this takes you to a new site. Purchases between At The Net and the Warehouse Sale cannot be combined at this time.');
				$('#wTip').addClass('background');
				});
			
			$('#warehouseSale a.wTip').mouseout(function() {
				$('#wTip').empty();
				$('#wTip').removeClass('background');
					 });
				});
