/**
 * Blinker
 * 
 * @license		MIT-style license
 * @author		Anquetil Manuel <manu [at] chess-mind.com>
 * @copyright	Author
 */
var Blinker = new Class({
	
	Implements: [Options, Events],
	
	options: {
		duration: 800,
		interval: 800,
		transition:	Fx.Transitions.linear
	},
					
	initialize:	function(content, options){
		this.content = $(content);
		this.setOptions(options);
		
		this.effect = new Fx.Morph(this.content, {
			duration: this.options.duration,
			transition: this.options.transition
		});
	},
	
	start: function(times) {
		this.options.times = $type(times)=='number'?times:0;
		this.times = 0;
		if(!this.started) {
			this.periodicalVar = this.blink.periodical(2 * this.options.duration + this.options.interval, this);
			this.started = true;			
		}
	},
	
	stop: function() {
		$clear(this.periodicalVar);
		this.started = false;
	},

	blink: function() {
		this.times++;
		this.effect.start({opacity: [1, 0]}).chain(
			function() {
				this.effect.start({opacity: [0, 1]});
			}.bind(this)
		);
		if(this.options.times > 0 && this.times >= this.options.times) {
			$clear(this.periodicalVar);
		}
	}
	
});