var Simple_Rotator = {};

Simple_Rotator.view = function (list)
{
	this.items = [];
	this.current = 0;

	for ( var i = list.length-1; i >= 0; i-- )
	{
		this.items.push(list[i]);
	}
};
Simple_Rotator.view.prototype = {
	hide_all : function () {
		for (var i = this.items.length-1; i >= 0; i--)
		{
			this.items[i].style.display = 'none';
		}
	},
	show : function (num) {
		if (this.items.length <= 0)
		{
			return false;
		}
		if (num > this.items.length)
		{
			num = 1;
		}
		if (num < 1){
      num = this.items.length;
    }
		this.items[num - 1].style.display = 'block';
		this.current = num;
  },
	next : function () {
		this.hide_all();
		this.show(this.current - 1);
	},
	previous : function () {
		this.hide_all();
		this.show(this.current + 1);
	}
};

Simple_Rotator.controller = function (view,rot_interval)
{
	this.rotation = true;
	this.interval = 5000;
	this.view = view;
	
	if (typeof(rot_interval) != 'undefined')
    {
        this.interval = rot_interval;
    }
};
Simple_Rotator.controller.prototype = {
	start : function () {
		var self = this;
		var _start = function () {
			if (self.rotation)
				{
					self.view.next();
					setTimeout(_start,self.interval);
				}
		}
		_start();
	},
	stop : function () {
		this.rotation = false;
    },
	next: function () {
		this.view.next();
	  },
	previous: function () {
		this.view.previous();
	}
};

Simple_Rotator.create = function (list,interval)
{
	var view = new this.view(list);
	return new this.controller(view,interval);
};

