

$(document).ready(function(){

  var elm_photoAlbumImages = $("#photoAlbumImages");

  intCounter = 1;
  $("li a", $(elm_photoAlbumImages)).each(function() {
    
    $(this).removeAttr("href");
    $(this).click(function(){
      showGallery(intCounter);
    });
    intCounter++;
  
    imgSrc = $("img", $(this)).attr("src");
    intFilePos = imgSrc.lastIndexOf("/")+1;
    strFileName = imgSrc.substr(intFilePos, (imgSrc.length - intFilePos));
    strFilePath = imgSrc.substr(0, intFilePos);
    strFileName = strFileName.replace("thumb-", "main-");
    strFilePath += strFileName;
    $(this).attr("href", strFilePath);
  });
  
  window.imageCount = $("li img", $(elm_photoAlbumImages)).length;

  $("li img", $(elm_photoAlbumImages)).each(function(){
  	var getSRC = $(this).attr('src');
  	$(this).attr('src','/_includes/images/icons/loading.gif');
  	var self = this;
  	var img = new Image();
  	$(img).load(function(){
  		$(this).hide();
  		$(self).removeClass('loading').replaceWith(this);
  		$(this).css({opacity:0, display:'inline'})
  		.animate({opacity:1},500);
  		imagesLoaded();
  	})
  	.attr('src', getSRC)
  	.attr('border','0');
  });

  $("li a", $(elm_photoAlbumImages)).lightBox();
  
});

window.imagesLoadedCount = 0;
function imagesLoaded(){
	window.imagesLoadedCount ++; 
	if(window.imagesLoadedCount == window.imageCount){
		$('#photoAlbumImages li').e4eColumnsFE();
	}
}

function showGallery(intImageID) {
/*
  $("#galleryOverlay").remove();

  $("body").append("<div id=\"galleryOverlay\"></div>");
  $("body").append("<div id=\"galleryOverlayContainer\"></div>");
  
  $("#galleryOverlay").css("width", "100%");
  $("#galleryOverlay").css("height", window.outerHeight);
  $("#galleryOverlay").css("position", "absolute");
  $("#galleryOverlay").css("top", "0");
  $("#galleryOverlay").css("background-color", "#000000");
  $("#galleryOverlay").css("opacity", "0.6");
  $("#galleryOverlay").css("z-index", "80");
  
  
  $("#galleryOverlayContainer").css("position", "absolute");
  $("#galleryOverlayContainer").css("top", "0");
  $("#galleryOverlayContainer").css("margin", "0 auto");
  $("#galleryOverlayContainer").css("z-index", "100");
 
*/

  
}
