var current_banner, total_banners;

function event_counter()
{
	$('#right-col > ul > li.evenementen > ul').each(function() {
		
		var days = parseInt( $(this).find('.number:eq(0)').attr('value') ),
			hours = parseInt( $(this).find('.number:eq(1)').attr('value') ),
			minutes = parseInt( $(this).find('.number:eq(2)').attr('value') ),
			seconds = parseInt( $(this).find('.number:eq(3)').attr('value') );
		
		if ((seconds - 1) >= 0) {
			seconds = seconds - 1;
		} else {
			seconds = 59;
			minutes = minutes - 1;
		}
		
		if (minutes < 0) {
			minutes = 59;
			hours = hours - 1;
		}
		
		if (hours < 0) {
			hours = 23;
			days = days - 1;
		}
		
		if (days < 0) {
			days = 0;
		}
		
		$(this).find('.number:eq(0)').attr('value', days);
		$(this).find('.number:eq(1)').attr('value', hours);
		$(this).find('.number:eq(2)').attr('value', minutes);
		$(this).find('.number:eq(3)').attr('value', seconds);
		
		days = days < 10 ? '0' + days : days;
		hours = hours < 10 ? '0' + hours : hours;
		minutes = minutes < 10 ? '0' + minutes : minutes;
		seconds = seconds < 10 ? '0' + seconds : seconds;
		
		$(this).find('.number:eq(0)').text(days);
		$(this).find('.number:eq(1)').text(hours);
		$(this).find('.number:eq(2)').text(minutes);
		$(this).find('.number:eq(3)').text(seconds);
		
	});
}

$(function() {
	
	$('.activate_lightbox').click(function() {
		
		var lightbox_id = $(this).attr('lightbox');
		
		$('#' + lightbox_id + ' a').lightBox({fixedNavigation:true});
		$('#' + lightbox_id + ' a:first').click();
		
		return false;
	});
	
	$('.validate-form').each(function() {
		$(this).validate();
	});
	
	$('form input:text').addClass('text');
	$('form input:file').addClass('text');
	
	current_banner = 0;
	total_banners = $('#header-carousel > ul > li').length - 1;
	
	$('#menu > ul > li:first').addClass('first');
	$('#menu > ul > li:lt(5)').addClass('bold');
	
	$('#left-btn .previous').click(function() {
		move_banner('left');
	});
	
	$('#right-btn .previous').click(function() {
		move_banner('right');
	});
	
	setInterval("move_banner('right')", 5000);
	setInterval('event_counter()', 1000);
	
	//$('.moederlist > li:gt(0)').hide();
	$('.moeder .left-bottom-arrow').click(function() {
		
	});
	
	$('.moeder .right-bottom-arrow').click(function() {
		
	});
	
});

function move_banner(direction)
{
	var banner_animate_from, banner_animate_to;
	
	banner_animate_from = current_banner;
	
	switch (direction)
	{
		case 'left':
			
			if ((current_banner - 1) > 0) {
				banner_animate_to = current_banner - 1;
			} else {
				banner_animate_to = total_banners;
			}
			
			break;
		
		case 'right':
			
			if ((current_banner + 1) > total_banners) {
				banner_animate_to = 0;
			} else {
				banner_animate_to = current_banner + 1;
			}
			
			break;
	}
	
	$('#header-carousel > ul > li:eq('+ banner_animate_from +')').fadeOut(1000);
	$('#header-carousel > ul > li:eq('+ banner_animate_to +')').fadeIn(500);
	
	current_banner = banner_animate_to;
}
