$(document).ready(function() {
  
  /* Determine if we are on the home page to add the background image */
  var currTitle = document.title;
  var checkHome = document.title.search(/CFE Homepage/i);
  if (checkHome >= 0) {
    $("#main").addClass("homepage_bg");
  } else {
    $("#main").removeClass("homepage_bg");
  }
  
  /*  Homepage Carousel */
  $('#slides').slides({
      effect: 'fade',
      preload: true,
      preloadImage: 'img/loading.gif',
      play: 5000,
      pause: 2500,
      hoverPause: true,
      generatePagination: false, 
      paginationClass: 'slidePagination',
      animationStart: function(current){
          if (window.console && console.log) {
              // example return of current slide number
              console.log('animationStart on slide: ', current);
          };
      },
      animationComplete: function(current){
          if (window.console && console.log) {
              // example return of current slide number
              console.log('animationComplete on slide: ', current);
          };
      }
  });

  /* Cross-Browser Alternate Column Colors */
  $('table.tblBody96AltColors td:nth-child(even)').addClass('altColorsEven');
  
  
  /* Thumbnail RTE support */
    $("img.thumbnail").wrap("<div style='display: inline-block; text-align:center;' />")
      .each(function(index) {
        var jImg = $(this);      
                         
        xyUrlFrag = "_" + jImg.attr("width") + "x" + jImg.attr("height");
        extension = this.src.substr(this.src.lastIndexOf("."));
        preExtension = this.src.substr(0, this.src.lastIndexOf("."));
        preXY = preExtension.substr(0, preExtension.length - xyUrlFrag.length);
        if (preExtension.substr(preXY.length) == xyUrlFrag) {
          fullSizeUrl = preXY + extension;
        } else {
          fullSizeUrl = jImg.attr("src");
        }  
     
        jImg.parent().css('float', jImg.css('float'));
        jImg.css('float', '');
        jImg.wrap('<a class="largeImageLink" href="' + fullSizeUrl + '" />');
        jImg.after('<img class="fullsize" src="' + fullSizeUrl + '"/>' + '<a class="largeImageLink" href="' + fullSizeUrl + '">CLICK FOR LARGER VIEW</a>')                         
      });
    $("img.fullsize").load(function(index) {
      var jImg = $(this);
      imgHeight = jImg.height();
      imgWidth = jImg.width();
      xImgBound = $(window).width() * .9;
      yImgBound = $(window).height() * .8;

      jImg.dialog(
        {
          modal: true,
          autoOpen: false,
          height: yImgBound,
          width: 'auto',
          resizable: false,
          maxHeight: $(window).height() * .9,
          maxWidth: $(window).width() * .8
        }
      );
    });
    $(".largeImageLink").click(function() {
      $('img.fullsize:hidden[src*="' + this.href+'"]').dialog( "open" ); 
      return false;
    });
  
}); /* END DOCUMENT READY */

