/**
 * DOM-based object that initiates and handles a category plans tab capabilities
 *
 */
function PlansTabsCategory(id)
{
	var This = this;
	
	this.id = id;
	this.element = $('#'+id);
	
	// Load category's plans upon click
	this.plans_select = function(event)
	{
		return plans_tabs_select($(this).attr('href'), event);
	}
	
	// Shows remove button
	this.show_remove_button = function()
	{
		if(!session_user_id) { return; } // don't show button if there's no session user
		
		if(!This.remove_element)
		{
			This.remove_element = $('<img src="/images/icons/remove.png" class="plans_tabs_category_remove" />');
			This.remove_element.bind('click', This.remove);
			
			This.element.append(This.remove_element);
		}
		
		This.remove_element.show();
	};
	
	// Hides remove button
	this.hide_remove_button = function()
	{
		if(This.remove_element)
		{
			This.remove_element.hide();
		}
	};
	
	// Removes tab
	this.remove = function(event)
	{
		event.stopPropagation();
		
		if(!confirm('Are you sure you want to remove this category from your tabs?')) { return false; }
		
		category_unsubscribe({ category_id: This.element.attr('category_id') });
		
		return false;
	}
	
	this.element.bind('click', this.plans_select);
	this.element.bind('mouseover', this.show_remove_button);
	this.element.bind('mouseout', this.hide_remove_button);
}
