$(document).ready(function() {

    // Collapseable divs
    $('div.collapse h3 a').click(function() {
        $(this).parent().siblings('div').slideToggle("medium");
        $(this).toggleClass("selected");
    });

    // Bind external links in new windows
    $('a[rel=external]').click(function() {
        open(this.href);
        return false;
    });

    // For Company Overview page with internal anchor links to behave as regular nav
    $('ul#navLevelThree li a').click(function() {
        $('ul#navLevelThree li').removeClass('levelThreeSelected');
        $(this).parent().addClass('levelThreeSelected');

        if ($(this).parent().attr('id') == "our-history") {
            $('ul.historyLevel4').show();
        }
        else {
            $('ul.historyLevel4').hide();
        }
    });

    var strHash = document.location.hash;
    if (strHash == "#history") {
        $('#our-history').addClass('levelThreeSelected');
        $('ul.historyLevel4').show();
    }
    if (strHash == "#who") {
        $('#who-we-are').addClass('levelThreeSelected');
    }
    if (strHash == "#what") {
        $('#what-we-do').addClass('levelThreeSelected');
    }

    //Smart cross-page links from FAQ to Other Flywheel Apps for auto expansion	
    var strSel = "div";
    if (strHash.match("#app_")) {
        strSel = strSel.concat(strHash);
        $(strSel + ' div').slideToggle("medium");
        $(strSel + ' h3 a').toggleClass("selected");
    }

    //Homepage Video Spotlight
    $("#spotlightHead img").hide();
    $("#spotlightOptions2").hide();
    $("#spotlightHead1").show();
    $(".spotlightBody").hide();
    $("#spotlightBody1").show();
    $(".spotlightOptions ul li#option1 a").addClass("optionSelect");
    $("#footer2").hide();

    $("ul li.spotlightOption a").mouseover(function() {
        if ($(this).hasClass("optionSelect")) {

        } else {
            $("ul li.spotlightOption a").removeClass("optionSelect");
            $(this).addClass("optionSelect");
            $(".spotlightBody").hide();
            var selectedID = $(this).parent().attr("id").replace("option", "");
            $("#spotlightBody" + selectedID).show();
            $("img.spotlightImg").hide();
            var selectedIMG = $(this).parent().attr("id").replace("option", "");
            $("#spotlightHead" + selectedID).show();
        }
    });

    $("a.next").click(function() {
        $("#spotlightHead4").show();
        $("#spotlightOptions1").hide();
        $("#spotlightOptions2").show();
        $("#footer1").hide();
        $("#footer2").show();
        $(".spotlightOptions ul li#option4 a").addClass("optionSelect");
    });

    $("a.prev").click(function() {
        $("#spotlightHead1").show();
        $("#spotlightOptions1").show();
        $("#spotlightOptions2").hide();
        $("#footer1").show();
        $("#footer2").hide();
        $(".spotlightOptions ul li#option1 a").addClass("optionSelect");
    });
});