/*
  @project  jquery.functions
  @name jquery.functions.js
  @author lukasz.tyrala
  @license  default
  @description  
*/

// VARIOUS FUNCTIONS
// See Wiki for more details on those functions

// INPUTS HOVERING
// Hides values of inputs

  jQuery.fn.inputHover = function() {
    return this.each(function() {
      if(!$(this).val()) $(this).val($(this).attr('title')) // Set default value if empty
      
      $(this).focus(function() {
        if ($(this).val() == $(this).attr('title'))                 // if value is default
        {
          $(this).val('');               // ... set empty value.
        }
      });
      
      $(this).blur(function() {
        if (!$(this).val())              // If no input from user...
        {
          $(this).val($(this).attr('title'));             // ... set default value.
        }
      }); 
      
    });
  }; // /fn.inputHover


// WRAPPERS
// Adds wrapping around/inside elements. To wrap inner content use .wrapContent('inner')

  jQuery.fn.wrapContent = function(what) {
    return this.each(function() {

      if ( what == 'inner' )
      {
        jq(this).wrapInner('<div class="wrapper"></div>');
      }

      else
      {
        jq(this).wrap('<div class="wrapper"></div>');
      }

    });

  }; // /fn.wrapContent


// MULTILEVEL NAVIGATION
// Hides 2nd level of navigation. Specify class name for sub navigation as ul_sub.

  jQuery.fn.multiNav = function(ul_sub) {
    return this.each(function() {

      var sub = ul_sub || 'sub';

      jq(this).find('.'+sub).hide();
      jq('ul li').hover(
        function () {
          jq(this).find('.'+sub).show();
          jq(this).parent('li').addClass('current');
        },
        function () {
          jq(this).find('.'+sub).hide();
        }
      );
    });
  }; //fn.multiLvl


// CONTENT IN TABS
// Displays content in tabs

    jQuery.fn.intabs = function(tab_id) {

      return this.each(function() {

        var start_tab       = tab_id || 0; // Tab index to start from

        // Settings ----------------------------
        var nav_element_def = '.tabs li'; // Avoid using class names for li as they are destroyed while changing a tab
        var sub_section_def = '.tabbed';
        var normal_def      = '.normal';
        var current_label   = 'current';
        // End od settings ---------------------

        var nav_element = jq(this).find(nav_element_def).not(normal_def);
        var sub_section = jq(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;
         });
       });

    }; //fn.intabs


// End
