(function($){
  var tabid = 0;
  
    
    
  main = function() {

  
   $(".dharmatab").height(250);
   $(".dharmatab").hide();
   $(".dharmatab:first").show();
   
   $(".dharmatab").each(function(idx){
   
   $(this).addClass("tab"+idx);
     
  //Generate Tab Links
  $("#dharmatabctr").append('<div class="crt" id=crt'+idx+'></div>');
  
  $(".crt").css('cursor', 'pointer');

  
   
   //Click to show
   $("#crt"+idx).click(function() {
     slidecar(idx);
     
     
     
  });
  //End Click to show
  
  
  

   
});
   $(".crt").css({'margin-right':'10px', 'width':'30px', 'height':'30px', 'background-color':'#ff0000', 'display':'block','float':'left','clear':'none'});
   $(".crt").css({opacity:0.5});
   $("#crt0").css({opacity:1});
   $("#crt0").addClass("tabactive");
   $("#crt1").css({'background-color':'#ff3333'});
   $("#crt2").css({'background-color':'#cc0000'});
   var ctrl = (($(".crt").length)*30)+(($(".crt").length)*10);
   $("#dharmatabctr").width(ctrl);
   
   //Automated Slide
    
   var autoslide = setInterval(function() { autocar(tabid)},5000);
   
   //Stop Automation on Mouseover
   $(".dharmatab").mouseover(function(){
      clearInterval(autoslide);
     
    }).mouseout(function(){
      autoslide = setInterval(function() { autocar(tabid)},5000);
    });
    
    $(".crt").mouseover(function(){
      clearInterval(autoslide);
     
    }).mouseout(function(){
      autoslide = setInterval(function() { autocar(tabid)},5000);
    });

  
   }
   
   
   
  slidecar = function(tabid) {
  
  
   $(".dharmatab").hide();
   $(".tab"+tabid).show();

   
   $(".crt").css({opacity:0.5},500);
   $(".crt").removeClass("tabactive");
   $("#crt"+tabid).css({opacity:1},500);
   $("#crt"+tabid).addClass("tabactive"); 
   
  
  
  }
  
  autocar = function(tabid) {
  
  //tabid = $(".tabactive").index(".crt");
 
  //var tabnext = tabid+1;
  tabid++;
  if (tabid == ($(".crt").length)) {
  
  tabid = 0;
  
  } 
  slidecar(tabid);
  
  
  }
 

})(jQuery);
