/*
 * TabMaster - Easy Tabbing
 *
 * Copyright (c) 2008 Fabrizio Fiandanese (creativepattern.com)
 *
 * $Date: 2009/03/04 03:39:46 $
 * $Rev: 110 $
 */

/**
 * Create a new TabMaster Object
 * @constructor
 */
function TabMaster(sSourceCssExp,sEventType)
{
	//Properties
	this.sEventType=sEventType;
	this.sEventType=(this.sEventType==null) ? 'click' : this.sEventType;
	
	this._sCssExp=sSourceCssExp;
	
	//Init
	this.init();
}

/**
* Inits TabMaster Object
* @method
*/
TabMaster.prototype.init = function()
{
	var oParent=this;
	
	switch(this.sEventType)
	{
		default:
			 // Assigning Click event callback
			$(this._sCssExp).each(function(i){
				
				//skip if rel=nofollow is found	
				if ( $(this).attr("rel") != 'nofollow' )  
				{	
					$(this).click(function() {oParent._onClick(i)} );
				}
			});
		break;
	}
}

/**
 * OnClick TabMaster Event
 * @method (private)
 */
TabMaster.prototype._onClick = function(sActiveTabIndex)
{
	//triggering callback

	 $(this._sCssExp).each(function(i){
		
			//Active class check
			if (sActiveTabIndex!=i)
			{			
				$(this).removeClass('active');
			}
			else
			{
				$(this).addClass('active');
			}

	});
};
