//tab
$.fn.tabSwitch = function(options){
  
  var c = $.extend({
    defaultCondition: true,
    effect: false
  },options);
  
  var switchEffect = {
    show: function(o){
      if(c.effect) $(o).fadeIn("normal");
      else $(o).show();
    },
    hide: function(o){
      if(c.effect) $(o).fadeOut("fast");
      else $(o).hide();
    }
  }
  
  function tabHide(o,flag){
    if(flag || !c.defaultCondition){
      $(o).each(function(){
        switchEffect.hide(this.hash);
      });
    }else{
      if($(o).hasClass("active")){
        $(o).each(function(){
          if(!$(this).hasClass("active"))
            switchEffect.hide(this.hash);
        });
      }else{
        for(var i=0;i<o.length;i++){
          if(i==0) $(o[i]).addClass("active");
          else switchEffect.hide(o[i].hash);
        }
      }
    }
  }
  
  function tabSet(o){
    $(o).each(function(){
      var anchor = $("ul.tab a",this).filter(function(){return this.hash;});
      for(var j=0;j<anchor.length;j++){
        tabHide(anchor,false);
        $(anchor[j]).click(
          function(){
            tabHide(anchor,true);
            $(anchor).not(this).removeClass("active");
            switchEffect.show(this.hash);
            $(this).addClass("active");
            $(this).blur();
            return false;
          }
        );
      }
      if(location.hash && $(location.hash,this).length>0){
        window.scroll(0,0);
        tabHide(anchor,true);
        $(anchor).removeClass("active");
        switchEffect.show(location.hash);
        $("a[href*='"+location.hash+"']","ul.tab").addClass("active");
      }
    });
  }
  
  $(this).each(function(){ tabSet(this);});
  
  return this;
}
