
// Initializes User Scripts:
$(document).ready(function() {
    resizeColumns();
    setInterval(resizeColumns, 1000);
    waitForLoad();
    groupHeaders();
    $('.slidesTxt').show();
  
  // Selects text in Search Box when focused:
  $('input.txtSearch').focus(function() {
    this.select();
  });
  $('input.txtSearch').blur(function() {
    if ( $(this).val() == '' ) $(this).val('search');
  });

  // Links - pop up in new window / tab:
  $("a.lnkBlank").click(function() {
    window.open($(this).attr("href"), 'window2', '');
    return false;
  });

  $("img").each(function() {
    var img = $(this).attr("src");
    if ( typeof(img) == 'undefined' || img == '' || img == '/' || img.substr(0, 1) == '?' || img.substr(0, 2) == '/?' ) $(this).hide();
  });
  
   $(".avMediaLink").each(function() {
     var disable = $(this).attr("href");
     if ( typeof(disable) == 'undefined' || disable == '' || disable == '/' || disable.substr(0, 1) == '?' || disable.substr(0, 2) == '/?' ) $(this).hide();
   });
  
   $(".avPdfLink").each(function() {
     var disable = $(this).attr("href");
     if ( typeof(disable) == 'undefined' || disable == '' || disable == '/' || disable .substr(0, 1) == '?' || disable .substr(0, 2) == '/?' ) $(this).hide();
   });
   
   $('#lowerLinks li:last').css({'margin-right':'0'})
   
  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: 200,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
    $("#subNavigation").remove();
  });
});


function groupHeaders(){
  var categoryGroup = "somethingrandom";
  $("#calendarItems #CalendarDay .groupHeading, .mediaDate.groupHeadings").each(function(){
    if ($(this).text() != categoryGroup)
      categoryGroup = $(this).text();
    else
      $(this).hide(0);
  });
}

function resizeColumns(){
var highestCol = Math.max($('#mainColumn').height(),$('#rightColumn').height()); $('.mainCols').height(highestCol);
}

function waitForLoad(){
 $('.waitForLoad').show()
}
