//Tab Switcher
//Author: Marghoob Suleman | Search me on google
// jquery.tabs.js
// version : 1.0
;(function($){
		   var msMyTabs = function(element, options) {
			   options = $.extend({
								  tabs:'a',
								  contentSuffix:'_content',
								  event:'click',
								  selected:'selected',
								  effects:'fade',
								  callback:'',
								  defaultTab:'',
								  auto:0,
								  }, options);		
			   var $this = this; //class object
			   var elementid = $(element).attr("id");
			   var oProp = new Object();
			   oProp.old = "";
			   var intid = 0;
			   function init() {
				   $("#"+elementid + " " + options.tabs).bind(options.event, function() {
																					  $this.switchTab(this.id);
																					  });
				   if(options.defaultTab=='') {
					   options.defaultTab = $("#"+elementid + " " + options.tabs)[0].id;
				   }
				   $this.switchTab(options.defaultTab);
				   if(options.auto>0) {
					   //make it auto tab
					   //working here
					   //intid = window.setInterval();
				   }
			   }
			   this.switchTab = function(evt) {
				   if(typeof(evt)!="string") {
					   evt.preventDefault();
					   evt.stopPropagation();
				   } else if(typeof(evt)=="string") {
					   $("#"+evt).show();
				   }
				   var id = (typeof(evt)=="string") ? evt : $(this).attr("id");
				   var content = id+options.contentSuffix;
				   if(oProp.old!="") {
					  $("#"+oProp.old).removeClass(options.selected);
					  if(options.effects=='fade') {
						  $("#"+oProp.oldContent).fadeOut("fast", function(evt) {$("#"+content).fadeIn("fast");});
					  } else {
						  $("#"+oProp.oldContent).slideUp("fast", function(evt) {$("#"+content).slideDown("fast");});
					  }
				   } else {
					   if(options.effects=='fade') {
							$("#"+content).fadeIn("fast"); 
					   } else {
						   $("#"+content).slideDown("fast"); 
					   }
				   }
				    $("#"+id).addClass(options.selected);
				   oProp.old = id;
				   oProp.oldContent = content;
				   if(options.callback!='') {
					   eval(options.callback)(id);
				   }
			   };
			   function autoTabs() {
				   
			   }
			   init();
		   }		   		   
	   $.fn.tabs = function(opt) {  
			return this.each(function() {
								  var element = $(this);
								  var myplugin = new msMyTabs(element, opt);
								  element.data("msTabs", myplugin);								  
								  });		   
	   }
   })(jQuery);
