﻿$(document).ready(function() {
    $("#header .tab").each(function(i) {
        $(this).append("<div class='left'></div>");
        $(this).append("<div class='right'></div>");

        if ($(this).hasClass("has-dropdown"))
            $(this).append("<div class='arrow'></div>");

        if ($(this).hasClass("selected"))
            $(this).find(".arrow").addClass("arrow-selected");
    });

    $("#header .tab .left").click(function() {
        window.location = $(this).siblings("a:first").attr("href");
    });

    $("#header .tab").mouseenter(function() {
        $(this).addClass("hovered");
        $(this).find(".arrow").addClass("arrow-hovered");
    });

    $("#header .tab").mouseleave(function() {
        $(this).removeClass("hovered");
        $(this).find(".arrow").removeClass("arrow-hovered");
        $(this).find(".dropdown").hide();
        $('#dropdown-research').hide();
        $('#dropdown-help').hide();
    });

   // $("#header .tab .arrow").click(function() {
   //     $(this).siblings(".dropdown").slideToggle("fast");
   // });

    $("#header .tab .arrow").mouseenter(function() {
        $(this).removeClass("arrow-selected");
        //$(this).addClass("arrow-focused");
    });

    $("#header .tab .arrow").mouseleave(function() {
        $(this).removeClass("arrow-focused");
        if ($(this).parent().hasClass("selected"))
            $(this).addClass("arrow-selected");
    });

    $("#header .tab .dropdown div:not(.separator)").click(function() {
        window.location = $(this).find("a:first").attr("href");
    });

    $("#header .tab .dropdown div:not(.separator)").mouseenter(function() {
        $(this).addClass("hovered");
    });

    $("#header .tab .dropdown div:not(.separator)").mouseleave(function() {
        $(this).removeClass("hovered");
    });

    $("#drilldown-research").mouseenter(function() {
        $('#dropdown-research').slideToggle("fast");
    });

    $("#drilldown-research").mouseleave(function() {
        $('#dropdown-research').hide();
    });

    $("#drilldown-help").mouseenter(function() {
        $('#dropdown-help').slideToggle("fast");
    });

    $("#drilldown-help").mouseleave(function() {
        $('#dropdown-help').hide();
    });
});

function selectTab(tabName) {
    $("#header .tab a").each(function(i) {
        if ($(this).text() == tabName) {
            $(this).parent().addClass("selected");
            $(this).siblings(".arrow").addClass("arrow-selected");
        }
    });
}
