function MyRotator () {

	// public
	this.direction = 'left'
	this.wrap = true;
	this.start = 0;
	this.auto = true;
	this.interval = 5000;
	this.holder = 'spotlight_images';

	// private
	var current = 0;
	var position = 0;
	var tween;
	var intervalObj;
	var numItems = 0;
	var holderSize = 0;
	
	this.init = function () {
		var host = this;
		var obj = document.getElementById(this.holder);
		if (!obj) {
			return;
		}
		
		holderSize = obj.offsetWidth;
		
		var li = obj.getElementsByTagName('li');
		for (var i = 0; i < li.length; i++) {
			li[i].style[this.direction] = (i * holderSize)+ 'px';
		}
		
		numItems = li.length;
		if (this.start > 0) {
			this.change(this.start);
		}
		
		var li = document.getElementById('spotlight_tabs').getElementsByTagName('a');
		for (var i = 0; i < li.length; i++) {
			(function(i) {
				Magic.Event.addEvent(li[i], 'click', function(e) {
					Magic.Event.cancelEvent(e);
					host.change(i);
				});
			})(i);
		}

		this.autoskip();
	}
	
	this.count = function () {
		return numItems;
	}
	
	this.autoskip = function () {
		this.stopauto();
		if (this.auto) {
			var host = this;
			intervalObj = setInterval(function(){host.next();}, this.interval);
		}
	}
	
	this.stopauto = function () {
		if (intervalObj) {
			clearInterval(intervalObj);
		}
	}
	
	this.tab = function () {
		var selected;
		var li = document.getElementById('spotlight_tabs').getElementsByTagName('li');
		for (var i = 0; i < li.length; i++) {
			selected = '';
			if (li[i].getAttribute('id') == 'item_' +current) {
				selected = 'selected';
			}
			li[i].className = selected;
		}
	}
	
	this.change = function (num) {
		if (num == current) {
			return false;
		}
		
		this.stopauto();
		if (this.count() <= 1) {
			return;
		}
		current = this.validate(num);
		this.scroll();
		this.tab();
		this.autoskip();
		return false;
	}
	
	this.scroll = function () {
		var obj = document.getElementById('spotlight_images');
		if (!obj) {
			return;
		}
		
		start = parseInt(obj.style[this.direction]);
		if (isNaN(start)) {
			start = 0;
		}
		
		end = -(holderSize * current);
		if (start == end) {
			return;
		}
		
		if (tween) {
			tween.stop();
		}
		
		tween = new Tween(obj.style, this.direction, Tween.regularEaseOut, start, end, 1, 'px');
		tween.start();
	}
	
	this.next = function () {
		num = current + 1;
		if (this.wrap && num > (this.count() - 1)) {
			num = 0;
		}
		this.change(num);
	}
	
	this.previous = function () {
		num = current - 1;
		if (this.wrap && num < 0) {
			num = this.count();
		}
		this.change(num);
	}
	
	this.validate = function (num) {
		return Math.max(0, Math.min(this.count() - 1, num));
	}
	
	this.loader = function (val) {
		var obj = document.getElementById('item_loader');
		if (!obj) {
			return;
		}

		obj.style.opacity = 0.5;
		obj.style.display = val;
	}
}