/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

$(document) .ready(function () {

    // Add click handlers to all items.
    $('.menu li>a') .each(function (i) {
        var href = this .href;
        $(this) .parent() .click(function (e) {
            window.location = href;
        });
    });

    $(".menu li") .click(function (e) {
        $(".menu li") .removeClass("active");
        // now open the selected tab
        switchToTab(e.target.id);
    });

    // Get the currently active item and load the appropriate tab:
    var activeId = 'welcome';
    var tmp = $('.menu li.active') .get(0);
    if (tmp != null) {
        activeId = tmp.id;
    }

    switchToTab(activeId);
});
function switchToTab(id) {
    // close all tabs first
    $("#mainNav > div") .css("display", "none");

    // now open the selected tab
    switch (id) {
        case "home" :
        $("#home") .addClass("active");
        $("div.home") .css("display", "block")
        break;
        case "raceInfo" :
        $("#raceInfo") .addClass("active");
        $("div.race") .css("display", "block")
        break;
        case "newsCenter" :
        $("#newsCenter") .addClass("active");
        $("div.news") .css("display", "block")
        break;
        case "tickets" :
        $("#tickets") .addClass("active");
        $("div.tickets") .css("display", "block")
        break;
        case "infield" :
        $("#infield") .addClass("active");
        $("div.infield") .css("display", "block")
        break;
        case "visitorsGuide" :
        $("#visitorsGuide") .addClass("active");
        $("div.visitors") .css("display", "block")
        break;
        case "preaknessTradition" :
        $("#preaknessTradition") .addClass("active");
        $("div.tradition") .css("display", "block")
        break;
    }
}

function selectNavItem(id)
{
    if (id != "")
        $("#"+id).addClass("selectedNavItem");
}

