// JavaScript Document
var Uccello = {
	uccello: '',
	start: -220,
	end: 0,
	bottom: 0,
	
	getSize: function() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		this.end = myWidth;
		this.bottom = myHeight - 147;
		
		return {"width": myWidth, "height": myHeight };
	},
	
	spring: function() {
		this.uccello.changeClassNames('front', 'back');
		this.uccello.removeClassName('hidden');
		var __this = this;
		
		var effect = new Effect.Move(this.uccello, {  
				x: this.end, 
				y: this.bottom/2,
				mode: 'absolute', 
				transition: Effect.Transitions.spring, 
				curve: function(pos) {
					return pos*(1-pos);
				},
				duration: 20.8, 
				delay: 2.0,
				
				afterUpdate: function() {
					if ( effect.currentFrame >= 500) {
						__this.uccello.changeClassNames('back', 'front');
						effect.afterUpdate = null;
					}
				},
				
				afterFinish: function() {
					__this.uccello.addClassName('hidden');
					__this.linear();
				}
			}
		);
		
	},
	
	linear: function() {
		this.uccello.changeClassNames('back', 'front');
		var __this = this;
		this.uccello.removeClassName('hidden');
		new Effect.Move(this.uccello, {x: this.start, mode: 'absolute', transition: Effect.Transitions.linear, duration: 20.8,
			afterFinish: function() {
				__this.uccello.addClassName('hidden');
				__this.sinoidal();
			}										
		});
	},
	
	sinoidal: function() {
		this.uccello.changeClassNames('front', 'back');
		var __this = this;
		this.uccello.removeClassName('hidden');
		new Effect.Move(this.uccello, {x: this.end, y: this.bottom, mode: 'absolute', transition: Effect.Transitions.sinoidal, duration: 10.8, delay: 5.0,
				afterFinish: function() {
					__this.uccello.addClassName('hidden');
					__this.flicker();
				}										
		});
	},

	flicker: function() {
		this.uccello.changeClassNames('back', 'front');
		var __this = this;
		this.uccello.removeClassName('hidden');
		new Effect.Move(this.uccello, {x: this.start, mode: 'absolute', transition: Effect.Transitions.flicker, duration: 0.5, delay: 5.0,
			afterFinish: function() {
				__this.uccello.addClassName('hidden');
				__this.spring();
			}										
		});
	},
}

document.observe("dom:loaded", function() {
	//	document.body.width = screen.availWidth;
		Uccello.uccello = $('uccello');
		Uccello.uccello.style.top = '0px';
		Uccello.uccello.style.left = Uccello.start + 'px';
		
		Uccello.getSize();
		Uccello.spring();
})
