var akaruaCountdown = new Class({

	Implements: [Events, Options],
	
	options: {
		container : 'countdown',
		futureDate : $empty,
		onlySeconds : false,
		dayText : 'day',
		hourText : 'hour',
		minuteText : 'minute',
		secondText : 'second',
		onCompleteText : '',
		startFont : '20px',
		finishFont : '10px',
		duration : 1000,
		onComplete : $empty,
		amount : $empty,
		amountTotal : $empty,
		months : $empty,
		days : $empty,
		hours : $empty,
		minutes : $empty,
		seconds : $empty
	},
	
	initialize : function(options){
		this.setOptions(options);
		
		if(this.options.onlySeconds === true) {
		  this.options.amountTotal = this.options.futureDate;
		  this.startOnlySeconds();
		}else{
		  this.start();
		}
	},
	
	start : function(){
		this.getCount();	
	},
	
	getCount : function(){
		var out = '';
		this.now = new Date();
		
		this.options.amount = this.options.futureDate - this.now.getTime();
		
		this.options.amount = Math.floor(this.options.amount/1000);
		this.options.amountTotal = this.options.amount;
		
		this.options.days = Math.floor(this.options.amount/86400);
		this.options.amount = this.options.amount%86400; 
		
		this.options.hours = Math.floor(this.options.amount/3600);
		this.options.amount = this.options.amount%3600;
		
		this.options.minutes = Math.floor(this.options.amount/60);
		this.options.amount = this.options.amount%60;
		
		this.options.seconds = this.options.amount;
		
		if(this.options.days>180){
			this.options.months=6;
			this.options.days=(this.options.days-180);
		}else if(this.options.days>152){
			this.options.months=5;
			this.options.days=(this.options.days-152);
		}else if(this.options.days>121){
			this.options.months=4;
			this.options.days=(this.options.days-121);
		}else if(this.options.days>91){
			this.options.months=3;
			this.options.days=(this.options.days-91);
		}else if(this.options.days>60){
			this.options.months=2;
			this.options.days=(this.options.days-60);
		}else if(this.options.days>30){
			this.options.months=1;
			this.options.days=(this.options.days-30);
		}else{
			this.options.months=0;
		}
		
		out += "<li class='months'>"+this.options.months +"</li>";
		out += "<li class='days'>"+this.options.days +"</li>";
		out += "<li class='hours'>" + this.options.hours +"</li>";
		out += "<li class='mins'>" +this.options.minutes +"</li>";
		
		$(this.options.container).set('html',out);
	    
	    var elSeconds = new Element('li',{
	      id : "seconds",
	      html : this.options.seconds
	    });
	    
	    elSeconds.inject(this.options.container);
	        
	    //l'effet
	    this.options.amountTotal--; 
	    var fx = new Fx.Tween($("seconds"),{
	      duration: this.options.duration,
	      onComplete: function() { 
	        if(this.options.amountTotal >= 0) {         
	          this.getCount();
	        }
	        //else {
	          // $(this.options.container).set('text',this.options.onCompleteText);
	           //this.fireEvent('complete');
	        //}
	      }.bind(this)
	    }).start('opacity',1); 
	}
});