$(function () {

    // fix main nav
    $('#mainNav > li li:first-child').addClass('first-child');
    $('#mainNav > li li:last-child').addClass('last-child');
    $('#mainNav > li:last-child').addClass('last-child');

    // Summer Clerks link
    var summerClerks = $('li:last-child li:last-child a', '#mainNav');
    if (summerClerks.attr('href') == '/Careers/Summer-Clerks-Program.html')
        summerClerks.attr('target', '_blank');

    // Service Homepage
    $('.services', '#ourServicesLanding').hide();
    $('h2', '#ourServicesLanding').hover(
        function () {
            if ($(this).next('div').is(":hidden"))
                $(this).addClass('on');
        },
        function () {
            if ($(this).next('div').is(":hidden"))
                $(this).removeClass('on');
        }
    );
    $('h2', '#ourServicesLanding').click(function () {
        if ($(this).next('div').is(":hidden")) {
            $(this).addClass('on');
            $(this).next('div').slideDown();
        } else {
            $(this).removeClass('on');
            $(this).next('div').slideUp();
        }
    });

    // add hover class - IE6
    $('.landingPage #subsections li').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });

    // generic landing page - subsection rollovers
    var hoverColour = "#fff";

    $("a.hoverBtn").show("fast", function () {
        $(this).wrap("<div class=\"hoverBtn\">");
        $(this).attr("class", "");
    });

    //display the hover div
    $("div.hoverBtn").show("fast", function () {
        //append the background div
        $(this).append("<div></div>");

        //get link's size
        var wid = $(this).children("a").width();
        var hei = $(this).children("a").height();

        //set div's size
        $(this).width(wid);
        $(this).height(hei);
        $(this).children("div").width(wid);
        $(this).children("div").height(hei);

        //on link hover
        $(this).children("a").hover(function () {
            //store initial link colour
            if ($(this).attr("rel") == "") {
                $(this).attr("rel", $(this).css("color"));
            }
            //fade in the background
            $(this).parent().children("div")
				.stop()
				.css({ "display": "none", "opacity": "1" })
				.fadeIn("fast");
            //fade the colour
            $(this).stop()
				.css({ "color": $(this).attr("rel") })
				.animate({ "color": hoverColour }, 350);
        }, function () {
            //fade out the background
            $(this).parent().children("div")
				.stop()
				.fadeOut("fast");
            //fade the colour
            $(this).stop()
				.animate({ "color": $(this).attr("rel") }, 250);
        });

        // Fix an issue when user goes back one page on browser
        $(this).children("a").click(function () {
            //fade out the background
            $(this).parent().children("div")
				.stop()
				.fadeOut("fast");
            //fade the colour
            $(this).stop()
				.animate({ "color": $(this).attr("rel") }, 250);
        });
    });

    // related info right col - staff rollovers

    $(".staff li a").hover(function () {
        $(this).children("span").fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
    },
	function () {
	    $(this).children("span").fadeTo("fast", 0.8); // This should set the opacity back to 60% on mouseout
	});

    // experts listing - staff tooltips

    $('.staffName').tooltip({
        bodyHandler: function () {
            return $(this).next().html();
        },
        showURL: false,
        track: true,
        extraClass: 'staffDetails',
        top: 10,
        left: 15,
        opacity: 1,
        //fixPNG: true, 
        fade: 0
    });


    // home page banner text positioning

    doResize();
    $(window).resize(function () {
        doResize();
    });
});

function doResize() {
    var windowWidth = $(window).width();
    if (windowWidth < 1200) {
        $('#homePage').addClass('lowRes');
    }
    else {
        $('#homePage').removeClass('lowRes');
    }
}

