var i=0;
var imagePos = 0;
var inteval;
var bannerArrowsShowing = false;
$(document).ready(function() {
  $(".calendar tr").each(function() {          
    if (i%2 == 0){
      $(this).addClass("row2");
      i++;
    } else {
      $(this).addClass("row1");
      i++;
    }
  });   
  
  // added by CST on 10/24/2010
  var url = document.location.href;
  if (url.indexOf('ticket-center') != -1) {
    $('#h2Container').html('<div style="float: right; padding-top: 14px; padding-right: 20px;"><a href="http://www.ticketingcentral.com/Portal/login.aspx?cust=tamu" title="Manage your tickets" alt="Manage your tickets" class="ticketrac">TickeTrac</a></div>');
  }
  
  //Setup the banner slideshow
  var images = $(".bannerImages").find("img");
  
  var height = 0;
  for(i = 0; i <images.length; i++){
    height = Math.max(height, images[i].height);
    images[i].id = "BannerImage" + i;
  }
 
  $(".bannerImages").css("height", (height) + "px");
  
  if(images.length > 1) {
    images[0].style.display = "block";
    interval = setTimeout("rotateBannerImage()", 6000);
  
  
    //The next and previous buttons for the banner slideshow transitions
    $(".bannerImages").mouseenter(function() {
      if(!bannerArrowsShowing) {
        $("#previousBanner").show("slide", { direction: "left" }, 500);
        $("#nextBanner").show("slide", { direction: "right" }, 500, function () {bannerArrowsShowing = true;});
      }
    });
    $(".bannerImages").mouseleave(function () {
      $("#previousBanner").hide("slide", { direction: "left" }, 500);
      $("#nextBanner").hide("slide", { direction: "right" }, 500, function() {bannerArrowsShowing = false;});
    });
        
    $("#nextBanner").click(function() { rotateBannerImage(); });
    $("#previousBanner").click(function() {
      clearTimeout(interval);
     
      var lastPos = imagePos;
      var images = $(".bannerImages").find("img");
    
      if(imagePos == 0)
        imagePos = images.length-1;
      else
        imagePos--;
      
      //In the case of a two image slideshow
      if(imagePos < 0)
        imagePos = images.length-1;
      
     
      $("#BannerImage"+imagePos).show("slide", { direction: "right" }, 1000);//Fade in the next image
      $("#BannerImage"+lastPos ).hide("slide", { direction: "left" }, 1000);//Fade out the current one
      interval = setTimeout("rotateBannerImage()", 6000);
    });
  }
  $(".slideshowImages img").each(function () {
      if($(this).parent()[0].nodeName == "A")
        $("#filmstrip").append('<li><a href="'+$(this).parent().attr("href")+'"><img src="' + $(this).attr("src") + '" /></a></li>');
      else
        $("#filmstrip").append('<li><img src="' + $(this).attr("src") + '" /></li>');
  
  });
  $('#filmstrip').galleryView({
    panel_width: 510,
    panel_height: 300,
    frame_width: 50,
    frame_height: 50,
    pause_on_hover: true,
    background_color: 'black'
    
  });
  
  $('#centerContent:not(.trustees,.greyContainer,.flatPages)').find("img").each(function() {
    if($(this).parent()[0].tagName != "A" && !$(this).parent().hasClass("bannerImages") && $(this).attr('src').lastIndexOf("_") != -1) {
      var src = $(this).attr('src');
      src = src.substr(0, src.lastIndexOf("_")) + src.substring(src.lastIndexOf("."));
      var a = $('<a/>').attr('href', src).addClass("fancyimage");
      $(this).wrap(a);
    }
  });

  $('.fancyimage').fancybox();
});
    
function rotateBannerImage() {
  clearTimeout(interval);
 
  var lastPos = imagePos ;
  
  //Find the next image to fade in
  imagePos++;
  var images = $(".bannerImages").find("img");
  
  if(imagePos >= images.length)
    imagePos = 0;
 
  $("#BannerImage"+imagePos).show("slide", { direction: "left" }, 1000);//Fade out the current image
  $("#BannerImage"+lastPos ).hide("slide", { direction: "right" }, 1000);//Fade in the next image
  interval = setTimeout("rotateBannerImage()", 6000);
}

