function detectImageLoad() {
	var thumbnailGroup = $$('#thumbnails img');
	var stillLoading = false;
	thumbnailGroup.each(function(t){
		if (!t.complete) stillLoading = true;
	})
	if (stillLoading) {
		detectImageLoad();
	} else {
		makeSlideShow();
	}
}

function makeSlideShow() { 
   var groups = $$('#images ul li');
   //groups.first().addClassName('selected');
   groups.each(function(g){
	  g.addClassName('startup');
	  g.setStyle({display:'none'});
  }) 
   groups.first().setStyle({display:'block'});

	$$('#images ul').first().setStyle({display:'block'});
	
   var triggers = $$('#thumbnails img');
   triggers.first().addClassName('current');
   current = groups.first();
   $R(0,(triggers.length-1)).each(function(i){
	  triggers[i].onclick = function() {
		if(current!=groups[i]) {
			Effect.Fade(current, { duration:0.8, from:1.0, to:0.0 });
			Effect.Appear(groups[i], { duration:0.8, from:0.0, to:1.0 });
			current = groups[i];
		}
		triggers.each(function(t){
			t.removeClassName('current');
		}); 
		this.addClassName('current');
	  }
   });

	$$('#images').first().setStyle({background:'none'});

}

Event.observe(window, 'load', function () {
	detectImageLoad();
})