/* 
  @project  intabs
  @name jquery.intabs.js
  @created  2008-11-11
  @version  0.1 (beta)
  @svn  http://intabs.googlecode.com/svn/trunk/
  @url  http://code.google.com/p/intabs
  @license  MIT License (http://www.opensource.org/licenses/mit-license.php)
  @author Lukasz Tyrala (http://lukasztyrala.pl/)
  @description  A jQuery Plugin for tabbed content browsing that needs no id only class names
  @contributors pblo, Jan, Adrian
*/

/*
  Basic step by step usage:
  
  1. Create xhtml that goes like this:
     [OPTIONAL] Add class "normal" to li that you do not want to be a tab
     
      <div class="your-container">

        <ul class="tabs">
          <li>[1]</li>
          <li>[2]</li>
          <li>[3]</li>
        </ul>

        <div class="sub-section"> [1] </div>

        <div class="sub-section"> [2] </div>

        <div class="sub-section"> [3] </div>

      </div> <-- /.your-cantainer -->

  2. Tell the plugin which elements are containers for tabbed content:
  
      $('your-container').intabs();

  3. Enjoy!
     [OPTIONAL] If not (a) try to improve by yourself, (b) give me a feedback

*/

;jQuery(function($) {

  ;(function($) {
    jQuery.fn.intabs = function(tab_id) {

      return this.each(function() {

        if (tab_id == undefined) tab_id = 0;
        var start_tab       = tab_id; // Tab index to start from

        // Settings ----------------------------
        var nav_element_def = '.tabs li';
        var sub_section_def = '.sub-section';
        var normal_def      = '.normal';
        var current_label   = 'current';
        // End od settings ---------------------

        var nav_element = $(this).find(nav_element_def).not(normal_def);
        var sub_section = $(this).find(sub_section_def);

        var sub_section_start = sub_section.eq(start_tab);
        var nav_element_start = nav_element.eq(start_tab);

        sub_section.hide();
        sub_section_start.show();
        nav_element.addClass('');
        nav_element_start.addClass(current_label);

        nav_element.click(function() {
          var nav_index = nav_element.index(this);

          // @todo Give user possibility to choose effects
          sub_section.hide();
          sub_section.eq(nav_index).show();

          nav_element.removeAttr('class');
          nav_element.eq(nav_index).addClass(current_label);
          return false;
         });
       });


    };                        // /jQuery.fn.intabs = function() {

  })(jQuery);                 // /function($) {

});                           // /jQuery(function($) {
