/*=============================================================================

				 TITLE:		NetMediaOne - Generic Rotator
			MODIFIED:		2008.06.23
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
	DEPENDENCIES:		NetMediaOne Core 1.2.0
									jQuery 1.2

=============================================================================*/

NMO.Rotator = function() {
	
	return {
	
		cycleTimer: "",
		selectedItem: 0,
		transitionInterval: 6000,
	
		init: function(elementRef) {
			var self = this;
			this.container = $(elementRef);
			this.items = this.container.children("li");
			if ( this.items.length > 1 ) {
				this.cycleTimer = setTimeout( function() { self.cycle(self); }, this.transitionInterval );
			}
		},
		
		cycle: function(self) {
			clearTimeout( this.cycleTimer );
			var oldItem = this.selectedItem;
			if ( this.selectedItem < this.items.length - 1 ) {
				this.selectedItem++;
			} else {
				this.selectedItem = 0;
			}
			var oI = $(this.items[oldItem]);
			var cI = $(this.items[this.selectedItem]);
			
			oI.fadeOut(2000);
			cI.fadeIn(2000);
			this.cycleTimer = setTimeout( function() { self.cycle(self); }, this.transitionInterval );
		}

	};

};

jQuery( function() {
	$(".Rotator").each( function() {
		new NMO.Rotator().init(this);
	} );
} );