var TICKER = 
{
	options: {
		'default':{
			ALARM_MIN: 0,//X minutes prior to nation war BLINK for 40 minutes before the WAR!!!
			END_HOUR: 22, //9PM
			END_MIN: 30,
			END_SEC: 0,
			START_HOUR: 21, //9PM
			START_MIN: 0,
			START_SEC: 0,
			INGAME_MSG: "<span  style='color:green'>HAS STARTED!</span>",
			WARNING_SIZE: 15,
			START_MSG: "<span  style='color:green'>STARTED!</span>",
			UNITS: 3,
			msgID: "tickerMSG"
		}
	},
	addOption: function(o,obj){//any non-defined values are copied over from default.
		this.options[o] = obj;
		for (var i in this.options['default']){
			if (this.options[o][i.toString()] == undefined) {this.options[o][i.toString()] = this.options['default'][i.toString()];} 
		}
	},
	printMSG: function(o,msg){
		document.getElementById(this.options[o].msgID).innerHTML = msg;},	
	countDown: function(o){
		if (typeof(this.options[o]) != "object") {o = "default";}//if o is wrong, set options[o] to "default".
		var option = this.options[o];//simplifing.. because we call this bunch of times
		var dnow = new Date();//CURRENT DATE!
		var currHour = dnow.getHours();                                                                                         
		var currMin = dnow.getMinutes();
		var currSec = dnow.getSeconds();
		var currMill = dnow.getMilliseconds() % 100;
		
		var targetDate;
		
		var diffHour = -1;
		var diffMin = -1;
		var diffSec = -1;
		var diffMill = -1;
		
		var time = 100; //used for calling this function time milliseconds later.. used in last line of this function
		//1. ENDTIME <-> (STARTTIME - ALARM_MIN) : just tick away..
		if(currHour >= option.END_HOUR && currHour < 23 && currMin > 0 && currMin > option.END_MIN)
		{	targetDate = new Date(dnow.getFullYear(), dnow.getMonth(), dnow.getDate()+1, option.START_HOUR, option.START_MIN, option.START_SEC);}
		else 
		{	targetDate = new Date(dnow.getFullYear(), dnow.getMonth(), dnow.getDate(), option.START_HOUR, option.START_MIN, option.START_SEC); }
		
		var diffDate = targetDate.getTime() - dnow.getTime();
		diffHour = Math.floor((diffDate / (1000*60*60))%24);
		diffMin = Math.floor((diffDate / (1000*60))%60);
		diffSec = Math.floor((diffDate / 1000)%60);
		diffMill = Math.floor((diffDate % 1000) / 11);
		var diffTime = 
		    ((diffHour < 10) ? "0" : "") + diffHour + ":" 
		    + ((diffMin < 10) ? "0" : "") + diffMin + ":" 
		    + ((diffSec < 10) ? "0" : "") + diffSec + "."
		    + ((diffMill < 10) ? "0" :"") + diffMill;
		
		    switch(option.UNITS){//filter out display by UNITS - hr:min:sec:millisec, AND reduce resource usage by setting revoke interval(time) via UNITS
		    case 3:
			    diffTime = diffTime.substr(0,diffTime.length-3);
			    time = 1000;//1 seconds
			    break;
		    case 2:
			    diffTime = diffTime.substr(0,diffTime.length-6);
			    time = 60000;//1 minute
			    break;
		    case 1:
			    diffTime = diffTime.substr(0,diffTime.length-9);
			    break;
		    default:
			    break;
		    }
		
		if (diffDate < option.ALARM_MIN * 1000 * 60 && diffDate > 0)//if difference of time is within alarm range!! BLINK BLINK !!
		{	
			time = 100;
			if (dnow.getMilliseconds() % 500 > 250) {document.getElementById(option.msgID).style.fontSize = (option.WARNING_SIZE+1).toString() + 'px';}
				else {document.getElementById(option.msgID).style.fontSize = (option.WARNING_SIZE).toString() + 'px';}
		}
		else if (diffDate < 0)
		{	diffTime = option.START_MSG;}
		
		if (option.END_HOUR < option.START_HOUR) {diffTime = "INVALID END_HOUR";}
		else if (option.END_HOUR == option.START_HOUR && option.END_MIN <= option.START_MIN) {diffTime = "INVALID END_MIN";}
		
		this.printMSG(o, diffTime);
		
		setTimeout("TICKER.countDown('default')",time);
	}
};

