﻿function Rotator(parentID) {
	var that = this;
	
	var _parentID = parentID;
	var _index = -1;
	var _pause = false;
	
	var _timer = null;
	var _timeout = 0;
	
	var _parent = null;
	var _current = null;
	var _nodes = null;
		
	Rotator.prototype.Rotate = function() {
			
		if (!_pause) {	
			if (_current != null) {
				_current.className = "rh";
			}
			
			_index++;
			
			if (_index >= _nodes.length) {
				_index = 0;
			}
			
			_current = _nodes[_index];
			_current.className = "rv";
		}
		
		_timer = setTimeout(function() { that.Rotate(); }, _timeout);
	}
	
	Rotator.prototype.Start = function(timeout) {	
	
		_timeout = timeout;
		_parent = document.getElementById(_parentID);
		_nodes = _parent.getElementsByTagName("div");
		_index = -1;
		
		_nodes = new Array();
				
		for (var x = 0; x < _parent.childNodes.length; x++) {
			var e = _parent.childNodes[x];
			if ((e.tagName != null) && e.tagName.toLowerCase() == "div" ) {
				_nodes.push(_parent.childNodes[x]);
			}
		}
		
		if (_nodes.length > 1) {
			$addHandler(_parent, 'mouseover', function() { _pause = true; });
			$addHandler(_parent, 'mouseout', function() { _pause = false; });
			this.Rotate();
		}
	}
	
	Rotator.prototype.Stop = function() {
		if (_parent) {
			$clearHandlers(_parent);
		}
		if (_timer) {
			clearTimeout(_timer);
		}
	}
	
}