var Wishlist = {
	// variables
	service:"services/wishlist.wsdl.php",
	
	// methods
	AddItem:function(id)
	{
		var post = {
			add:true,
			id:id
		}
		
		this.Send(post);
	},
	
	Remove:function(id)
	{
		var post = {
			remove:true,
			id:id
		}		
		
		this.Send(post);		
	},
	
	Quantity:function(id, amount)
	{
		var post = {
			quantity:true,
			id:id,
			amount:amount
		}		
		
		this.Send(post);		
	},
	
	Options:{
		Change:function(obj, id, dir)
		{
			var qty 	= $(obj).parent().parent().children(".Q");			
			var cost 	= $(obj).parent().parent().children(".P");						
			var amount = parseInt(qty.html()) + dir;
			if(amount > 0)
			{
				qty.html(amount);
				
				if(cost.html() > 0)
				{
					price = parseFloat(cost.html());
					price *= dir;
					total	= parseFloat($("#TotalPrice").html());
					total += price;					
					$("#TotalPrice").html(Math.round(total*100)/100);
				}
				
				var post = {
					quantity:true,
					id:id,
					amount:amount
				}
				
				Wishlist.Send(post, true);
			}
			else
			{
				var response = {
					title:"Oops!",
					message:"You have chosen to set the amount to zero (0). If you wish to remove the product, please click the remove button!"
				}
				
				ModalController.Load('WishlistModal', response);
			}
		},
		Remove:function(obj, id)
		{
			Wishlist.Remove(id);
			var tbody = $(obj).parent().parent().parent();
			$(obj).parent().parent().remove();			
			
			if($(tbody).children("tr").length == 0)
			{
				$(tbody).parent().remove();
				$("#None").fadeIn();
			}
		}
	},
	
	Send:function(post, modal)
	{
		var service = this.service;
		$.ajax(
			{
				url:service,
				cache:false,
				data:post,
				dataType:"json",
				type:"POST",
				success:function(response)
				{
					if(!modal)
					{
						ModalController.Load('WishlistModal', response)						
					}
				},
				error:function()
				{
					console.log("failed:" + service);
				}
			}
		);		
	}	
}