// Initializes User Scripts:
$(document).ready(function() {
  if ( !$("#rightColumn").html() ) {
    $("#rightColumn").hide();
    $("#mainColumn").width(1000);
  }
  $('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: 250,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
  });
  
  $(".listItem .listItemImage").each(function() {
    var img = $(this).find('img').attr("src");
    if ( img == '' || img == '/' || img.substr(0, 1) == '?' ) {
      $(this).hide();
    }
  });
  if ( $("#listItemImage").length ) {
    if ( $("#listItemImage").attr('src') == '' || $("#listItemImage").attr('src') == '/' || $("#listItemImage").attr("src").substr(0, 1) == '?' ) {
      $("#listItemImage").hide();
    }
  }
  
  if ( location.pathname == '/' ) {
    $("h1#headerText").html($("h1#headerText").html().replace('AdFedCO.', '<span style="color: #999;">AdFedCO.</span>'));
  }
  
  $("img").each(function(){
    if($(this).attr("src") == "" || $(this).attr("src") == "/" || $(this).attr("src") == "?w=100&h=100") $(this).hide();
  });
});