﻿var scroll_to_x = 0;
var scroll_to_y = 0;

$(document).ready(function () {

    


    if (window.location.href.indexOf("CONTENT=") != -1) {
        var tab = getParameterByName("CONTENT");
        $("ul.tabs li a").removeClass("activeTab");
        $('#' + tab + 'a').addClass("activeTab"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = '#' + tab; //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(500); //Fade in the active content


        if (window.location.href.indexOf("PRODUCT=") != -1) {

            var subtab = getParameterByName("PRODUCT");
            
            showSubTab('#' + subtab);
        }

    }
    else {
        //Default Action
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li:first a").addClass("activeTab").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content
    }

    //On Click Event
    $("ul.tabs li").click(function () {
        scroll_to_x = window.pageXOffset;
        scroll_to_y = window.pageYOffset;

        $("ul.tabs li a").removeClass("activeTab");
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab + 'a').addClass("activeTab"); //Add "active" class to selected tab
        $(activeTab).fadeIn(500); //Fade in the active content
        
        window.scroll(scroll_to_x, scroll_to_y);
        return false;
    });

});

function showSubTab(id) {
    scroll_to_x = window.pageXOffset;
    scroll_to_y = window.pageYOffset;

    $('#CATS').hide();
    $('#TAKTIX').hide();
    $('#ELIBRARY').hide();

    

    $(id).fadeIn(500);

    window.scroll(scroll_to_x, scroll_to_y);
    return false;
}

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}
