var galleryTimer;
var currentImg = 0;
var galleryLength;


$(document).ready(function()
{
   addProjectGallery();
   var yourBrowser = navigator.appName;
   var yourBrowserVersion = navigator.appVersion;
   yourIEVersion = yourBrowserVersion.substring(22, 23);
   if (yourBrowser == "Microsoft Internet Explorer" && yourIEVersion == 6)
   {
      addPNG();
      fixFooter();
   }
});

function addProjectGallery()
{
   $(".projectGallery img:eq(0)").css("display","block");
   $(".projectGallery .galleryNav a:eq(0)").addClass("active");
   galleryLength = $(".projectGallery img").length;
   setGalleryTimer();
   addAnchorEvent();
}

function setGalleryTimer()
{
   galleryTimer = setTimeout("galleryNext()",0);
}

function galleryNext()
{
   // move to next gallery item
   if (currentImg > galleryLength - 1)
   {
      currentImg = 0;
   }
   $(".projectGallery img").css("display","none");
   showImg = ".projectGallery img:eq(" + currentImg + ")";
   $(showImg).css("display","block");
   $(".projectGallery .galleryNav a").removeClass("active");
   showThmb = ".projectGallery .galleryNav a:eq(" + currentImg + ")";
   $(showThmb).addClass("active");
   currentImg = currentImg + 1;
   galleryTimer = setTimeout("galleryNext()",4000);
}

function addAnchorEvent()
{
   $(".projectGallery .galleryNav a").click(function(){
      clearTimeout(galleryTimer);
      anchorIndex = $(this).parent("div").children("a").index(this);
      currentImg = anchorIndex;
      $(".projectGallery img").css("display","none");
      showImg = ".projectGallery img:eq(" + anchorIndex + ")";
      $(showImg).css("display","block");
      $(".projectGallery .galleryNav a").removeClass("active");
      showThmb = ".projectGallery .galleryNav a:eq(" + anchorIndex + ")";
      $(showThmb).addClass("active");
      galleryTimer = setTimeout("galleryNext()",4000);
      return false;
   });
}

