$(document).ready(function(){

  // selected menu item
  if (window.location.href.indexOf("type=3") >= 0) {
    /* annual reports */
    $("#annual_reports").addClass("selected");
  } else if (window.location.href.indexOf("type=2") >= 0) {
    /* semi-annual */
    $("#semiannual_reports").addClass("selected");
  } else if (window.location.href.indexOf("type=1") >= 0) {
    /* MRFP */
    $("#mrfps").addClass("selected");
  } else if (window.location.href.indexOf("type=5") >= 0) {
    /* IMRFP */
    $("#interim_mrfps").addClass("selected");
  } else if (window.location.href.indexOf("type=6") >= 0) {
    /* quarterly */
    $("#quarterly_summaries").addClass("selected");
  } else if (window.location.href.indexOf("fundfacts.html") >= 0) {
    /* fund facts */
    $("#fundfacts").addClass("selected");
  } else if (window.location.href.indexOf("FXWMain.aspx") >= 0) {
    $("#home").addClass("selected");
  }
  
  // IE hover
  $("#menu li").mouseover(function(){
    if (!$(this).hasClass("selected")) {
      $(this).children("a").eq(0).css("color", "#3D3C2B");
      $(this).css("color", "#3D3C2B");
      $(this).css("background-color", "transparent");
      $(this).css("background-image", "url('../images/menu.gif')");
      $(this).css("background-repeat", "repeat-x");
      $(this).css("background", "transparent url('../images/menu.gif') repeat-x");
    }
  });
  
  $("#menu li").mouseout(function(){
    if (!$(this).hasClass("selected") && !$("#board_" + $(this).attr("id")).is(":visible")) {
      $(this).children("a").css("color", "#ffffff");
      $(this).css("color", "#ffffff");
      $(this).css("background-color", "transparent");
      $(this).css("background-image", "url('../images/menudiv.gif')");
      $(this).css("background-position", "top right");
      $(this).css("background-repeat", "no-repeat");
    }
  });

  var last_click = false;
  
  // hide the old menu column, stupid
  $("#table1 td").eq(0).hide();

  $("#menu li.board").click(function() {    
    $("#submenu").hide();
    $("#submenu div.board").hide();
    $("#submenu").css("left", $(this).offset().left + 25 + "px");
    
    if (last_click != $(this).attr("id")) {
      $("#board_" + $(this).attr("id")).show();
      $("#submenu").show();
      last_click = $(this).attr("id");
      
      $("#menu li").not(".selected").mouseout();
      $(this).mouseover();
      
      var outside_window = ($("#submenu").offset().left + $("#submenu").width()) - $(window).width();
      if (outside_window > 0) $("#submenu").css("left", $("#submenu").offset().left - outside_window - 10 + "px");
      
    } else {
      last_click = false;
      $(this).mouseout();
    }
  });
  
  $(window).resize(function(){
    $("#submenu").css("left", $("#menu #" + last_click).eq(0).offset().left + 25 + "px");
    var outside_window = ($("#submenu").offset().left + $("#submenu").width()) - $(window).width();
    if (outside_window > 0) $("#submenu").css("left", $("#submenu").offset().left - outside_window - 10 + "px");
  });
  
  /* phone number for AIC reports */
  $.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return 0; }
    return results[1] || 0;}
    
  if ($("#lblPrint").size() > 0) {      
    $("#lblPrint").html($("#lblPrint").html().replace("Manulife Mutual Funds", " "));
    $("#lblPrint").html($("#lblPrint").html().replace("de Fonds communs Manuvie", " "));

    if (parseInt($.urlParam("cat")) == 10) {
      // segregated funds
      // english
      $("#lblPrint").html($("#lblPrint").html().replace("1-888-588-7999", "1-888-242-7060"));
      // french
      $("#lblPrint").html($("#lblPrint").html().replace("1-877-426-9991", "1-888-242-7060"));      
    } else if (parseInt($.urlParam("cat")) == 9) {
      // closed-end funds
      // english
      $("#lblPrint").html($("#lblPrint").html().replace("1-888-588-7999", "1-888-333-3240 (Copernican Capital) or 1-866-626-3707 (Markland Street Funds)"));
      // french
      $("#lblPrint").html($("#lblPrint").html().replace("1-877-426-9991", "1-888-333-3240 (Copernican Capital) or 1-866-626-3707 (Markland Street Funds)"));  
    }
  }

});
