window.onload = function()
{
	jQuery("#basketItemsWrap li:first").hide();
	jQuery("#slidingTopContent").hide();
	
	jQuery("#slidingTopTrigger").live("click", function(event) {
      	jQuery("#slidingTopContent").slideToggle("slow", function(){
			if (jQuery("#slidingTopContent").is(":visible")) {
				jQuery("#slidingTopFooterLeft").html('<img src="../images/arrow-up.png" alt="Hide shortlist" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">Hide shortlist</a>');
			} else {
				jQuery("#slidingTopFooterLeft").html('<img src="../images/arrow-down.png" alt="Show shortlist" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">View shortlist</a>');
			}
		});
    }); 

	jQuery('.productPriceWrapRight a img').click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];

		
		if (jQuery("#slidingTopContent").is(":visible")) {

			jQuery("#notificationsLoader").html('<img src="images/loader.gif">');
		
			jQuery.ajax({  
			type: "POST",  
			url: "inc/functions.php",  
			data: { productID: productIDVal, action: "addToBasket"},  
			success: function(theResponse) {
				
				if( jQuery("#productID_" + productIDVal).length > 0){
					jQuery("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
					jQuery("#productID_" + productIDVal).before(theResponse).remove();
					jQuery("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
					jQuery("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
					jQuery("#notificationsLoader").empty();
					
				} else {
					jQuery("#basketItemsWrap li:first").before(theResponse);
					jQuery("#basketItemsWrap li:first").hide();
					jQuery("#basketItemsWrap li:first").show("slow");  
					jQuery("#notificationsLoader").empty();			
				}
				
			}  
			}); 

		}
		else {
			
			jQuery("#slidingTopContent").slideToggle("slow", function(){		
																 
				jQuery("#slidingTopFooterLeft").html('<img src="../images/arrow-up.png" alt="Hide shortlist" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">Hide shortlist</a>');
				jQuery("#notificationsLoader").html('<img src="../images/loader.gif">');
			
				jQuery.ajax({  
				type: "POST",  
				url: "inc/functions.php",  
				data: { productID: productIDVal, action: "addToBasket"},  
				success: function(theResponse) {
					
					alert(productIDVal);
					if( jQuery("#productID_" + productIDVal).length > 0)
					{
						jQuery("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						jQuery("#productID_" + productIDVal).before(theResponse).remove();
						jQuery("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						jQuery("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
						jQuery("#notificationsLoader").empty();
						
					} else {
						jQuery("#basketItemsWrap li:first").before(theResponse);
						jQuery("#basketItemsWrap li:first").hide();
						jQuery("#basketItemsWrap li:first").show("slow");  
						jQuery("#notificationsLoader").empty();			
					}
				}  
				}); 
				
				
				jQuery("#slidingTopTrigger").fadeTo(4000, 1, function(){
					jQuery("#slidingTopContent").slideToggle("slow", function(){
						jQuery("#slidingTopFooterLeft").html('<img src="../images/arrow-down.png" alt="Show shortlist" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">View shortlist</a>');												 
					});
					
				});

			});												 
		}
	});
	
	
	
	jQuery("#basketItemsWrap li img").live("click", function(event) {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];	
	
		jQuery("#notificationsLoader").html('<img src="/images/loader.gif">');
	
		jQuery.ajax({  
		type: "POST",  
		url: "/inc/functions.php",  
		data: { productID: productIDVal, action: "deleteFromBasket"},  
		success: function(theResponse) {
			
			var the_index = $.inArray(productIDVal, in_shortlist);
			in_shortlist = jQuery.grep(in_shortlist, function(value) { return value != the_index; });

			jQuery("#productID_" + productIDVal).hide("slow",  function() {
				jQuery(this).remove();
			});
			jQuery("#notificationsLoader").empty();
		
		}
					
		});
		return false;
	});
};

