	/*	------------------------------------
	 	countdown to amageddon...
		------------------------------------
	 	author: matthew knight
	 			webponce@hotmail.com
		date:	jan 18, 2000
		ver: 	1.6
		------------------------------------
		
		i've made the script a little easier to change, bringing
		all the variables to the top should you need to change anything	
		
		targetDay = the day (ie. march 22nd, targetDay=22)
		targetMonth = the month (ie jan targetMonth=0, dec targetMonth=11)
		targetHour = the hour (ie. 5pm, targetHour=17)
		targetMin = the minutes (ie. 5.05pm, targetMin=5)
		targetSec = leave this at zero.. or do you need to be that fussy? :)
		
		then 'targetMsg' is the message displayed at target time
		
		and 'redirDelay' is how long in seconds before the redirect page is
		called upon
		
		just below that is "redirect", which is the URL of the page
		where the clock should go to once the target has been hit..
		
		and below that is the nwd array, which lists all of the none working
		days from now until the target... ie, 12.0 is jan12th, 11.1 is feb11th
		to add extra non-working days (for whatever reason...), follow the 
		format of the existing days off..
		
		leadingZeros = true will show a 0 in front of single digit minutes 
		and seconds, should you want em..
		
		messages is the list of scrolly messages that will appear, in order
		as in the list... at the moment.. a different message appears every minute..
		but if you want, we can have the same message appearing in one day, and
		then a different message the following day, or a message an hour, or
		whatever.. infinatly customisable..
		
		
	*/

	
	// variables:

		
		function findShow() {
	  	var datenow = new Date();
			showtimes = new Array(new Date('February 29, 2008 19:30:00'), 
								  new Date('March 1, 2008 14:30:00'), 
								  new Date('March 1, 2008 19:30:00'), 
								  new Date('March 2, 2008 13:00:00'), 
								  new Date('March 2, 2008 17:30:00'), 
								  new Date('March 5, 2008 19:30:00'), 
								  new Date('March 6, 2008 19:30:00'), 
								  new Date('March 7, 2008 19:30:00'), 
								  new Date('March 8, 2008 14:30:00'), 
								  new Date('March 8, 2008 19:30:00'),
								  new Date('March 9, 2008 13:00:00'),
                                  new Date('March 9, 2008 17:30:00'), 
								  new Date('March 12, 2008 19:30:00'), 
								  new Date('March 13, 2008 19:30:00'), 
								  new Date('March 14, 2008 19:30:00'), 
								  new Date('March 15, 2008 14:30:00'), 
								  new Date('March 15, 2008 19:30:00'),
								  new Date('March 16, 2008 13:00:00'),
								  new Date('March 16, 2008 17:30:00'));

			for (i = 0; i<showtimes.length;i++) {
				if (datenow < showtimes[i]) {
					targetDay = showtimes[i].getDate();
					targetHour = showtimes[i].getHours();
					targetMin = showtimes[i].getMinutes();
					targetMonth = showtimes[i].getMonth();
					targetYear = showtimes[i].getYear();
					break;
				}
			}		
		}
		findShow();

		targetSec = 0
		
		targetMsg = "Show time"
		redirDelay = 0
		redirect = 'whatever.html'
		
		leadingZeros = true;
		
		messages = new Array(
					'another minute gone : not long now', 'nearly there', 'getting there slowly', 'need... more... time...'
					)
		
		mesg_every_n_mins = 1;
		
		nwd = new Array();

	

	/*------------------------ you can touch below here.. but on your head be it ------------------------*/
	
	
	updateDelay = 100;
	scrollFlag=false;
	msg_hpos=0;
	msg_num=-1;
	every_nmins = 0;
	
	function initMsg() {
		if (every_nmins==0) {
			msg_num++;
			if (msg_num>=messages.length) {
				msg_num=0;
			}
			msg_msg = messages[msg_num];
				
			msg_hpos=0
			msg_width=40;
			msg_delay=150
			msg_padstr = ''
		
			for(s=0;s<msg_width;s++) {
				msg_padstr = msg_padstr + ' ';
			}
			msg_msg = msg_padstr + msg_msg + msg_padstr;
			scrolltext();
			every_nmins = mesg_every_n_mins-1;
		} else {
			every_nmins--;
		}
		
	}
	
	
	function scrolltext() {
		
//			if(msg_hpos<msg_msg.length) {
//				document.getElementById('msgscroll').innerHTML = msg_msg.substr(msg_hpos,msg_width);
//				msg_hpos++;
//				setTimeout("scrolltext()",msg_delay);
//			} else {
//				msg_hpos=0
//			}
		
	}
	
	
	function lazyassNonWorkingDays() {
		nwds=0;
		for(thisNWD=0;thisNWD<nwd.length;thisNWD++) {
			
			dbits = nwd[thisNWD].split('.');
			
			thisParticularWkend = makeDateObj(dbits[1],dbits[0]);
			if (thisParticularWkend>now && thisParticularWkend<then) {
				nwds++;
			}
			
		}
		return nwds;
	}
	
	function init() {
		kountdown();
	}
	
	function kountdown() {
		now = new Date();
		then = new Date();

		then.setDate(targetDay);
		then.setMonth(targetMonth);
		then.setYear(targetYear);
		then.setSeconds(targetSec);
		then.setHours(targetHour);
		then.setMinutes(targetMin);
		
		dif = then - now;

		if (dif>0) {

			days = '' + dif / 1000 / 60 / 60 / 24
			dayBits = days.split('.');
			days = dayBits[0];
			
			
			//days = parseInt(days - lazyassNonWorkingDays());
			
			hours = '' + (dif - (days*24*60*60*1000)) / 1000 / 60 / 60;
			hourbits = hours.split('.');
	
			hours = hourbits[0];
//			hours = parseInt(hours - (lazyassNonWorkingDays()*24));
			
			mins = '' + (dif - (days*24*60*60*1000) - (hours*60*60*1000)) / 1000 / 60;
			minBits = mins.split('.');
			mins = minBits[0];
//			mins = parseInt(mins - (lazyassNonWorkingDays()*24*60));
			
			secs = '' + (dif - (days*24*60*60*1000) - (hours*60*60*1000) - (mins*60*1000)) / 1000
//			secs = parseInt(secs - (lazyassNonWorkingDays()*24*60*60));
	
			
			// formatting options
			if (days<=0) {
				swapClass('klok_dd','hidden');
			} else {
				swapClass('klok_dd','large');
			}
			
			//cleardowns..

			daystr = 'day';
			if (days>1 || days==0) {
				daystr = daystr + 's';
			}
			document.getElementById('klok_dd').innerHTML = (days + ' '+daystr+' ');
			if(hours>0) {
				document.getElementById('klok_hh').innerHTML = (hours + ' hours ');
			} else {
				document.getElementById('klok_hh').innerHTML = '';
			}
			
			if(mins>0) {
				document.getElementById('klok_mm').innerHTML = (leadingZero(mins) + ' minutes ');
			} else {
				document.getElementById('klok_mm').innerHTML = '';
			}
			if(secs>=0) {
				document.getElementById('klok_ss').innerHTML = (leadingZero(secs) + ' seconds!');
			}
			
			if (secs==0 && (mins!=0 && hours!=0 && days!=0)) {
					if(msg_hpos==0) {
						initMsg();
					}
				
			}
			
			setTimeout("kountdown()",updateDelay);
		} else {
			document.getElementById('klok_ss').innerHTML = '';
//			klok_done.innerHTML = targetMsg
			setTimeout("gonext()",(redirDelay*1000));
		}
		
	}

	function  swapClass(itmId,clName){
		theClass = document.getElementById(itmId);
		theClassName = theClass.className;
		theClass.className = clName;
	}
			
	
	function leadingZero(str) {
		if (leadingZeros) {
			str = '' + str;
			if(str.length==1) {
				str = '0' + str;
			}
			return str;
		}
	}
	
	
	function gonext() {
		findShow();
		init();
//		document.location.href = redirect;
	}
	