function Countdown(appendToElement, dateStr) {
	// Countdown component. Works out the difference between the current date and a certain date

	// Set the element to append to
	this.appendToElement = appendToElement;

	// Set up the date to go towards
	this.date = new Date(dateStr);

	// Set up two dates based on the current time
	this.currentDate = new Date();
	this.countdown = new Date();

	this.ele = null;
	this.difference = null;

	// Write out the div containing the countdown counter
	this.draw();

	// Set up a closed reference
	var closedRef = this;

	// Update every second
	setInterval(function() { closedRef.update() }, 1000);
}

Countdown.prototype.draw = function() {
	// Draw the counter display

	var ele = document.createElement("span");

	ele.innerHTML = this.getOuputDate();
	
	this.ele = ele;
	this.appendToElement.appendChild(ele);
}

Countdown.prototype.getDaysInMonth = function(monthID) {
	// Return how many days in month. Leap year support not added,
	// but shouldnt be an issue

	switch(monthID) {
		case 0:	 return 31; // Jan
		case 1:	 return 28; // Feb
		case 2:	 return 31; // ...
		case 3:	 return 30;
		case 4:	 return 31;
		case 5:	 return 30;
		case 6:	 return 31;
		case 7:	 return 31;
		case 8:	 return 30;
		case 9:	 return 31;
		case 10: return 30;
		case 11: return 31; // Dec
	}

	return false;
}

Countdown.prototype.getOuputDate = function() {
	// Get a string containing the data in format 'x days x:xx:xxs'

	this.difference = this.date.getTime() - (new Date()).getTime();

	this.countdown.setTime(this.difference);

	// If the difference is less then or equal
	// to zero, return some hyphens
	if (this.difference <= 0) {
		return "-- -- --";
	}
	
	// Work out how many days are due to go
	var days = (this.countdown.getFullYear() - 1970) * 365;
	
	days += this.countdown.getMonth() * this.getDaysInMonth(this.date.getMonth());
	days += this.countdown.getDate() - 1;

	// How many hours
	var hours = this.countdown.getHours();

	// return some hyphens
	if (hours < 0) {
		return "-- -- --";
	}

	// How many minutes, if less then ten, precede with a 0
	var minutes = this.countdown.getMinutes();
	//if (minutes < 10) minutes = "0" + minutes;

	// How many seconds, if less then ten, precede with a 0
	var seconds = this.countdown.getSeconds();
	//if (seconds < 10) seconds = "0" + seconds;
	
	// Is it day or days?
	var dayDays = (days != 1) ? "Days" : "Day";

	if (days == 0) {
		return "Only " + hours + " hours, " + minutes + " mins, " +  seconds + " secs to go!";
	}
	
	var rtnString = days + " Days, " + hours + " Hours, " + minutes + " Minutes and " + seconds + " Secs";

	return (rtnString);
}

Countdown.prototype.update = function() {
	// Update the display to show the current countdown amount
	
	// If the elements been drawn
	if (this.ele) {
		this.ele.innerHTML = this.getOuputDate();
	}
}