
// Initializes User Scripts:
$(document).ready(function() {
  
  $('#themeCorners').html('<div class="corner tl spriteTheme"></div><div class="corner tr spriteTheme"></div><div class="corner bl spriteTheme"></div><div class="corner br spriteTheme"></div>');
  
  //Group Headers for dates and Calendar events
  groupHeaders();
  
  //Resize Column
    if ($('#content').size() >0) {
    adjustColumns('#content','div.column',true,true);
  }
      // Adjust the columns (container class or ID, column class, margin-[true|false], padding-[true|false])
    function adjustColumns(container,cssclass,margin,padding) {
        $(cssclass).each(function() {
            var tHeight = 0;
            if (margin) {
                tHeight += Number(Number($(this).css('margin-top').replace('px','')) + Number($(this).css('margin-bottom').replace('px','')));
            }
            if (padding) {
                tHeight += Number(Number($(this).css('padding-top').replace('px','')) + Number($(this).css('padding-bottom').replace('px','')));
            }
            $(this).css('min-height',Number($(container).height()-tHeight));
        });
    }
    
  $("#initDoor").click(function () {  
  $('#garageDoor').slideUp(1000, function() {  
        // Initiates Home Page Slides
      $('#homeSlideShowTxtContainer').show();
      $('.homeSlideShow').each(function(index) {
        $(this).cycle({
        fx: index ? 'uncover' : 'fade',
        direction:     'up',
        speed:  1000,
        timeout: 10000,
        cleartypeNoBg: true,
        sync:    true,
        pager:'#nav-1',
        pagerAnchorBuilder: function(i) {
          if (index == 0)
            // for first slideshow, return a new anchor
            return '<a href="#">'+(i+1)+'</a>';
          // for 2nd slideshow, select the anchor created previously
          return '#nav-1 a:eq('+i+')';
        }
      });
    });  
   });
  });
 setTimeout("$('#initDoor').trigger('click')", 3000);
 setTimeout("$('#homeSlideShowTxtContainerFirst').remove()", 5000);

  // Initiates Home Page Slides
  //$('.slidesTxt').show();
  //$('#homeSlideShow').cycle({
 // fx:     'uncover',
 // direction:     'up',
  //speed:  1000,
 // timeout: 8000,
 // pager:'#nav-1'
 // });
 
// Apply Background Color To Table Rows
//   $(".units tr:odd").css("background-color", "#FFFFFF");
//   $(".units tr.heading").css("background-color", "#124c7a");
 
      // Selects text in Search Box when focused:
    $('input[type=text].clearText').each(function() {
        var txtSearchText = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == txtSearchText) {
                $(this).val('');
            }
        });
        $(this).blur(function() {
            if ($(this).val() == '') {
                $(this).val(txtSearchText);
            }
        });
        
        if ($(this).hasClass('validate')) {
            $(this).parent().parent().submit(function() {
                //alert($(this).find('input[type=text]').val()+'|'+txtSearchText);
                if ($(this).find('input[type=text]').val() == txtSearchText) {
                    alert('Please enter a valid search term')
                    return false;
                }
            });
        }
    
    });

  // 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()); $('.mainCols').height(highestCol);
}
