/**
* CountDown Class
*
* @author        Giovambattista Fazioli
* @email         g.fazioli@undolog.com
* @web           http://www.undolog.com
*
* @param    dd   (string) 'month day, year'
*
*/
function counterB( dd ) {
	this.padding = function (s,l) {
		return( Number( l.substr(0, (l.length-s.length) )+s ) );
	}
   
    /**
     * refresh countdown
     */
    this.refresh = function() {
		var target					= new Date("May 08,2008");
		this.targetTime				= target.getTime();
		//
		var today				 	= new Date();
		this.currentTime		 	= today.getTime();
		// time left
		this._leftMilliseconds		= (this.currentTime - this.targetTime);
		this._leftSeconds		 	= Math.floor( this._leftMilliseconds / 1000 );
		this._leftMinutes		 	= Math.floor( this._leftSeconds / 60 );
		this._leftHours		   		= Math.floor( this._leftMinutes / 60 );
		// no module
		this.leftDays			 	= this.padding( String(Math.floor( this._leftHours / 24 ) ), '00');
		// for print
		this.leftMilliseconds		= this.padding( String(this._leftMilliseconds % 1000),'0000');
		this.leftSeconds		  	= this.padding( String(this._leftSeconds % 60),'00');
		this.leftMinutes		  	= this.padding( String(this._leftMinutes % 60),'00');
		this.leftHours				= this.padding( String(this._leftHours % 24),'00');
		
		this.percSeconds			= Math.round( ( (59-(this._leftSeconds % 60) )/59 )*100 );
		this.percMinutes			= Math.round( ( (59-(this._leftMinutes % 60) )/59 )*100 );
		this.percHours				= Math.round( ( (23-(this._leftHours % 24) )/23 )*100 );
		this.percDays				= Math.round( ( (53-(this._leftHours / 24) )/53 )*100 );
    }
    this.refresh();
}

var i = setInterval(intervalCounter, 1000);

function showCounter() {
	var cd = new counterB('5 8, 2008');
	var oo = (cd.leftDays + 2054) + " giorni<br/>" + cd.leftHours + " ore<br/>" + cd.leftMinutes + " minuti<br/>" + cd.leftSeconds + ' secondi';
	return oo;
}

function intervalCounter() {
	jQuery('div#counterB').html( showCounter() );
}
