 
(function($) {  
    $.fn.smoothTabs = function(fadeSpeed) {
        // Visible index
        var currentIndex = 0;
        // Clicked tab class
        var smoothTabsLiCurrent = 'smoothTabsLiCurrent';
        // Hidden div class
        var smoothTabsDivHidden = 'smoothTabsDivHidden';
        // Visible div class
        var smoothTabsDivVisible = 'smoothTabsDivVisible';
        // Current hash if any.
        var hash = document.location.hash.substr(1, document.location.hash.length);

        if (hash && $('#'+hash, this).size()) {
            currentIndex = $('#'+hash, this).index();
        }

        // Makes first tab current, hides all divs and fades in the first one
        this.each(function() {
            $('ul li:eq('+currentIndex+')', this).addClass(smoothTabsLiCurrent);
            $(this).children("div").addClass(smoothTabsDivHidden);
            $('div:eq('+currentIndex+')', this).fadeIn(fadeSpeed)
            .addClass(smoothTabsDivVisible)
            .removeClass(smoothTabsDivHidden);
        });

        // Tab click function
        $('ul li', this).hover(function(){
            var $parentUl = $(this).parent();
            var $parentDiv = $($parentUl).parent();
            $('li', $parentUl).removeClass(smoothTabsLiCurrent);
            $(this).addClass(smoothTabsLiCurrent);
            var $clickedIndex = $('li', $parentUl).index(this);
            var $currentDiv = $('div', $parentDiv).get($clickedIndex);
                
            // If current tab is clicked - we're done
            if ($($currentDiv).attr('class') == smoothTabsDivVisible) {
                return false;
            }
                
            // Current div is replaced by the selected one
            $('.'+smoothTabsDivVisible, $parentDiv).fadeOut(fadeSpeed, function(){
                $($currentDiv).fadeIn(fadeSpeed).addClass(smoothTabsDivVisible).removeClass(smoothTabsDivHidden);
            });
            $('.'+smoothTabsDivVisible, $parentDiv).removeClass(smoothTabsDivVisible).addClass(smoothTabsDivHidden);
        });
    };
})(jQuery); 
