
(function($) {
	
   $.fn.svInitTab = function(settings) {
    
     var config = { 
    		 		'selected' : '1',
    		 		'tabCss' : 'tab-inactive',
    		 		'tabActiveCss' : 'tab-active',
    		 		'tabOverCss' : 'tab-over'
    		 	  };
     
     if (settings) $.extend(config, settings);
     
     this.each(function() 
     {
		var mainId = $(this).attr('id');
		svSelectTab(mainId, config);
         
		/* Set events for "tabs", click and hover fx */
		$("#"+ mainId +" > div:nth-child(1) > div")
		.bind('click', function() {
			i=1;
			$(this).prevAll().each(function(){i++});
            config.selected = i;
          	svSelectTab(mainId, config);
		})
		.bind("mouseenter mouseleave", function()
        {
        	if(!$(this).hasClass(config.tabActiveCss))
            	$(this).toggleClass(config.tabOverCss);
        });
     });
     
     return this;
   };
   
   var svSelectTab = function(mainId, config) 
   {
       $("#"+mainId+" > div:nth-child(2) > div > div > div").hide();
       $("#"+mainId+" > div:nth-child(2) > div > div > div:nth-child("+ config.selected +")").show();
       
       $("#"+mainId+" > div:nth-child(1) > div").removeClass(config.tabActiveCss + " " + config.tabCss + " " + config.tabOverCss);
       $("#"+mainId+" > div:nth-child(1) > div").addClass(config.tabCss);
       $("#"+mainId+" > div:nth-child(1) > div:nth-child("+ config.selected +")").removeClass(config.tabCss);
       $("#"+mainId+" > div:nth-child(1) > div:nth-child("+ config.selected +")").addClass(config.tabActiveCss);
	   
       $("#"+mainId+" > div:nth-child(1) > div:last").removeClass(config.tabActiveCss + " " + config.tabCss);
   };
   
}) (jQuery);
