//$('a.lightbox').hide();
// Initializes User Scripts:
$(document).ready(function() {
  //var cycleTimer = setInterval(function (){$('.scroll').trigger('next')}, 8000);
  //$('a.lightbox').show().lightBox();

  $('input.txtSearch').focus(function() {
    if ( $(this).val() == 'search' ) {
      $(this).val('');
    }
  });
  $('input.txtSearch').blur(function() {
    if ( $(this).val() == '' ) {
      $(this).val('search');
    }
  });

  // hide text in spans (text replacement). Adds sprite class for 'image'.
  $('.imgText').each(function() {
    $(this).find('>span').hide();
    $(this).addClass('spriteTheme');
  });

  // Links - pop up in new window / tab:
  $(".lnkBlank").click(function() {
    window.open($(this).attr("href"), 'window2', '');
    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();
    });
  }
  
  $("#leftNavMenu ul").addClass('collapsible');
  $("#leftNavMenu li:has(ul.collapsible):not(:first)").addClass('hasChild');
  $("#leftNavMenu a[href='" + location.pathname + "']").addClass('current');
  $("#leftNavMenu ul li:not(.hasChild) .arrow").css('background-image', 'none');
  $("#leftNavMenu").accordionMenu();
  
  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):not(.custom)");
    for (z = 0; z < sections.length; z++) {
      var li = topElements[z];
      var lihtml = li.innerHTML;
      li.innerHTML = lihtml + sections[z].innerHTML;
    }
    $("#topMenu li.custom li").addClass('noHover');
    $("#topMenu>li:has(ul) a").addClass('hasChild');
    $("#topMenu").navMenu({
      menuWidth: 200,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
    $("#subNavigation").remove();
  });
  
  $(".listItem .listItemImage").each(function() {
    if ( $(this).attr("src") == '' || $(this).attr("src") == '/' || $(this).attr("src") == '?w=150' ) {
      $(this).hide();
    }
  });
  if($("#CouponImageContent").length > 0){
    var newA = $("<a>");
    var oldA = $("#CouponImageContent").parent().parent();
    newA.attr("id", oldA.attr("id"));
    newA.attr("href", oldA.attr("href"));
    $("#CouponImageContent").parent().unwrap();
    $("#CouponImageContent img").wrap(newA);
    
  }
  var fdate = new Date();
  $('#footer span.date').text(fdate.getFullYear());
});
