/* NextHardware - JAVASCRIPT DOCUMENT */


var K_nn    = document.layers                  ? true              : false;
var K_w3c   = document.getElementById          ? true              : false;
var K_beg   = K_nn                               ? "document.layers" : (K_w3c ? "document.getElementById('" : "document.all");
var K_mid2  = K_nn                               ? ""                : (K_w3c ? "')"       : "");


 /**
 * CountDown Class
 *
 * @author		Giovambattista Fazioli
 * @email		 g.fazioli@undolog.com
 * @web		   http://www.undolog.com
 *
 * @mod by Nexthardware
 *
 * @param	dd   (string) 'month day, year'
 *
 */
function countDown( dd , box ) {
	// init target time
	var target_box		  = eval(K_beg+box+K_mid2);
    var target            = new Date( dd );
    this.targetTime       = target.getTime();

    /**
     * refresh countdown
     */
    this.refresh = function() {
        var today             = new Date();
        var currentTime       = today.getTime();
        // time left
        this.leftMilliseconds = this.targetTime - currentTime;
        this.leftSeconds      = Math.floor(this.leftMilliseconds / 1000);
        this.leftMinutes      = Math.floor(this.leftSeconds / 60);
        this.leftHours        = Math.floor(this.leftMinutes / 60);
        this.leftDays         = Math.floor(this.leftHours / 24);
        this.render();
    };

    this.render = function() {
        this.leftMilliseconds = this.ms = this.leftMilliseconds%1000;
        this.leftSeconds = this.s = this.leftSeconds%60;
        this.leftMinutes = this.m = this.leftMinutes%60;
        this.leftHours = this.h = this.leftHours%24;
        this.d = this.leftDays;
        this.output('d,h,m,s:giorni,ore,min.,sec.');
    };

    this.output = function(_format) {
		var countdown_control = 0;
		var _forma = _format.split(':');
		var format = _forma[0].split(',');
		var label  = _forma[1].split(',');
		var output = '';
		//format.reverse();
		//label.reverse();
        for(var t in format) {
            if(this[format[t]] || format[t]=='s'){ 
				output += '<span id="date_' + format[t] + '" class="date_external"><span class="date_internal">' + this[format[t]] + '</span>' + label[t] + '</span>' + ((t!=format.length-1) ? ' ' : '');
			}
			if(this[format[t]]){
				countdown_control = 1;
			}
        }
		if(countdown_control==0){
			window.location.reload();
		}
        //return();
		target_box.innerHTML = output;
    };
    
	this.refresh();
}


