/**
/* Sample:
/*      $('#tab_wrapper').dsTab();
/*      <div id="tab_wrapper">                                  // wrapper element - can have any attributes
/*          <div class="tabbed_links">                          // link wrapper - div.tabbed_links is default (tabSelector)
/*              <a class="active" href="" rel="one">Tab One</a> // tab link - rel points to tab boxes, put active class on default tab (activeClass and activeSelector)
/*              <a href="" rel="two">Tab Two</a>                //  href is not used
/*          </div>
/*          <div class="tab_box" id="one_box">Box One</div>     // tab box - div.tab_box is default (tabSelector)
/*          <div class="tab_box" id="two_box">Box Two</div>     //  default id is <rel>+'_box' (relPostfix)
/*      </div>
/*
/* Parameters:
/*      linkSelector:   'div.tabbed_links'  // Selector for a wrapper around the tab links
/*      tabSelector:    'div.tab_box'       // Selector for the tab boxes 
/*      activeSelector: 'a'                 // Selector for the element that the active class is applied to
/*      activeClass:    'active'            // Class that is applied to the active tab link
/*      relPostfix:     '_box'              // Last part of tab box id that comes after the
/*                                          //  tab link's rel - default looks like '<rel>_box'
/*                                          //  where '_box' is the relPostfix
/*      after:  function(clickedLink, shownBox){}   //callback made when a tab is clicked, after swap
 */
jQuery.fn.dsTab = function(params) {
    var $ = jQuery;
    var params = params || {};
    params.linkSelector = params.linkSelector || 'div.tabbed_links';
    params.tabSelector = params.tabSelector || 'div.tab_box';
    params.def = params.def || 0;
    params.activeSelector = params.activeSelector || 'a';
    params.activeClass = params.activeClass || 'active';
    params.relPostfix = params.relPostfix || '_box';
    params.after = params.after || function(){};
    $(params.linkSelector+' a', this).click(function(e){
        if( params.def == 0 ){ e.preventDefault(); }
        var tabbedLinks = $(this).closest(params.linkSelector);
        tabbedLinks.find('.'+params.activeClass).removeClass(params.activeClass);
        if(params.activeSelector=='a'){
            $(this).addClass(params.activeClass);
        }else{
            $(this).closest(params.activeSelector).addClass(params.activeClass);
        }
        tabbedLinks.parent().find(params.tabSelector).hide();
        var showBox = $('#'+$(this).attr('rel')+params.relPostfix);
        showBox.show();
        params.after(this, showBox[0]);
    });
    $(params.tabSelector,this).hide();
    if(params.activeSelector=='a'){
        var e=$(params.linkSelector+' a.'+params.activeClass, this);
    }else{
        var e=$(params.linkSelector+' .'+params.activeClass+' a', this);
    }
    var showBox = $('#'+e.attr('rel')+params.relPostfix);
    showBox.show();
    params.after(e[0], showBox[0]);
    return this;
}

