// Initializes User Scripts:
$(document).ready(function() {
  $("#content").append('<div id="themeFooter"><img src="/footer-corners.gif" width="1001" height="10" alt="" /></div>');
    $("#topMenu>li:first>a").prepend('<span style="float:left; margin-top:13px; width:17px; height:13px; display:block;" />&nbsp;');
  
  $('input.txtSearch').focus(function() {
    if ( $(this).val() == 'search' ) {
      $(this).val('');
    }
  });
  $('input.txtSearch').blur(function() {
    if ( $(this).val() == '' ) {
      $(this).val('search');
    }
  });

  // Links - pop up in new window / tab:
  $(".lnkBlank").click(function() {
    window.open($(this).attr("href"), 'window2', '');
    return false;
  });
  
  $("a.button").click(function() {
    if ( $(this).hasClass("smaller") ) {
      resizeText('smaller');
    } else if ( $(this).hasClass("larger") ) {
      resizeText('larger');
    } else { // "normal"
      resizeText('normal');
    }
    return false;
  });
  
  if ( document.URL.indexOf('EditListItem.aspx') == -1 ) {
    $("img").each(function() {
      var img = $(this).attr("src");
      if ( typeof(img) == 'undefined' || img == '' || img == '/' || img.substr(0, 1) == '?' || img.substr(0, 2) == '/?' ) $(this).hide();
    });
    $("img").error(function() {
      $(this).hide();
    });
  }
  
  pixelsilk2.renderSkin({skin: '[' + '[Menu1]' + ']', path: ''}, function(html) {
    $("#siteMenu").after('<div id="subNavigation" style="display: none;"></div>');
    $("#subNavigation").html(html);
    var sections = $("#subNavigation div");
    var topElements = $("#topMenu li:not(.separator)");
    for (z = 0; z < sections.length; z++) {
      var li = topElements[z];
      var lihtml = li.innerHTML;
      li.innerHTML = lihtml + sections[z].innerHTML;
    }
    $("#topMenu").navMenu({
      menuWidth: 250,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
    $("#subNavigation").remove();
    $("a[href$='/senior-health/health-care-partnerships/']").attr('target', '_blank');
  });
});

function resizeText( size ) {
  switch (size) {
    case "larger":
      $("body").css({"font-size": "16px", "line-height": "1.5em"});
      $("h1").css({"font-size": "30px"});
      $("h2").css({"font-size": "24px"});
      $("h3").css({"font-size": "20px"});
      $("h4").css({"font-size": "18px"});
      $("h5").css({"font-size": "16px"});
      $("#footer .copyright").css({"font-size": "12px"});
      break;
    case "normal":
      $("body").css({"font-size": "14px", "line-height": "1.5em"});
      $("h1").css({"font-size": "28px"});
      $("h2").css({"font-size": "20px"});
      $("h3").css({"font-size": "18px"});
      $("h4").css({"font-size": "16px"});
      $("h5").css({"font-size": "14px"});
      break;
    default: // "smaller" which is really the baseline
      $("body").css({"font-size": "13px", "line-height": "1.5em"});
      $("h1").css({"font-size": "24px"});
      $("h2").css({"font-size": "18px"});
      $("h3").css({"font-size": "16px"});
      $("h4").css({"font-size": "14px"});
      $("h5").css({"font-size": "13px"});
      $("#footer .copyright").css({"font-size": "10px"});
  }
}
