Ext.namespace('Flying.airport');
Flying.airport.Cloud = Ext.extend(Ext.util.Observable, {
	constructor: function(runway, config){
		this.runway = runway;
		Ext.apply(this, config);
		Flying.airport.Cloud.superclass.constructor.apply(this, arguments);
		this.init();
	}
	
	//Config
	,runway: null
	
	,init: function(){
		this.initEl();
		this.initCloud();
		this.initListeners();
	}
	
	,initListeners: function(){
		this.runway.on('scroll', function(position){
			this.cloud.animate(
			    {
			    	top  : { to: position.y }
			    },
			    5,      // animation duration
			    null,      // callback
			    'easeBoth', // easing method
			    'motion'      // animation type ('run','color','motion','scroll')    
			);
		}, this);
	}
	
	,initEl: function(){
		this.el = Ext.get(Ext.DomHelper.append(Ext.getBody(), {
			tag: 'div'
			,cls: 'runway-cloud-el'
			,style: {
				top: '0px'
				,left: '0px'
				,width: '100%'
			}
		}));
	}
	
	,initCloud: function(){
		this.cloud = Ext.get(Ext.DomHelper.append(this.el, {
			tag: 'div'
			,cls: 'runway-cloud'
		}));
		
		//this.animateRight();
	}
	
	,animateLeft: function(){
		this.container.shift({
			scope: this
			,x: 0
			,duration: 10
			,easing: 'backOut'
			,callback: function(){
				setTimeout(this.animateRight.createDelegate(this), 5000);
			}
		});
	}
	
	,animateRight: function(){
		this.container.shift({
			scope: this
			,x: 100
			,duration: 10
			,easing: 'backOut'
			,callback: function(){
				setTimeout(this.animateLeft.createDelegate(this), 5000);
			}
		});
	}
	
});
