 /*
  * jQuery Tabify
  * author: www.theatomgroup.com
  * summary: provides tab features
  *
  */
 
// jQuery plugin closure 
 (function($, window, undefined) {
     // Attach to jQuery prototype
     // Context: (jQuery) Object of what the plugin is being run on
     // @_active: (String) Representing active className
     // @_content: (String) Selector representing all content elements
     // Returns: (jQuery) Object of what the plugin is being run on
     $.fn.tabify = function(_active, _content, _hash) {
            // Cache collection
            var $collection = this,
            	clicked = false;
            // Chainability
            // Context: (jQuery) Object iteration plugin will be run on.
            return this.each(function $each() {                
                // Caching iterative element
                var $element = $(this),
                    // Caching DOMElement
                    element = this,
                    // Cache content jQuery object
                    $content = $(_content);
                    
                // Mouse event to handle swapping active tab
                // Context: (DOMElement) 
                // @_evt: (Object) MouseEvent
                // Returns: (Undefined)
                $element.bind("click", function(_evt) {
                    // Cache context jQuery element
                    var $this = $(this),
                        // Store index value
                        index = $collection.index($this);
                    
                    // Revert exist active classes and set new active class
                    $collection.filter("."+_active)
                        .removeClass(_active);
                        
                    // Add the active class to this selected tab
                    $this.addClass(_active);
                                           
                    // Hide all existing content and show correct content
                    $content.hide()
                        .eq(index)
                        .show();
                        
                	return false;
                });
                
                // If ID support is available trigger the click
                if(_hash === true) {
                    $(location.hash, $content).trigger("click");
                }
                
                // Show first $content
                if(!clicked) {
                	$element.trigger("click");
                	clicked = true;
                }
          });
     };

// Standard wrapper closing and calling
})(jQuery, window, undefined);