/*
*	Lib: Sitevision jQuery
*	Author: Kent C @ Strateg
*	
*	Creates functionality for tabs
*	You need to style it with your own CSS, sorry
*	Some TODOs
*
*	Takes a couple of parameters:
*	@hoverclass: CSS class to add to tab element when hover
*	@activeclass: CSS class to add to tab elment when active
*	@opentab: Index of current active tab
*	@contentholder: The class name of div holding acctually content to be shown, defaults to class name .tab_content
*	@myclass: Dont touch.
*/

(function($){  
$.fn.svsimpletab = function(options) {
		
	/* Settings */
	var defaults = {
		hoverclass: '',
		activeclass: '',
		opentab: 0,
		contentholder: 'tab_content',
		myclass: $(this).attr("class")
	};
	
	var options = $.extend(defaults, options);
	/* Inits */
	var current_content_ix = options.opentab;
	
	/* Set default values for hover and active classes */
	if(!options.hoverclass > '')
		options.hoverclass = $(this).attr("class") + "-hover";
	if(!options.activeclass > '')
		options.activeclass = $(this).attr("class") + "-active";
		
	/** End settings **/
	
	this.each(function(){
		// Init per tab
		var $tab = $(this);
		var myix = $tab.parent().index();
		// If this one should open by default, TODO: support stateful urls
		if(myix == options.opentab) {
			$tab.addClass(options.activeclass);
			$("."+ options.contentholder).eq(myix).show();
		}
		
		/***/
		$tab
		.hover(function(){
			$(this).addClass(options.hoverclass);	
		},function(){
			$(this).removeClass(options.hoverclass);
		})
		.click(function(){
			if(current_content_ix == myix) // if current tab is active, do nothing
				return;
				
			$("."+ options.myclass).removeClass(options.activeclass);
			$tab.addClass(options.activeclass);
			
			/** Change contentholder **/
			var $content = $("."+ options.contentholder).eq(myix);
			
			$("."+ options.contentholder).hide();
			$content.fadeIn("fast");
			
			current_content_ix = myix;
		});
		
	});
};  
})(jQuery);
