﻿function recordOutboundLink(link, category, action) {
    try {
        var pageTracker = _gat._getTracker("UA-20332668-2");
        pageTracker._trackEvent(category, action);
    } catch (err) { }
}

$(document).ready(function () {

    $('a.jsTrackClick').click(function () {
        var url = $(this).attr('href');

        recordOutboundLink($(this), "Outbound Links", url);
    });

    $(".jsInitNav").each(function () {
        var homeElem = null;
        var selectedCount = 0;
        $(this).find("li").each(function () {
            var liElem = $(this);
            var thisUrl = liElem.children("a").attr("href");

            // special case for home page, since it is contained in all nav.
            if (thisUrl == '/home') {
                homeElem = liElem;
                return;
            }

            if (typeof (thisUrl) != 'undefined') {
                thisUrl = thisUrl.toLowerCase();

                if (thisUrl.indexOf('/home') == 0 && thisUrl.length > 5)
                    thisUrl = thisUrl.substr(5);

                var secondSlashPos = thisUrl.indexOf('/', 1);
                if (secondSlashPos != -1)
                    thisUrl = thisUrl.substr(0, secondSlashPos + 1);

                if (window.location.toString().indexOf(thisUrl) != -1) {
                    liElem.addClass("sel");
                    selectedCount++;
                }
            }
        });

        if (selectedCount == 0) {
            homeElem.addClass("sel");
        }
    });

    $(".mediaReleases table tr").hover(
        function () {
            $(this).addClass(" jsHover");
        },
        function () {
            $(this).removeClass(" jsHover");
        });

    var blurFn = function () {
        var title = $(this).attr('title');
        if ($(this).val() == '' || $(this).val() == title) {
            $(this).addClass('hint').val(title);
        }
    };
    $("#searchBoxText").blur(blurFn).focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('').removeClass('hint');
        }
    }).each(blurFn);

});
