var clockTimeOut;
$(document).ready(function(){
	var i=0;
	var countdownBox = $('#countdownbox');	
	$('.countdown').each(function(){
		$(this).find(".date").hide();
		$(this).click(function(){
				clearTimeout(clockTimeOut);
				$(countdownBox).find('.location').html($(this).find('.location').html());
				$(countdownBox).find('.date').html($(this).find('.date').html());
				var countdownDate = $(this).find('.date').html().split('/');
				countdown(countdownDate[0],countdownDate[1],'20'+countdownDate[2]);
				$(countdownBox).find('.date').html("graduation date: "+$(countdownBox).find('.date').html());

		});
	});
	$('.countdown').trigger("click");
	
});

/*window.addEvent('domready',function() {
									
		
		$$('.countdown').getElement('.date').setStyle('display','none');

		$$('.countdown').addEvent('click',function() {
			clearTimeout(clockTimeOut);
			countdownBox.getElement('.location').innerHTML = this.getElement('.location').innerHTML;
			countdownBox.getElement('.date').innerHTML = this.getElement('.date').innerHTML;
			// make the countdown timer
			var countdownDate = this.getElement('.date').innerHTML.split('/');
			countdown(countdownDate[0],countdownDate[1],'20'+countdownDate[2]);
			countdownBox.find('.date').html("graduation date: "+countdownBox.getElement('.date').html());



			
		});
		$$('.countdown')[0].fireEvent('click');
});*/


/*
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
*/



function countdown(d,m,yr){
var countdownBox = $('#countdownbox');
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
theyear=yr;themonth=m;theday=d;
var today=new Date();
var todayy=today.getYear();
if (todayy < 1000)
todayy+=1900;
var todaym=today.getMonth();
var todayd=today.getDate();
var todayh=today.getHours();
var todaymin=today.getMinutes();
var todaysec=today.getSeconds();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
futurestring=montharray[m-1]+" "+d+", "+yr;
dd=Date.parse(futurestring)-Date.parse(todaystring);
dday=Math.floor(dd/(60*60*1000*24)*1);
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1){
$(countdownBox).find('.thecountdown').html('<span class="number">event has already happened!</span>');
return
}
else
$(countdownBox).find('.thecountdown').html("<span class=\"number\">"+checkTime(dday)+ ":"+checkTime(dhour)+":"+checkTime(dmin)+":"+checkTime(dsec)+"</span>days to graduation!");
clockTimeOut = setTimeout("countdown(theyear,themonth,theday)",1000);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
