function GaleriePhotos( targetElement, _container ) {
  this.start = function() {
    for( var i=0; i<this.images.length; i++ )
      addListener( this.images[ i ].parentNode, 'click', Delegate.create( this, 'onClick', this.images[ i ] ) );
  }
  this.onClick = function( e, imageSource ) {
    DOMEvent.stopEvent( e );

    var target = DOMEvent.getTarget( e );
    if ( target.parentNode.href ) {
      this.target.src = GaleriePhotos.LOADING_PIX_URL;
      new ImagePreloader( target.parentNode.href, Delegate.create( this, 'onImageLoaded' ) );
		}
  }
  this.onImageLoaded = function( pix ) {
    this.target.src = pix.src;
  }

	new ImagePreloader( GaleriePhotos.LOADING_PIX_URL, Delegate.create( this, 'start' ) );

  this.target = targetElement;
  this.images = _container.getElementsByTagName( 'img' );
}
GaleriePhotos.LOADING_PIX_URL = '/images/loading.gif';


addListener( window, 'load', function( e ) {
  new GaleriePhotos( document.getElementById( 'block-thumb-target' ), document.getElementById( 'block-thumbs-holder' ) );
} );
