jQuery(document).ready(function($){ 

	$("#wishlistWrap li:first").hide();
	
	$(".wishlist a").click(function() {
		if ($(this).hasClass("req")){ 
		tb_show("",
              "#TB_inline?height=100&width=275&inlineId=hiddenLogin","");
			  return;
		}
		var splitter = (this.id).split("_");
		var id = splitter[1];
		var name = this.title;
		$("#wishlistLoader").html('<img src="../../wp-content/plugins/wishlist/images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "wp-content/plugins/wishlist/inc/add.php",  
		data: { productID: id, productName: name},  
		success: function(theResponse) {
			if( $("#productID_" + id).length > 0){
				$("#productID_" + id).animate({ opacity: 0 }, 500, function() {
				$("#productID_" + id).before(theResponse).remove();
				});				
				$("#productID_" + id).animate({ opacity: 0 }, 100);
				$("#productID_" + id).animate({ opacity: 1 }, 100);
				$("#wishlistLoader").empty();			
			} else {
				$("#wishlistWrap li:first").before(theResponse);
				$("#wishlistWrap li:first").hide();
				$("#wishlistWrap li:first").show(500);  
				$("#wishlistLoader").empty();			
			} 
		}  
		});  
		
	});
	
	
	$("#wishlistWrap li img").live("click", function(event) { 
														
		var splitter = (this.id).split("_");
		var id = splitter[1];	
	
		$("#wishlistLoader").html('<img src="../../wp-content/plugins/wishlist/images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "wp-content/plugins/wishlist/inc/delete.php",  
		data: { productID: id},  
		success: function(theResponse) {
			
			$("#productID_" + id).hide(500,  function() {$(this).remove();});
			$("#wishlistLoader").empty();
		
		}  
		});  
		
	});

});
