/**
 * Snow
 * @classDescription  
 * @dependence        Mootools (http://www.mootools.net)
 * @author            Aken.li (http://www.kxbd.com)
 * @created           2009-11-25
 */
var Ladder = new Class({

	Implements: [Options,Events],
	
	options:{
		sign:'L',
		interval:30,
		width:30,
		height:30,
		speedX: 0,
		speedY: 2,
		score:1,
		scale:1,
		opacity:1
	},
	
	initialize:function(pX, pY, pHolder, options){
		this.setOptions(options);
		this.x = pX;
		this.y = pY;
		this.width = this.options.width;
		this.height = this.options.height;
		this.isHited = false;
		this.score = this.options.score;
		this.ladder = this.create();
		this.holder = $(pHolder);
		this.ladder.inject(this.holder);

		this.init();
	},

	create:function(){
		return new Element('div', {
			'class': 'ladder',
			'text': this.options.sign,
			'styles': {
				'left':this.x,
				'top':this.y
			}
		});
	},

	init:function(){
		this.moveTimer = this.move.periodical(this.options.interval,this);
	},

	render:function(){
		this.ladder.setStyles({
			left:this.x,
			top:this.y
		});
	},

	move:function(){
		this.y += this.options.speedY;
		this.render();
		if (this.y > 300) {
			this.remove();
		}
	},

	remove:function(){
		this.fireEvent('ladderRemove',this);
		this.moveTimer = $clear(this.moveTimer);
		//this.ladder.destroy();
		this.fadeTimer = this.fadeOut.periodical(this.options.interval,this);
	},

	fadeOut:function(){
		this.options.opacity -= 0.05;
		this.ladder.setStyle('opacity',this.options.opacity);
		if (this.options.opacity <= 0) {
			this.fadeTimer = $clear(this.fadeTimer);
			this.ladder.destroy();
		}
	}
});
