﻿var tabSwitcher = {
    activeTab: null,

    tabClick: function() {
        if (tabSwitcher.activeTab != $(this).attr('href')) {
            $(tabSwitcher.activeTab).fadeOut('def');
            $('a[href=' + tabSwitcher.activeTab + ']').removeClass('active');


            $($(this).attr('href')).fadeIn('def');
            $(this).addClass('active');

            tabSwitcher.activeTab = $(this).attr('href');
        }
        return false;
    },

    init: function() {
        var anchor = window.location.href.split('#');
        var target = (anchor.length > 1) ? anchor[1] : 'Default';

        tabSwitcher.activeTab = '#' + target;

        $('div.tab-content').each(function() {
            if ($(this).attr("id") != target) { $(this).hide(); }
            else {
                $(this).show();
                var link = $('a[href=#' + $(this).attr("id") + ']');
                $(link).addClass('active');
            }
        });

        $('#tabs ul.vpnav a').click(tabSwitcher.tabClick);
    }
};

$(tabSwitcher.init);