﻿var imgSrc, imgOnSrc;
var numImages;
var galleryIndex;

$(document).ready(function(){
  $('.galleryButtonList li img').hover(function(){
      imgSrc = $(this).attr('src');
      imgOnSrc = imgSrc.replace('_off','_on');    
      $(this).attr('src',imgOnSrc);
    },function(){
      imgOnSrc = $(this).attr('src');
      if (!$(this).hasClass('selected'))
         imgSrc = imgOnSrc.replace('_on','_off'); 
      $(this).attr('src',imgSrc);
    }
  );
  //$('.galleryButtonList li a').attr('href','#');
});

$(document).ready(function(){
  
  $('#galleryPrev img').hover(function(){
    var prevSrc = $(this).attr('src');
    $(this).attr('src',prevSrc.replace('prev','prevOn'));
  },function(){
    var prevSrcOn = $(this).attr('src');
    $(this).attr('src',prevSrcOn.replace('prevOn','prev'));
  });
  
  $('#galleryNext img').hover(function(){
    var nextSrc = $(this).attr('src');
    $(this).attr('src',nextSrc.replace('next','nextOn'));
  },function(){
    var nextSrcOn = $(this).attr('src');
    $(this).attr('src',nextSrcOn.replace('nextOn','next'));
  });
  
  var imagePreloader = new Image();
  $('.files').find('span').each(function(){
    var preloadSrc = $(this).html();
    imagePreloader.src = preloadSrc;
  });
  

  numImages = $('.files').find('span').length;  
  if (numImages > 0){
    if (numImages == 1)
      $('#galleryControls').html("");
    galleryIndex = 1;
    changeImage();
  }  
  
  $('#galleryPrev').click(function(){
    if (galleryIndex == 1)
      galleryIndex = numImages;
    else
      galleryIndex -= 1;
      changeImage();
      return false;
  });
  
  $('#galleryNext').click(function(){
    if (galleryIndex == numImages)
      galleryIndex = 1;
    else
      galleryIndex += 1;
    changeImage();
    return false;
  });
  
  
    /*
    var firstImage = $('ul.thumbnailList li:first img').attr('src');
    if (firstImage != undefined){
      $('ul.thumbnailList li:first img').attr('src',firstImage.replace("tb_","tbOn_")).addClass("thumbSelected");
      $('.galleryLeftContentContainer img').attr('src',firstImage.replace("tb_","")); 
      var firstPhotoID=$('ul.thumbnailList li:first img').attr('photoID');    
      $('.galleryCopy').html($('#caption'+firstPhotoID).html());    
      
      $('ul.thumbnailList img').click(function(){
        var photoID=$(this).attr('photoID');    
        $('.galleryCopy').html($('#caption'+photoID).html());    
        $('.thumbSelected').each(function(){
          var selectedSrc = $(this).attr('src');
          $(this).attr('src',selectedSrc.replace("tbOn_","tb_")).removeClass("selected");
        });
        var thumbSrc = $(this).attr('src');
        $('.galleryLeftContentContainer img').attr('src',thumbSrc.replace("tb_","")); 
        $(this).attr('src',thumbSrc.replace("tb_","tbOn_")).addClass("thumbSelected");     
        $(this).parent('a').blur();
        return false;
      
      });
    }
    */
});

$(document).ready(function(){
  $('#otherWindowTypes').click(function(){
    if ($('#otherWindowMenuContainer').css('display') == "none"){
      $('#otherWindowMenuContainer').slideDown(500);
    }else{
      $('#otherWindowMenuContainer').slideUp(200);
    }
    $(this).blur();
    return false;
  });
  
  $('.otherWindowsMenu').hover(function(){  
  },function(){
    setTimeout("$('#otherWindowMenuContainer').slideUp(200);",500);
  });
});

function changeImage(){
$('.galTitle').hide();
 $('#picTitle'+galleryIndex).show();
  $('.fullSizeImage').attr('src',$('#file'+galleryIndex).html());
  //$('.galleryCopy').innerHtml("");
  $('.galleryCopy').html($('#caption'+galleryIndex).html());    
}