(function($){ 
	$.fn.Tabs = function() {
		var settings = $.extend({
				start:null, 
              	treturn:false
			}, arguments[0] || {});
		var self = this;
		var init = false;
		/* containers for the elements */
		var aList = null, idList = null; 
		/* Apply the click function */
		var list = $('a[href^="#"]',this).click(function(){ 
			/* return if already selected */
			if($('li.selected a',self)[0]==this){return settings.treturn;} 
			/* Set the id of the clicked element */
			var id = "#"+ this.href.split('#')[1]; 
			/* check if the list exists, and create them if not */
			if (!aList || !idList){
				aList=[];idList=[];
				$('a[href^="#"]',self).each(function(){ 
					aList.push(this); 
					idList.push("#"+ this.href.split('#')[1]); 
				}); 
			}
		  	/* Clear tabs, and hide all  */
		  	for(i in aList){$(aList[i]).parent('LI').removeClass('selected');}
		  	for(i in idList){$(idList[i]).hide();}
		  	/* Select clicked tab and show content  */
		  	$(this).parent('LI').addClass('selected'); 
			if(init){ $(id).fadeIn("normal"); }
			else{ $(id).show(); }
			init = true;			
		  	return settings.treturn; //Option for changing url 
		}); 
		
		/* Select default tab  */
		var test; 
		/* Start is a number */
		if(typeof settings.start == 'number' && (test=list.filter(':eq('+s.start+')')).length) 
			test.click(); 
		/* Start is the id */
		else if(typeof settings.start == 'string' && (test=list.filter('[href="#'+s.start+'"]')).length) 
			test.click(); 
		/* Check the location hash - can have multiples with a comma ie(#Tab1m,Tab2) */
		else if(location.hash && (test=list.filter('[href="'+ location.hash.replace(',','"],[href="#') +'"]')).length)
			test.click();
		/* Select the first tab */	
		else list.filter(":first").click();
	 
		return this;
	  }; 
	  $(function(){ $(".tabs").each(function(){$(this).Tabs(); }); }); 
})(jQuery);
