function WishlistHandler(selector,redirect){ 

	$('.'+selector+'').live('click',function (event) {
		$('.'+selector+'').removeAttr('onclick');
		event.preventDefault();
		if (redirect){
			alert(redirect); 
			location = 'index.php?route=account/login';
			return;
		}
		var product_id = $(event.target).attr('id');
		var eventParent = $(event.target).parents('td');
		//flypage
        var picture = $('#image');
		if (eventParent.find('.list_picture img').length!=0){
			picture = eventParent.find('.list_picture img');
		}

		$.ajax({
				type: 'post',
				url: 'index.php?route=module/wishlist/addToWishlist',
				dataType: 'json',
				data: 'product_id='+product_id,
				beforesend: function(){
						//ajaxstart=true;
					},
				success: function (data) {
						if ($("#wishlist").length > 0) {
							$('#wishlist .middle').html($(data.html).find('.middle').html());
						}
					},
				complete: function () {
						if ($("#wishlist").length == 0) {
							window.location = 'index.php?route=wishlist/wishlist';
						}else{
							$('#wishlist').show();
							var image = picture.offset();
							var cart  = $('#wishlist').offset();
							
							picture.before('<img src="' + picture.attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

							params = {
								top : cart.top + 'px',
								left : cart.left + 'px',
								opacity : 0.0,
								width : $('#wishlist').width(),
								heigth : $('#wishlist').height()
							};

							$('#temp').animate(params, 'slow', false, function () {
								ajaxstart = false;
								$('#temp').remove();
							});
						}
					}
				});
	});
};
