if (typeof(eWishlistManagerObject) == 'undefined') 
{
    eWishlistManagerObject = function(ajaxEventVar, ajaxEventUID)
    {
    	this.ajaxEventVar = ajaxEventVar;
    	this.ajaxEventUID = ajaxEventUID;
	    this.loader = new eAJAXLoaderObject();

	    this.event = null;
	    this.productId = null;

    	this.addButtonContent = 'Add To Wishlist';
    	this.removeButtonContent = 'Remove From Wishlist';
    }
}
eWishlistManagerObject.prototype.setAddButtonContent = function(content)
{
    this.addButtonContent = content;
}
eWishlistManagerObject.prototype.setRemoveButtonContent = function(content)
{
    this.removeButtonContent = content;
}
eWishlistManagerObject.prototype.actionItem = function(productVariationId, action, qty, callbackFunction)
{    
	this.loader.show('Please wait ...');
	
	var currentObject = this;
		
	var postData = { __callHandler: action, 
					 productVariationId: productVariationId,
					 qty: qty
	}; 
	postData[this.ajaxEventVar] = this.ajaxEventUID;
	
	$.post(selfUrl, postData,	
	function(responseData) {
		
		currentObject.loader.hide();
		
	    if ((typeof(showAJAXDebugInfo) != 'undefined') && responseData.PHPAJAXDebug != null) 
	    {
	        showAJAXDebugInfo(responseData.PHPAJAXDebug.Info, responseData.PHPAJAXDebug.Owner);
	    }
	    currentObject.updateInfoPanel();
		
		if (typeof callbackFunction == 'function'){
			callbackFunction(responseData);
		}
	},
	'json');
}
eWishlistManagerObject.prototype.addItem = function(productId)
{    
	this.event = 'add';
	this.productId = productId;
	$('#wishbutton' + this.productId).unbind('click');
	
	this.loader.show('Please wait ...');
	
	var currentObject = this;
	
	var postData = { __callHandler: 'addToWishlist', 
			productId: productId
	}; 
	postData[this.ajaxEventVar] = this.ajaxEventUID;
	
	$.post(selfUrl, postData,	
			function(responseData) { 
		currentObject.onGetResponse(responseData); 
	},
	'json');
}
eWishlistManagerObject.prototype.removeItem = function(productId)
{    
    this.event   = 'remove';
    this.productId = productId;
    $('#wishbutton' + this.productId).unbind('click');
    
	this.loader.show('Please wait ...');
	
	var currentObject = this;
		
	var postData = { __callHandler: 'removeFromWishlist', 
	  		         productId: productId
	}; 
	postData[this.ajaxEventVar] = this.ajaxEventUID;
	
	$.post(selfUrl, postData,	
	function(responseData) {
  		currentObject.onGetResponse(responseData); 
	},
	'json');
}
eWishlistManagerObject.prototype.setInfoPanel = function(infoPanelObject)
{
    this.infoPanelObject = infoPanelObject;
}
eWishlistManagerObject.prototype.updateInfoPanel = function()
{
    if (typeof(this.infoPanelObject) == 'object')
    {
        this.infoPanelObject.loadInfo();
    }
}
eWishlistManagerObject.prototype.onGetResponse = function(responseData)
{
	var currentObject = this;
	
	this.loader.hide();
	
    if ((typeof(showAJAXDebugInfo) != 'undefined') && responseData.PHPAJAXDebug != null) 
    {
        showAJAXDebugInfo(responseData.PHPAJAXDebug.Info, responseData.PHPAJAXDebug.Owner);
    }
	
	var productId = currentObject.productId;
	if (responseData.Response.Code != 0)
	{
		alert(responseData.Response.Message);
		
        switch (this.event)
        {
            case 'add':
                $('#wishbutton' + this.productId).bind('click', function() {
                    currentObject.addItem(productId);
                });                
                break;
            case 'remove':
                $('#wishbutton' + this.productId).bind('click', function() {
                    currentObject.removeItem(productId);
                });                
                break;
        }
	}
	else
	{
        switch (this.event)
        {
            case 'add':
                $('#wishbutton' + this.productId).html(this.removeButtonContent);                
                $('#wishbutton' + this.productId).bind('click', function() {
                    currentObject.removeItem(productId);
                });                
                break;
            case 'remove':
                $('#wishbutton' + this.productId).html(this.addButtonContent);                
                $('#wishbutton' + this.productId).bind('click', function() {
                    currentObject.addItem(productId);
                });                
                break;
        }
        
        this.updateInfoPanel();
	}
}
