
// Initializes User Scripts:
$(document).ready(function() {
resizeColumns();
setInterval(resizeColumns, 1000);
groupHeaders();
$('.slidesTxt').show();
$('#emailVerificationForm').submit(function(){
  $('#ajax-loading').show();
  $('#submit').hide(); 
});
  
if ($('#purchaseReportWrapper').size() >= 1)
  {
     $('.interiorCTAWrap').css('height' , '150px');
    $('.interiorCTAWrap').css('background-position' , '0 136px');
    $('.interiorCTA').css('height' , '105px');
  }
  
  // Get all the text nodes from the body
$(document.body).textNodes().each(function() {
    // Test each text node to see if it has any numbers in it
    if(/mortech/ig.test(this.nodeValue))
        // Remove numbers or sequences of numbers and replace with links
        $(this).replaceWith(
            this.nodeValue.replace(/mortech/ig, function(nums) {
                return "MORTECH"
            })
        );
});
  
  // 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();
    });

  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").each(function(){
    if ($(this).text() != categoryGroup)
      categoryGroup = $(this).text();
    else
      $(this).hide(0);
  });
}

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

// This is a simple jQuery extension to find text nodes
$.fn.textNodes = function() {
    var ret = [];
    $.each(this.contents(), function() {
        try {
        if(this.nodeType == 3) 
            ret.push(this);
        else 
            $(this).contents().each(arguments.callee);
        } catch(e) {}
    });
    return $(ret);
}

                  


