﻿String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

$(document).ready(function() {

    $("#masthead div.search input.text").val("Search");

    $("#masthead div.search input.text").click(function() {
        if ($(this).val() == "Search")
            $(this).val("");
    });

    $("#masthead div.search input.text").blur(function() {
        if ($(this).val() == "")
            $(this).val("Search");
    });

    // secondary navigation
    $("div#sub-nav ul ul").hide();
    var openIcon = "<img src='Images/ICN-sub-nav-parent-open.gif' alt='' width='9' height='9' />"
    var closedIcon = "<img src='Images/ICN-sub-nav-parent-closed.gif' alt='' width='9' height='9' />"

    $("div#sub-nav li:has(ul)").prepend(closedIcon);
    $("div#sub-nav > ul > li.current").find("ul").show();
    $("div#sub-nav > ul > li.current > img").attr("src", "Images/ICN-sub-nav-parent-open.gif");
    $("div#sub-nav img").click(function() {
        if ($(this).parent().find("ul").is(":hidden")) {
            $(this).parent().find("ul").slideDown();
            $(this).attr("src", "Images/ICN-sub-nav-parent-open.gif");
            $(this).parent("li").addClass("parent-open");
            $(this).parent().siblings().find("ul").not(":hidden").slideUp();
            $(this).parent().siblings("li").removeClass("parent-open");
            $(this).parent().siblings().find("img").attr("src", "Images/ICN-sub-nav-parent-closed.gif");
        } else {
            $(this).parent().find("ul").slideUp();
            $(this).attr("src", "Images/ICN-sub-nav-parent-closed.gif");
            $(this).parent("li").removeClass("parent-open");
        }
    });

    // expert profiles
    $("#body-content-center div.expert-profile").hide();
    //var currentProfile = "";
    var theAnchor = jQuery.url.param("profile");
    if (theAnchor != null) {
        $("ul.expert-profiles li#" + theAnchor).addClass("current");
        $("#body-content-center div.#" + theAnchor + "-profile").fadeIn("slow");
        //currentProfile = theAnchor + "-profile";
    } else {
        $("ul.expert-profiles li#ronald-christensen").addClass("current");
        $("#body-content-center div.#ronald-christensen-profile").fadeIn("slow");
        //currentProfile = "ronald-christensen-profile";
    }
    //alert(theAnchor);
    //$("ul.expert-profiles li#ronald-christensen").addClass("current");
    //$("#body-content-center div.#ronald-christensen-profile").fadeIn("slow");
    // leadership
    $("ul.expert-profiles li#c-maki").addClass("current");
    $("#body-content-center div.#c-maki-profile").fadeIn("slow");

    $("#body-content-center ul.expert-profiles li a").click(function(event) {
        var profileTrigger = $(this).parent("li").attr("id") + "-profile";
        //if(currentProfile != "")
        //$("#" + currentProfile).hide();
        $("#" + profileTrigger).fadeIn("slow").siblings("div.expert-profile").hide();
        //currentProfile = profileTrigger;
        $(this).parent("li").addClass("current").siblings().removeClass("current");
        event.preventDefault();
        return false;
    });

    // open new window for pdfs
    $("a[href$=.pdf]").click(function() {
        if ($(this).attr("target") != "_blank") {
            window.open($(this).attr("href"), 'newWin');
            return false;
        }
    });

});