function RotationSpace(id)
{
	this.space = document.getElementById(id);
	this.img = this.space.getElementsByTagName("img")[0];
	this.link = this.space.getElementsByTagName("a")[0];
	this.images = [];
	this.originals = [];
	this.sec = 1000;
	this.stop = false;
	
	var self = this;
	this.link.onmouseover = function()
	{
		self.stop = true;
	}
	
	this.link.onmouseout = function()
	{
		self.stop = false;
	}
}

RotationSpace.ROTATION = "rotation";
RotationSpace.RANDOM = "random";

RotationSpace.prototype.addImage = function(obj)
{
	this.images.push(obj);
	this.originals.push(obj);
}

RotationSpace.prototype.start = function(type)
{
	var self = this;
	self.interval(type);	
	
	this.timer = setInterval(function()
	{	
		if(!self.stop)	self.interval(type);
				
	} , this.sec );

}

RotationSpace.prototype.interval = function(type)
{
	switch(type)
	{
		case 'rotation' :
			var obj = this.images.pop();
			
		break;
		
		case 'random' :
			var key = (Math.floor(Math.random()*999999 % this.images.length)) ;
			var obj = this.images[key];
			this.images.splice( key  , 1 );
		break;
	}

	this.img.setAttribute("src" , obj.src );
	this.link.setAttribute("href" , obj.link );
	if(this.images.length == 0)
	{
		for(var i = 0 ; i < this.originals.length ; i++)
		{
			this.images.push( this.originals[i]);
		}
	}

}
