//--------------------------------
// Easter/Christmas Countdown Script!
// Written By:  Dean
//--------------------------------

function CDown(o, d)
{
	if (!document.getElementById || !document.getElementById(o))
	{
		return;
	}

	this.obj   = document.getElementById(o);
	this.time  = new Date();
	this.date  = new Date(d);
	this.there = false;

	this.execute();
}

CDown.prototype.execute = function()
{
	var o = this;
	this.time.setSeconds(this.time.getSeconds()+1);

	setTimeout(function(){o.execute()}, 1000);
}

CDown.prototype.display = function(b, f)
{
	this.base   = b;
	this.format = f;

	this.show();
}

CDown.prototype.show = function()
{
	var o = this;
	var x = (this.date-this.time)/1000;

	if (x < 0)
	{
		this.there = true;
		this.obj.innerHTML = this.format();

		return;
	}

	var m  =60;
	var h  =60*60;
	var d  =60*60*24;
	var dd =Math.floor(x/d);
	var hh =Math.floor((x-dd*d)/h);
	var mm =Math.floor((x-dd*d-hh*h)/m);
	var ss =Math.floor((x-dd*d-hh*h-mm*m));

	if (this.base == 'hours')
	{
		hh = dd*24+hh;
		dd = 'n/a';
	}
	else if (this.base == 'minutes')
	{
		mm = dd*24*60+hh*60+mm;
		dd = hh = 'n/a';
	}
	else if (this.base == 'seconds')
	{
		ss = x;
		dd = hh = mm = 'n/a';
	}

	this.obj.innerHTML = this.format(dd, hh, mm, ss);
	setTimeout(function(){o.show()}, 1000);
}

function show_easter()
{
	if (this.there == false)
	{
		var s = 'Only '+arguments[0]+' days, '+arguments[1]+' hours, '+arguments[2]+' minutes, '+arguments[3]+' seconds left until Christmas!';
	}
	else
	{
		var s = 'Christmas has arrived! (Or been passed by!)';
	}

	return s;
}