;(function($) {
	
	$.fn.tabs = function(opts)
	{
		// Ensure we have a pane selector
		if (typeof opts == 'string')
		{
			opts = 
			{
				pane: opts
			};
		}	
		
		// Keep a cache of all elements for removing selected classes and such
		var $all = $(this);
		
		// Add a click handler and index to each element
		this.each(function(index)
		{
			var $this = $(this);
			
			// Index will be used for opening up the item
			$(this)
				.attr('tabs-index', index)
				.click(function(e) 
				{
					// Close all others
					$(opts.pane)
						.hide()
						.eq(index)
						.show();
					
					// Select only this one
					$all.removeClass('selected');
					$(this).addClass('selected');
					
					// Prevent Default on click
					e.preventDefault();
				});
		});
		
		// Default selection? Click it
		if ($all.filter('.selected').length)
		{
			$all.filter('.selected').click();
		}
		// Show the first
		else
		{
			$all.eq(0).click();
		}
		
		return this;	
	};
	
})(jQuery);
