/* ........................................................
*/		
	function DEC_StageLayer(idLayer,xKoeff,xSelfShift,xSelf){
		this.oLayer = document.getElementById(idLayer);
		this.width = this.oLayer.offsetWidth;
		this.x = 0;
		this.xKoeff = xKoeff;
		this.xSelfShift = (xSelfShift)?xSelfShift:0;
		var xSelf = (xSelf)?xSelf:0;
		var stageWidth = 0;
		/* ........................................................
		*/		
			this.init = function (xShiftMax,xShift){
				this.x = (xSelf)?xSelf:(xShift*xKoeff);
				stageShiftMax = xShiftMax; 
				this.oLayer.style.left = this.x+"px";
			};
		/* ........................................................
		*/		
			this.resize = function (w){
				stageWidth = w;
				if(this.oLayer.tagName=="DIV"){
					this.oLayer.style.width = stageWidth+2*stageShiftMax*xKoeff+"px";
				}
			};
		/* ........................................................
		*/		
			this.stageMove = function (xShift){
				this.x += xShift*this.xKoeff;
			};
		/* ........................................................
		*/		
			this.move = function (speedKoeff){
				this.x += this.xSelfShift*speedKoeff;
				this.replace();
			};
		/* ........................................................
		*/		
			this.replace = function (){
				if(this.xSelfShift>0 && this.x>stageWidth+stageShiftMax){
					this.x = - this.width - Math.random()*stageWidth;
				}else if(this.xSelfShift<0 && this.x<-stageShiftMax){
					this.x = stageWidth + Math.random()*stageWidth;
				}
			};
		/* ........................................................
		*/		
			this.repaint = function (){
				this.oLayer.style.left = this.x+"px";
			};
	}
/* ........................................................
*/		
	function DEC_Stage(idContainer,shift,speed){
		var oTO = null;
		var selfObject = this;
		var aLayers = new Array;
		var oContainer = document.getElementById(idContainer);
		var width = oContainer.offsetWidth;

		var repaintSpeed = speed;
		var repaintSpeedDefault = speed;
		var x = 0;
		var xMax = shift;
		var xStep;
	/* ........................................................
	*/		
		this.init = function (w,shiftX,speed){
			oContainer.onmousemove = this.changeStep;
			oContainer.onmouseout = this.stop;
			this.resize(w);
			this.start();
		};
	/* ........................................................
	*/		
		this.resize = function (w){
			width = w;
			oContainer.style.width = w+"px";
			for(var i=0;i<aLayers.length;i++){
				aLayers[i].resize(w);
			}
		};
	/* ........................................................
	*/		
		this.appendLayer = function (oLayer){
			oLayer.init(xMax,-xMax);
			aLayers[aLayers.length] = oLayer;
		};
	/* ........................................................
	*/		
		this.start = function (){
			oTO = setTimeout(selfObject.repaint,repaintSpeed);
		};
	/* ........................................................
	*/		
		this.changeStep = function (e){
			var oEvent = (e)?e:(window.event)?window.event:null;
			repaintSpeed = (oEvent.screenX/width - 0.5);
			xStep = (repaintSpeed>=0)?-1:1;
			repaintSpeed = (1.5 - Math.abs(repaintSpeed)*2)*repaintSpeedDefault;
		};
	/* ........................................................
	*/		
		this.repaint = function (){
			if(oTO) clearTimeout(oTO);
			if(Math.abs(x+xStep)<xMax){	
				x+=xStep;
				for(var i=0;i<aLayers.length;i++){
					aLayers[i].stageMove(xStep);
				}
			}else{
				xStep = 0;
				repaintSpeed = repaintSpeedDefault;
			}
			oTO = setTimeout(selfObject.repaint,repaintSpeed);
			for(var i=0;i<aLayers.length;i++){
				aLayers[i].move(repaintSpeed/repaintSpeedDefault);
				aLayers[i].repaint();
			}
		};
	/* ........................................................
	*/		
		this.stop = function (){
			repaintSpeed = repaintSpeedDefault;
			xStep = 0;
		};
		return this;
	}