// Initializes User Scripts:
$(document).ready(function() {
  $('input.txtSearch').focus(function() {
    if ( $(this).val() == 'search' ) {
      $(this).val('');
    }
  });
  $('input.txtSearch').blur(function() {
    if ( $(this).val() == '' ) {
      $(this).val('search');
    }
  });

  // Footer Links - pop up in new window / tab:
  $("a.lnkBlank").click(function() {
    window.open($(this).attr("href"), 'window2', '');
    return false;
  });

  pixelsilk2.renderSkin({skin: '[' + '[Menu1]' + ']', path: ''}, function(html) {
    $("#siteMenu").after('<div id="subNavigation"></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;
    }
    // figure out percentage of sections to width to force them to fill up the space...
    var x = Math.floor(1000 / sections.length) - 57; // padding (28) * 2 (left + right) + 1
    $("#topMenu > li:not(.separator) a").css('width', x + 'px');
    $("#topMenu > li:first > a").css('width', (x + 1) + 'px');
    $("#topMenu").navMenu({
      menuWidth: x,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
  });
});
