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

			 	 TITLE:		Javascript Utility Library
		  MODIFIED:		2006.09.07
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		Prototype 1.5.0 ( www.conio.com )

=============================================================================*/
var NMO = window.NMO || {
	
	init: function() {
		NMO.Utils.enableFlashInteraction();
		$$(".NMOContentRotator").each( function(el) {
			NMO.Controls.rotatorGroups.push( new NMO.Controls.ContentRotator(el) );
		} );
	},
	
	Utils: {
		
		enableFlashInteraction: function() {
			$$("object").each( function(el) {
				el.outerHTML = el.outerHTML;																	
			} );
		}
		
	}, // Utils Namespace
	
	Controls: {
		
		rotatorGroups: $A( new Array() )		
		
	} // Controls Namespace
	
};

NMO.Controls.ContentRotator = Class.create();
NMO.Controls.ContentRotator.prototype = {
	
	initialize: function(elementRef) {
		this.container = $(elementRef);
		this.repeatDelay = this.container.getAttribute("repeatDelay") || -1;
		this.items = $$("#"+this.container.id+" .NMORotatorItem");
		this.showItem();
		this.container.style.display = "block";
	},
	
	showItem: function() {
		clearTimeout( this.repeatTimer );
		this.hideItems();
		var rNum = Math.floor( Math.random() * ( this.items.length - 1 ) );
		var el = this.items[rNum];
		el.style.display = "block";
		if ( this.repeatDelay > 0 ) {
			var proxyObj = this;
			proxyObj.repeatTimer = setTimeout( function() { this.showItem(); }.bind(proxyObj), proxyObj.repeatDelay );
		}
	},
	
	hideItems: function() {
		this.items.each( function(el) {
			el.style.display = "none";
		} );
	}
	
};

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