function readDir(){
  new Effect.Appear("busyDir", { duration: 0.3 });
  new Ajax.Updater("list", "gallery/readdir.php", 
    {
    onComplete: function() { EventSelectors.start(Rules); new Effect.Fade("busyDir", { duration: 0.3 }); }
    });
}

function readImages(dir){
  new Effect.Appear("busyImg", { duration: 0.3 });
  new Effect.Appear("gallery", { duration: 0.3 });
  new Ajax.Updater("gallery", "gallery/readimages.php",
    { 
    postBody: "dir=" + dir,
    onComplete: function(){ new Effect.Fade("busyImg", { duration: 0.3 }); }
    });
}

function displayImg(element){
  new Effect.Appear("displayDiv", { duration: 0.3 });
  /* $("displayImg").appendChild(loading); */
  var img = new Image;
  img.src = element.src;
  img.title = "Right Click this image to save it to your computer.";
  /* $("displayImg").removeChild($("displayImg").firstChild); */
  $("displayImg").appendChild(img);
}

function hideImg(){
  new Effect.Fade("displayDiv", { duration: 0.3 });
  $("displayImg").removeChild($("displayImg").firstChild);
}

var Rules = {
	'#galleryContainer td:click': function(element){ readImages(element.getAttribute("file")); },
	'#galleryContainer tr:mouseover': function(element){ element.parentNode.style.backgroundColor = "#708090"; },
	'#galleryContainer tr:mouseout': function(element){ element.parentNode.style.backgroundColor = Element.hasClassName(element.parentNode, "ruler") ? "#222222" : "transparent"; },
  '#galleryContainer #gallery img:click': function(element){ displayImg(element); },
  '#galleryContainer #displayClose:click': function(){ hideImg(); }
};