///<reference path="jquery-1.2.6-vsdoc.js"/>


//Starts when DOM is ready
$(function () {
    $("div.col-right-country").each(function () {
        $("a").each(
		function (i, obj) {
		    var regexp = /^[A-Za-z]*\s+([x-]|[-x]|[\u2013\u2014])/;
		    if ($(obj).text().match(regexp)) {
		        //alert($(obj).text());
		        $(obj).text($(obj).text().replace(regexp, " - "));
		    }
		});
    });


    $("a.ms-navitem2").each(function (i, obj) {
        var menuHeader3 = $(this).parents("tr:eq(0)").parents("table").parents("tr:eq(0)").next("tr").find("table.ms-navSubMenu3:eq(0)");

        if ($(obj).text().indexOf("-") == -1) {
            $(obj).text("- " + $(obj).text());
        }

        if (menuHeader3.length > 0) {
            $(obj).addClass("plusBG");
        }
    });

    $("a.ms-navheader5").each(function (i, obj) {
        //alert($(obj).parents("tr:eq(0)").parents("tr:eq(0)").attr("title").indexOf("Bio"));

        var msNavHeaderTable = $(obj).parents("tr:eq(0)").parents("tr:eq(0)").find("table.ms-navheader5");
        if ($(obj).parents("tr:eq(0)").parents("tr:eq(0)").attr("title").indexOf("Bio") != -1) {
            $(obj).addClass("table.ms-navheader5");
        }
        else {
            $(msNavHeaderTable).removeClass("td.ms-navheader5");
            $(msNavHeaderTable).removeClass("table.ms-navheader5");
            $(msNavHeaderTable).removeClass("ms-navheader5");
        }
    });



    //For each Quick Launch navigation sub menu: 
    $("table.ms-navSubMenu2").each(function () {
        //Find any navigation items under the sub menu that have been selected.
        var selectedNavItems = $(this).find("a.ms-selectednav");

        //Find the corresponding navigation header of the current sub menu being processed
        var menuHeader = $(this).parents("tr:eq(0)").prev("tr").find("table.ms-navheader:eq(0)");

        var regexp = /([Ii][Nn][Vv][Ee][Ss][Tt][Oo][Rr][Ss][Mm][Ee][Dd][Ii][Aa])|([Cc][Aa][Rr][Ee]+[Rr][Ss])|([Cc][Oo][Mm][Pp][Aa][Nn][Yy])|([Nn][Aa]\/Products\/Pages)|([Nn][Aa]\/Pages)/;

        if ($(menuHeader).hasClass("ms-selectednavheader") || selectedNavItems.length > 0) {
            //selected navigational items in this submenu, show the submenu.

            $(this).show();
        }
        else {
            if (regexp.test(window.location.href))
            { $(this).hide(); }
        }
    });

    //For each Quick Launch navigation sub menu: 
    $("table.ms-navSubMenu3").each(function () {
        //Find any navigation items under the sub menu that have been selected.
        var selectedNavItems = $(this).find("a.ms-selectedItem");

        //Find the corresponding navigation header of the current sub menu being processed
        var menuHeader = $(this).parents("tr:eq(0)").prev("tr").find("table.ms-navitem:eq(0)");
        var menuHeader2 = $(this).parents("tr:eq(0)").prev("tr").find("table.ms-navitem2:eq(0)");

        if ($(menuHeader).hasClass("ms-selectednav") || $(menuHeader2).hasClass("ms-selectednav2") || selectedNavItems.length > 0) {
            //alert('found: ' + $(menuHeader).hasClass("ms-selectednav") + " length: " + selectedNavItems.length);
            //if the navigation header for this sub menu is selected or if there are any 
            //selected navigational items in this submenu, show the submenu.

            $(this).show();
            //$("table.ms-navSubMenu3").hide("slow");
        }
        else {
            //otherwise, hide the submenu, except when the header is "Trauma"				
            //if ($("a.ms-selectednavheader").text() != "Trauma") 
            $(this).hide();
        }
    });

    //For each Quick Launch navigation sub menu: 
    $("table.ms-navSubMenu4").each(function () {

        //Find any navigation items under the sub menu that have been selected.
        var selectedNavItems = $(this).find("a.ms-selectednav2");

        //Find the corresponding navigation header of the current sub menu being processed
        var menuHeader4 = $(this).parents("tr:eq(0)").prev("tr").find("table.ms-navheader2:eq(0)");

        if ($(menuHeader4).hasClass("ms-selectednavheader") || selectedNavItems.length > 0) {
            //alert("has class: " + $(menuHeader4).hasClass("ms-selectednavheader"));
            //selected navigational items in this submenu, show the submenu.

            $(this).show();
        }
        else {
            //otherwise, hide the submenu, except when the header is "Trauma"				
            //if ($("a.ms-selectednavheader").text() != "Trauma") 
            //$(this).hide();	
        }

    });

    $("a.ms-navheader2").each(function (i, obj) {
        var menuHeader3 = $(this).parents("tr:eq(0)").parents("table").parents("tr:eq(0)").next("tr").find("table.ms-navSubMenu4:eq(0)");

        if ($(obj).text().indexOf("Information") != -1) {
            $(menuHeader3).show();
        }
        else {
            $(menuHeader3).hide();
        }
        $(obj).text("- " + $(obj).text());
    });

    $("table.ms-navheader5").each(function () {

        //Find any navigation items under the sub menu that have been selected.
        var selectedNavItems = $(this).find("a.ms-selectednav5");

        //Find the corresponding navigation header of the current sub menu being processed
        var menuHeader5 = $(this).parents("tr:eq(0)").parents("tr:eq(0)").find("table.ms-navSubMenu3:eq(0)");

        //alert("has class: " + $(menuHeader5).hasClass("ms-navSubMenu3"));
        if ($(menuHeader5).hasClass("ms-navSubMenu3") || selectedNavItems.length > 0) {
            //alert("has class: " + $(menuHeader3).hasClass("ms-navSubMenu5"));				
            $(this).show;
        }
        else {
            //$(this).hide();	
        }

    });


    $("table.ms-navitem5").each(function () {
        $("table.ms-navSubMenu3").each(function () { $(this).show(); });

        //Find any navigation items under the sub menu that have been selected.
        var selectedNavItems = $(this).find("a.ms-selectednav5");

        //Find the corresponding navigation header of the current sub menu being processed
        var menuHeader5 = $(this).parents("tr:eq(0)").parents("tr:eq(0)").find("table.ms-navSubMenu5:eq(0)");
        //alert("has class: " + $(menuHeader5).hasClass("ms-navSubMenu5"));
        if ($(menuHeader5).hasClass("table.ms-navSubMenu5") || selectedNavItems.length > 0) {
            //alert("has class: " + $(menuHeader5).hasClass("ms-navSubMenu5"));
            //selected navigational items in this submenu, show the submenu.

            $(this).show();
        }
        else {
            //otherwise, hide the submenu, except when the header is "Trauma"				
            //if ($("a.ms-selectednavheader").text() != "Trauma") 
            //$(this).hide();	
        }

    });



    //When a user clicks a navigation header, the user should be taken directly
    //to the site link. The javascript event handler to hide/display the submenus
    //should not be triggered.
    $("a.ms-navheader").click(function (e) {
        //alert("clicked header");
        e.stopPropagation();
    });



    //When the user hovers over the navigation header, it would be nice
    //to have an indicator that they can click on the header. Usually,
    //browsers use the hand icon to indicate clickable items.
    $("table.ms-navheader").hover(function (e) {
        $(this).css("cursor", "hand");
    }, function (e) {
        $(this).css("cursor", "default");
    });

    /*
    
    //Finally, this adds a click event handler for the navigation header table
   
    $("a.ms-navheader").click(function(e){
    var subMenu = $(this).parents("tr:eq(0)").next("tr").find("table.ms-navSubMenu2:eq(0)");
    alert("submenu a.ms-navheader: " + subMenu.length);
    if (subMenu.length > 0)
    {
    //only if we have a submenu should we hide the other submenus and show the current one.
    $("table.ms-navSubMenu2").hide("slow");
    subMenu.show("slow");
    }
    // e.stopPropagation();
    }); 
   
    $("a.ms-navitem").click(function(e){
    $(this).addClass("ms-itemSelected");
    alert($(this).hasClass("ms-itemSelected"));
     	
    }); 


     
   

     
      
    $("table.ms-navSubMenu2").click(function(e)
    {		    
    alert("table.ms-navSubMenu2.clicked");
    //var subMenu = $(this).parents("tr:eq(0)").next("tr").find("table.ms-navitem:eq(0)");
    //alert("has class: " + subMenu.hasClass("table.ms-navitem"));
    alert("has class: " + $(this).hasClass("table.ms-navitem"));
    if ($(this).hasClass("table.ms-navitem"))
    {
    alert('subMenu # of items  : ' + subMenu.length);
    //only if we have a submenu should we hide the other submenus and show the current one.
    //$("table.ms-navSubMenu3").hide("slow");
    subMenu.show("slow");
    }
    		
    });
    
 
 
    $("table.ms-navheader").click(function(e)
    
    {           
    
    var subMenu = $(this).parents("tr:eq(0)").next("tr").find("table.ms-navSubMenu2:eq(0)");
    
    if (subMenu.length > 0)
    
    {
    
    //only if we have a submenu should we hide the other submenus and show the current one.
    
    $("table.ms-navSubMenu2").hide("slow");
    
    subMenu.show("slow");
    
    }
    
     
    
    }); 
    */

});

