/*=============================================================================

			 TITLE:		NMO Rotating Image System
		MODIFIED:		2006.06.19
   AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		REQUIRES:		Prototype 1.5.0 ( www.conio.com )

=============================================================================*/

var NMO_IMAGE_ROTATORS = $A( new Array() );

var ImageRotator = Class.create();

ImageRotator.init = function() {
	$$(".NMORotatingImageCollection").each( function(el) {
		NMO_IMAGE_ROTATORS.push( new ImageRotator(el) );
	} );
}

ImageRotator.prototype = {
	
	initialize: function( elementRef )	{
		this.container = elementRef;
		this.images = $$("#" + elementRef.id + " img");
		this.counter = 0;
		this.interval = 5;
		if ( this.images.length > 0 && this.interval > 0 ) {
			this.pe = new PeriodicalExecuter( this.nextImage.bind(this), this.interval );
		}
	},
	
	showImage: function() {
		var img = this.images[this.counter];
		Effect.Appear( img );
		if ( this.interval > 0 ) {
			if ( this.counter == (this.images.length -1) ) {
				this.counter = 0;
			} else {
				this.counter++;
			}
		}
	},
	
	nextImage: function() {
		this.images.each( function(img) {
			Effect.Fade( img );
		} );
		var funcRef = this.showImage;
		var delEx = setTimeout( this.showImage.bind(this), 1000 );
	}
	
}

Event.observe( window, "load", ImageRotator.init, false );


