function Countdown() {
	var time_left = 10; //number of seconds for countdown
	var output_element_id = 'Countdown_time';
	var keep_counting = 1;
	var no_time_left_message = 'No time left for JavaScript countdown!';
 	var onNoTimeLeft = null;
 	var timeout = null;
 		
 	var timeOutReference = null;
 	
 	var callBackEveryTickFunc = false;
 	
 	var returnOnlySeconds = false;
	 function countdown() {
		
		if(time_left < 2) {
			keep_counting = 0;
		}
 
		time_left = time_left - 1;
	}
 
	function add_leading_zero(n) {
		if(n.toString().length < 2) {
			return '0' + n;
		} else {
			return n;
		}
	}
 
	function format_output() {
		var hours, minutes, seconds;
		seconds = time_left % 60;
		minutes = Math.floor(time_left / 60) % 60;
		hours = Math.floor(time_left / 3600);
 
		seconds = add_leading_zero( seconds );
		minutes = add_leading_zero( minutes );
		hours = add_leading_zero( hours );
		return (returnOnlySeconds) ? parseInt(seconds) :  hours + ':' + minutes + ':' + seconds;
		
	}
 
	function show_time_left() {
		
		if(output_element_id){
			if(typeof output_element_id == 'string'){
				$('#' + output_element_id).text(format_output());//time_left;
			}
			
			if(typeof output_element_id == 'object')
				$(output_element_id).text(format_output());
		}
			
		
		if(typeof callBackEveryTickFunc == 'function'){
		
			callBackEveryTickFunc();
		}
	
		
	}
 
	function no_time_left() {
		//call to callback function
		
		if (typeof(onNoTimeLeft) === "function")
        	onNoTimeLeft();
	}
 
	
	this.count = function () {	
		countdown();
		show_time_left();
	};
	
	this.timer = function () {
		this.count();
		//console.log(keep_counting)
 		if(keep_counting) {
 			var that = this;
 			timeOutReference = setTimeout(function(){that.timer()}, 1000);
			
		} else {
			
			no_time_left();
		}
	};
	/*
	 * if callBackEveryTick set, then the callback 
	 * function will be executed every clock tick,
	 * 
	 */
	this.init = function (t, element_id, f, callBackEveryTick, onlySeconds) {
		callBackEveryTickFunc = callBackEveryTick || false;
		output_element_id = element_id;
		time_left = t;
		onNoTimeLeft = f;
		keep_counting = 1;
		returnOnlySeconds = onlySeconds;
		this.timer();
			
	};
		
	this.updateTimeLeft = function(t){
		time_left = t;
	};
	/*
	 * @param string/jQuery element,
	 * contains the id or the jQuery element 
	 * himself where the timer output should be placed 
	 */
	this.updateOutputElementId = function(element){
		output_element_id = element;
	}
		
	this.updateOnTimeLeftCallback = function(f){
		onNoTimeLeft = f;
	};
	
	this.getTimeLeft = function(){
		
		return time_left;
	}
	/**
	 * clears the interval and destructs the object
	 */
	this.destruct = function(){
		
		clearTimeout(timeOutReference);
		delete that;
	}
	
}
