/**
 * @author Sergey Chikuyonok (gonarch@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 */


function Lift(elem){
	this.setPointer(elem);
	this.min_y=-40;
	this.max_y=70;
	this.wait();
}

Lift.prototype.setPointer=function(elem){
	this._ptr=elem;
}

Lift.prototype.getPointer=function(){
	return this._ptr;
}

Lift.prototype.wait=function(){
	if(this.timer)
		clearTimeout(this.timer);
	var me=this;
	this.timer=setTimeout(function(){me.animate();}, this._rand(1000, 3000));
}

Lift.prototype._rand=function(from, to){
	return Math.round(Math.random()*(to-from) + from);
}

Lift.prototype.animate=function(){
	if(this.tween)
		this.tween.stop();

	var ptr=this.getPointer();
	var me=this;
	this.tween=new Tween(ptr, 'top', EEQ.linear, ptr.offsetTop, (ptr.offsetTop < 0) ? this.max_y : this.min_y, 70);
	this.tween.onMotionFinished=function(){
		me.wait();
	}
}


$(function(){
	$('#lifts .lift').each(function(){new Lift(this);});
});