function timer(_holder) {
	var month = getElementsByClass('month',_holder,'li');//  '*' for next month, '0' for this month or 1 through 12 for the month 
	var day = getElementsByClass('day',_holder,'li');       //  Offset for day of month day or + day  
	var hour = getElementsByClass('hour',_holder,'li'); //  0 through 23 for the hours of the day
	var min = getElementsByClass('min',_holder,'li'); //  min
	var tz = getElementsByClass('tz',_holder,'li');         //  Offset for your timezone in hours from UTC
	var lab = 'timer';    //  The id of the page entry where the timezone countdown is to show
	var _timer = false;
	
	month = month[0].innerHTML;
	day = day[0].innerHTML;
	hour = hour[0].innerHTML;
	min = min[0].innerHTML;
	tz = tz[0].innerHTML;
	
	displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);

	function setTZCountDown(month,day,hour,tz) {
		var toDate = new Date();
		if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
		else if (month > 0) { 
			if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
			toDate.setMonth(month-1);
		}
		toDate.setDate(day);
		toDate.setHours(hour);
		toDate.setMinutes(min-(tz*120)); // ehem. 60
		toDate.setSeconds(0);
		var fromDate = new Date();
		fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
		var diffDate = new Date(0);
		diffDate.setMilliseconds(toDate - fromDate);
		return Math.floor(diffDate.valueOf()/1000);
	}
	function displayTZCountDown(countdown) {
		if (countdown < 0) {
			clearTimeout(_timer);
			_holder.innerHTML = "<li><strong>Zeit ist abgelaufen</strong></li>";
		}
		else {
			var secs = countdown % 60; 
			if (secs < 10) secs = '0'+secs;
			var countdown1 = (countdown - secs) / 60;
			var mins = countdown1 % 60; 
			if (mins < 10) mins = '0'+mins;
			countdown1 = (countdown1 - mins) / 60;
			var hours = countdown1 % 24;
			if (hours == 0) hours = '00';
			else if (hours < 10) hours = '0'+hours;

			var days = (countdown1 - hours) / 24;
			if (days == 0) days = '00';
			else if (days < 10) days = '0'+days;
   if ( days >= 30 ) days = days-30; 
			
			//_holder.innerHTML = "<li>"+days+"</li><li>"+hours+"</li><li>"+mins+"</li><li>"+secs+"</li>";
			_holder.innerHTML = ' \
				<li>\
					<strong>'+days+'</strong>\
					<span>Tage</span>\
				</li>\
				<li>\
					<strong>'+hours+'</strong>\
					<span>Std</span>\
				</li>\
				<li>\
					<strong>'+mins+'</strong>\
					<span>Min</span>\
				</li>\
				<li>\
					<strong>'+secs+'</strong>\
					<span>Sek</span>\
				</li>';
			_timer = setTimeout(function(){displayTZCountDown(countdown-1)},1000);
		}
	}
}
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
function initTimer(){
	var _uls = document.getElementsByTagName('ul');
	for (var i=0; i<_uls.length; i++) {
		if (_uls[i].className.indexOf('timer') != -1) {
			timer(_uls[i]);
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", initTimer, false);
else if (window.attachEvent)
	window.attachEvent("onload", initTimer);


