/**************************************************

Filename:		wishItem.js
Date Modified:	June 28, 2011
Modified By:	David Lackey

Dependencies:	http.js

Description:	javascript file for dealing with
				Wishlist

**************************************************/

// Create namespace and specify some meta-information
WishItem = {};
WishItem.NAME = "WishItem";
WishItem.VERSION = 1.0;

/*************************************************

Remove wish item

**************************************************/

WishItem.remove = function(itemID, element)
{
	// url for ajax
	var url = './ajax/wishItemAjax.php';
	// callback function
	var callback = function(x)
	{	
		$(element).closest('.wish').hide('fast');
		// Check remaining wishes
		WishItem.checkRemaining();
	};
	// options object
	var options = {};
	options.parameters = {};
	// parameters
	options.parameters.action = 'remove';
	options.parameters.itemID = itemID;
	
	// ajax through post method
	HTTP.post(url,callback,options);
	
	// Disable link
	return false;
}

/*************************************************

Insert wish item

**************************************************/

WishItem.insert = function(type,typeID,element)
{	  
	// url for ajax
	var url = './ajax/wishItemAjax.php';
	
	// callback function
	var callback = function(x)
	{	
		if (!isNaN(parseInt(x)))
		{
			$(element).html('Added');
			$(element).attr('href', 'profile.php');
			$(element).attr('onclick', '');
		}
	};
	// options object
	var options = {};
	// parameters object of options object
	options.parameters = {};
	// parameters
	options.parameters.action = 'insert';
	options.parameters.type = type;
	options.parameters.typeID = typeID;	
	// ajax through post method
	HTTP.post(url,callback,options);
        
    // do not allow the form to submit
    return false;
}

/*************************************************

Insert wish item

**************************************************/

WishItem.checkRemaining = function()
{
	var wishes = $('.wishlist').find('.wish:visible');
	// Subtract 1 due to delay
	if ((wishes.length - 1) <= 0)
	{
		$('#emptyWishes').slideDown('fast');
	}
}
