
var RotateStands = new Class({
	Binds : ['_refreshStands', '_completeRequest'],
	
	initialize : function()
	{
		
		if (!$('random-stands')) {
			return;
		}
		
		this._currentContainer = $('random-stands').getChildren('ul');
		if (!this._currentContainer[0]) {
			return;
		}
		
		var language = document.location.href.toString().replace(/http.?:\/\//, '').split('/');
		if (!language[1]) {
			return;
		}
		this._language = language[1];
		
		this._currentContainer = this._currentContainer[0];
		
		this._number = this._currentContainer.getElements('li').length;
		
		this._timer = null;
		this._request = new Request.HTML({
			url: '/' + this._language + '/index/get-random-stands/number/' + this._number,
			method : 'get',
			onComplete : this._completeRequest
		});
		
		this._startRotateTimer();
	},
	
	_startRotateTimer : function()
	{
		$clear(this._timer);
		this._timer = this._refreshStands.delay(10000);
	},
	
	_refreshStands : function()
	{
		if (this._request.running) {
			this._startRotateTimer();
		}
		this._request.send();
	},
	
	_completeRequest : function(html, i, i2)
	{
		//this._currentContainer.set('html', i2);
		var coordinates = this._currentContainer.getCoordinates(this._currentContainer.getParent());
		var newUl = new Element('ul', {'class': 'background-degrade'})
			.set('tween', {duration: 1000})
			.setStyles({'top': coordinates.top, 'left': coordinates.left - coordinates.width})
			.set('html', i2);
		newUl.inject(this._currentContainer, 'before');
		this._currentContainer
			.set('tween', {duration: 1000, onComplete: function (el) {el.destroy()}})
			.tween('left', coordinates.left + coordinates.width);
		newUl.tween('left', coordinates.left);
		this._currentContainer = newUl;
		this._startRotateTimer();
	}
	
});

window.addEvent('domready', function () {
	var rotateStands = new RotateStands();
});
















