var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var counterTimeout;

function countdown(yr,m,d,minute,sec) {
	theyear = yr;
	themonth = m;
	theday = d;
	theminute = minute;
	thesecond = sec;

	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 + " " + minute + ":" + sec;
	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 == 0) || dsec < 0) {
		$('#countdown_01').text('Nu kommer tåget!');
		clearInterval(counterTimeout);
		return;
	}
	else {
		var myOutput = dday + " Dagar, " + dhour + "h, " + dmin + "m, " + dsec + "s";
		$('#countdown_01').text(myOutput);
	}
}

$(document).ready(function() {
	countdown(2010,9,25,00,00);
	counterTimeout = setInterval("countdown(2010,9,25,00,00)",1000);
});

