/* The below code is used to do the mega-nav navigation */
var strSelectedSubNav = "";
var strPathname = location.pathname;   // eg. /Zyz/Abc.aspx
var strFilename = strPathname.substr(strPathname.lastIndexOf("/") + 1);   // eg. Abc.aspx
var strPathnameLower = strPathname.toLowerCase();   // eg. /zyz/zbc.aspx
var strFilenameLower = strFilename.toLowerCase();   // eg. abc.aspx
var strSearchBoxText = "Keyword";


/* Search Box */
$(document).ready(function () {

    $("#search-input").focus(function() {
        if ($(this).attr("value") == strSearchBoxText)
        {
            $(this).attr("value", "");
        }
    });

    $("#search-input").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).attr("value", strSearchBoxText);
        }
    });
});  /* END Search Box */



/* Primary Nav and Mega Nav */
$(document).ready(function () {

    $(".primary-nav-item, .mini-nav-item").mouseenter(function () {
        $(this).addClass("over");
        $(this).find(".mega-nav, .mini-nav").stop().fadeTo(200, 1, function () {
            //alert('ignore me doing this');
            $(this).css('filter', '');  // fix clear type font bug in IE

        });
    }).mouseleave(function () {
        $(this).find(".mega-nav, .mini-nav").stop().hide();
        $(this).removeClass("over");

    });


    // home link
    if (strPathnameLower == "/default.aspx" || strPathnameLower == "/") {
        $("#home-nav-item").children('a').addClass('selected');
    }


    // other nav links
    $(".primary-nav-item, .mini-nav-item, .related-nav-item").children('a').each(function (i) {
        var pHref = $(this).attr('href');
        if (strPathnameLower.indexOf(pHref.toLowerCase()) > -1) {
            $(this).addClass('selected');
        }
    });

}); /* END Primary Nav and Mega Nav */



/* The code below is used to do the rollovers in the Landing page table rows */

    $(document).ready(function () {
        $(".landing tr").click(function (event) {
            if (event.target.nodeName != "A") {
                var url = $("a", $(this)).attr("href");
                if (url != undefined) {
                    window.location.href = url;
                }
            }
            // document.location = url;
        });

        $('.landing tr').mouseover(function () {
            $(this).addClass('op');
        }).mouseout(function () {
            $(this).removeClass('op');
        });

        $(".landing-wide tr").click(function (event) {
            if (event.target.nodeName != "A") {
                var url = $("a", $(this)).attr("href");
                if (url != undefined) {
                    window.location.href = url;
                }
            }
            // document.location = url;
        });

        $('.landing-wide tr').mouseover(function () {
            $(this).addClass('op');
        }).mouseout(function () {
            $(this).removeClass('op');
        });

        // show correct Header and Footer
        if ($('body[id^="producer-offset"]').length != 0) {
            $('#header-logo-po').css('visibility', 'visible');
            $('#footer-logo-po').css('visibility', 'visible');
        }
        else {
            $('#header-logo').css('visibility', 'visible');
            $('#footer-logo').css('visibility', 'visible');
        }


        /*  Column rollovers - "col-" class must be the First class in the TD: "col-x otherclass"  */
        $('[class^="col-"]').each(function (index) {
            var strCol = '.' + $(this).attr('class');
            if (strCol.indexOf(' ') > -1) {
                strCol = strCol.substr(0, strCol.indexOf(' '));
            }
            $(strCol).click(function (event) {
                if (event.target.nodeName != "A") {
                    var urlcol = $(strCol + " a").first().attr("href");
                    if (urlcol != undefined) {
                        window.location.href = urlcol;
                    }
                }
            });

            $(strCol).mouseover(function () {
                $(strCol).addClass('op');
            }).mouseout(function () {
                $(strCol).removeClass('op');
            });
        }); // end for each '[class^="col-"]'


    });  /* END landing and Col table rollovers */



/* In Page Navigation (ie. ul lists in left hand nav) */

    $(document).ready(function () {
        // get current page, set selected link
        var path = strPathnameLower;

        if (strSelectedSubNav.length > 0) {
            path = strSelectedSubNav;
        }

        if (path) {
            path = path.toLowerCase();
            path = path.substring(0, 1) == "/" ? path.substring(1) : path;
            $('#in-page-nav a').each(function (i, n) {
                var href = $(n).attr("href");
                href = href.toLowerCase();
                href = href.substring(0, 1) == "/" ? href.substring(1) : href;
                //alert(href + "\n" + path);
                if (path == href || (path + "default.aspx" == href) || (path == href + "default.aspx")) {
                    $(n).addClass('subnav-selected');
                }

            });

        }

        // hide all sub sub nav
        $('#in-page-nav ul li').find('ul').hide();
        // find lis with sub sub nav
        $('#in-page-nav li').has('ul').children('a:first-child').addClass('subnav-closed');
        /// <reference path="../images/Bullet_Arrow_Grey.png" />

        // show relevant sub sub nav for selected page
        $('#in-page-nav a.subnav-selected').parentsUntil('#in-page-nav').show();
        $('#in-page-nav a.subnav-selected').parents('#in-page-nav li').children('a:first-child').addClass('subnav-open').removeClass('subnav-closed').remove('.imgarrow');
        $('#in-page-nav a.subnav-selected').nextUntil('ul li').show();
        if ($('.subnav-selected.subnav-open').parent('li').children('ul').size() == 0) {
            $('.subnav-selected.subnav-open').removeClass('subnav-open');
        }
        $('#in-page-nav .subnav-closed').closest('a').append('&nbsp;<img src="/images/Bullet_Arrow_Grey.png" border="0" alt="arrow" class="imgarrow">');
        $('#in-page-nav .subnav-open').closest('a').append('&nbsp;<img src="/images/Bullet_Arrow_Black_Down.png" border="0" alt="arrow" class="imgarrowD">');


        // mouseover subnav
        $('#in-page-nav li').mouseenter(function (e) {
            $(this).css("cursor", "pointer");
            $('a', this).first().addClass('subnav-over');

        }).mouseleave(function (e) {
            $('a', this).first().removeClass('subnav-over');
        });

        $('#in-page-nav li').click(function (e) {
            e.stopPropagation();
            var strHref = $('a', this).first().attr('href');
            if (strHref != undefined && strHref != '#') {
                window.location.href = strHref;
            }
        });

    });   // end in page nav code

