(function($) {
	var objElement, objDate, strEvent, intRemain;

	function startCount() {
		objElement = this;
		strEvent = new String(arguments[0]);
		objDate = new Date(arguments[1], arguments[2] - 1, arguments[3], arguments[4], arguments[5], arguments[6]);
		setInterval(updateCount, 1000);

	}

	function updateCount() {
		var intDays = 0, intHours = 0, intMins = 0, intSecs = 0, strCountdown = new String;
		intRemain = Math.floor((objDate.getTime() - (new Date()).getTime()) / 1000);

		if (intRemain < 0) {
			return $(objElement).text(strEvent.toUpperCase() + " HAS LAUNCHED!");

		}

		intDays = Math.floor(intRemain / 86400);
		intRemain = intRemain % 86400;
		intHours = Math.floor(intRemain / 3600);
		intRemain = intRemain % 3600;
		intMins = Math.floor(intRemain / 60);
		intRemain = intRemain % 60;
		intSecs = Math.floor(intRemain);

		if (intDays != 0) {
			strDays = ((intDays < 10) ? ("0" + intDays) : intDays);
			strCountdown += (strDays + ":");

		} else {
			strCountdown += "00:";

		}

		if (intHours != 0) {
			strHours = ((intHours < 10) ? ("0" + intHours) : intHours);
			strCountdown += (strHours + ":");

		} else {
			strCountdown += "00:";

		}

		if (intMins != 0) {
			strMins = ((intMins < 10) ? ("0" + intMins) : intMins);
			strCountdown += (strMins + ":");

		} else {
			strCountdown += "00:";

		}

		if (intSecs != 0) {
			strSecs = ((intSecs < 10) ? ("0" + intSecs) : intSecs);
			strCountdown += (strSecs);

		} else {
			strCountdown += "00";

		}

		return $(objElement).text(strCountdown).addClass("Counter");

	}

	$.fn.extend({

		setCountdown: function() {
			strArgs = arguments;

			$(this).each(function() {
				startCount.apply($(this), strArgs);

			});

		}

	});

})(jQuery);
