function FlashSelling (id, days, delta, pageType, locale) {
	this.mainDiv = $('#flashSellingMainDiv' + id);
	this.countDown = $('#countDown' + id);
	this.pageType = pageType;
	this.delta = delta;
	this.days = days;
	this.layout = ""; 
	// valeur par défaut correspondant à la locale (fr)
	this.dateFormat = "D";
	this.dayShortFormat = "J";
	this.dayLongFormat = "Jour";
	this.daysLongFormat = "Jours";
	this.hourShortFormat = "H";
	this.hourFormat = "h";
	this.minuteFormat = "min";
	this.secondFormat = "sec.";
	this.locale = "";
	this.setLocalParams(locale);
	this.msPerDay = 86400000;
	this.msPerHour = 3600000;
	this.msPerMinute = 60000;
	this.msPerSecond = 1000;
}

FlashSelling.prototype = {
    showCountDown: function() {
    	var object = this;
    	this.delta = this.delta - 1000;
    	if(this.delta > 0) {
	 		setTimeout(function(){object.showCountDown()},1000);
	 		var diff = parseInt(this.delta);
	 		var days = parseInt(diff / parseInt(this.msPerDay));
	 		diff = diff - days*this.msPerDay;
	 		var hours = parseInt(diff / this.msPerHour);
	 		diff = diff - hours*this.msPerHour;
	 		var minutes = parseInt(diff / this.msPerMinute);
	 		diff = diff - minutes*this.msPerMinute;
	 		var seconds = parseInt(diff / this.msPerSecond);
	 		this.countDown.html(this.applyPattern(days, hours, minutes, seconds));
	 	} else {
	 		this.countDownOff();
	 	}
    },
    applyPattern: function(days, hours, minutes, secondes) {
    	var strDays = days;
    	var strHours = this.formatNumber(hours);
    	var strMinutes = this.formatNumber(minutes);
    	var strSeconds = this.formatNumber(secondes);
    	var layout = "";
    	if(this.pageType=='product') {
	    	if (this.days >= 2){
				layout = '<strong>' + strDays + ' ' + this.daysLongFormat + ' ' + strHours + ' ' + this.hourFormat + ' ' + strMinutes + ' ' + this.minuteFormat + ' '+ strSeconds + ' ' + this.secondFormat + '</strong>';
			} else if (this.days >= 1){
				layout = '<strong>' + strDays + ' '+ this.dayLongFormat + ' ' + strHours + ' ' + this.hourFormat + ' ' + strMinutes + ' ' + this.minuteFormat + ' '+ strSeconds + ' ' + this.secondFormat + '</strong>';
			} else if(this.days < 1){
				layout = '<strong>'+ strHours + ' '+ this.hourFormat + ' ' + strMinutes + ' ' + this.minuteFormat + ' '+ strSeconds + ' ' + this.secondFormat + '</strong>';
			}
		} else {
			if (this.days >= 2){
				layout = strDays + ' ' + this.daysLongFormat + ' ' + strHours + ':' + strMinutes + ':' + strSeconds;
			} else if (this.days >= 1){
				layout = strDays + ' ' + this.dayLongFormat +' '+ strHours + ':' + strMinutes + ':' + strSeconds;
			} else if(this.days < 1){
				layout = strHours + ':' + strMinutes + ':' + strSeconds;
			}
		}
		return layout;
    },
    formatNumber: function(number) {
    	if (number<10) {
    		return '0'+number;
    	}
    	else return number;
    },
    setLocalParams: function(locale) {
    	this.locale = locale.substring(0,2);
    	if(this.locale == 'de') {
    		this.dayShortFormat = 'T';
			this.dayLongFormat = 'Tag';
			this.daysLongFormat = 'Tags';
			this.hourShortFormat = 'S';
			this.hourFormat = 'St';
			this.minuteFormat = 'Min';
			this.secondFormat = 'Sek.';
    	}	
    },
    countDownOff: function() {
    	this.mainDiv.css("display","none");
    }
    
}