﻿$(document).ready(function() {

    $(".tabContent").hide(); //hide all content

    // check to see if a tab has been specified in the URL on page load
    var url = location.href;
    var querystring = "";
    if (url.lastIndexOf('?') > 0) {
        querystring = new String(url.substring(url.lastIndexOf('?') + 1));
    }

    var sep = querystring.indexOf('&');
    if (sep > 0)
        querystring = querystring.substring(0, sep);
    var selectedTab = "#" + querystring.toLocaleLowerCase();
    var defaultTab = "#" + "_default";

    // use _default tab if no get param or selected tab does not exist
    if (querystring == "" || $(selectedTab).length <= 0) {
        selectedTab = defaultTab;
    }

    if ($(selectedTab).length > 0) { //found tab with given name
        if (selectedTab.toLocaleLowerCase() != defaultTab.toLocaleLowerCase())
            $(selectedTab).addClass("active");
        $(selectedTab + "Content").css("visibility", "visible");
        $(selectedTab + "Content").show();
    }
    else {

        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tabContent:first").css("visibility", "visible"); //Show first tab content
        $(".tabContent:first").show(); //Show first tab content
    }
    //click handler
    $("ul.tabs li").click(function(event) {

        if ($(this).hasClass("empty") == false) {
            selectedTab = "#" + $(this).attr("id");  //find the selected tab

            $("ul.tabs li").removeClass("active");
            $(this).addClass("active"); //make the current tab active

            $(".tabContent:not(" + selectedTab + "Content)").css("visibility", "hidden");  //hide the unselected tab in CSS

            $(selectedTab + "Content").css("visibility", "visible");

            $(selectedTab + "Content").show();
            $(".tabContent:not(" + selectedTab + "Content)").hide();  //collapse it

            return false;
        }
        return true;

    });
});

