
/* -- Fancybox -- */

$('.fancybox, .lightbox').fancybox({
	overlayOpacity : 0.7
});

/* -- Input hints -- */

$('input[title]').inputHint({});

/* -- Countdown (homepage) -- */

var liftoffTime = new Date();
liftoffTime.setDate(1);
liftoffTime.setMonth(1);
liftoffTime.setYear(2015);
liftoffTime.setHours(0);
liftoffTime.setMinutes(0);
liftoffTime.setSeconds(0);

$('#footer').append('<div id="countdown"><div id="digits"></div></div>');
$('#digits').countdown({
	until: liftoffTime, 
	format: 'dHMS', 
	compact: true,
	onTick : function(periods) {
		$('#digits').html(periods[3] + 'D<br />' + zeropadding(periods[4]) + ':' + zeropadding(periods[5]) + ':' + zeropadding(periods[6]));
	}
});

function zeropadding(n) {
	if(n < 10) {
		return '0' + n;
	}
	return n;
}

/* -- Calendar interface -- */

$('.calendar-embedded .month-previous, .calendar-embedded .month-next').live('click', function() {
	// Remember selection
	var $t = $(this);
	
	// Split href up into an array:
	var elm = $(this).attr('href').split('/');
	
	// Extract month + year
	var m = elm[elm.length - 2];
	var y = elm[elm.length - 1];
	
	// Compose new URL:
	var u = '';
	for(var i = 0; i < elm.length - 2; i ++) {
		u += (elm[i] == 'kalender' ? 'kalender/calendar-ajax/' : elm[i] + '/');
	}
	
	// AJAX Request:
	$.ajax({
		url : u,
		data : {
			year  : y,
			month : m
		},
		dataType : 'html',
		success : function(data) {
			$t.parent().parent().html(data);
		}
	});
	
	// Override default behavior
	return false;
});

/* -- Cycle logos -- */

var logoCursor = 0;
var logoInterval = 12000;
$('#logos a').each(function(i) {
	if(i != logoCursor) {
		$(this).hide();
	}
});

function showAnimationFrameInLogos(n, prevN) {
	if(n >= $('#logos a').length) {
		n = 0;
	}
	$('#logos a:eq('+ prevN +')').fadeOut(200, function() {
		$('#logos a:eq('+ n +')').slideDown(250, function() {
			setTimeout('showAnimationFrameInLogos(' + (n + 1) + ', '+ n +')', logoInterval);
		});
	});
}

// We do not active the animation of logos for now, since there is only one 
// logo remaining in the page view:
// setTimeout('showAnimationFrameInLogos(1, 0)', logoInterval);

/* -- Video -- */

$('#scoren-voor-2015-video').html('').flash({
	src: jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/player.swf',
	width: 640,
	height: 360,
	flashvars : {
		videoPath : jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/promo.flv',
		playerSkin : jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/ClearOverPlaySeekMute.swf'
	}
});

$('#cultuurcentrum-brugge').html('').flash({
	src: jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/player.swf',
	width: 320,
	height: 180,
	flashvars : {
		videoPath : jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/CCBruggeScorenvoor2015.flv',
		playerSkin : jQueryBaseHrefWithoutPrefix + '/application/modules/text/resources/video/ClearOverPlaySeekMute.swf'
	}
});

/* -- Ik scoor mee (homepage) -- */

// Animate the number of participants into view (count from zero to current number)
$('a#participant-counter span').remove();
var numberOfParticipants = parseInt($('a#participant-counter').text());
function showAnimationFrameInNumberOfParticipants(n) {
	if(n <= numberOfParticipants) {
		$('a#participant-counter').html(n);
		setTimeout('showAnimationFrameInNumberOfParticipants(' + (n + 1) + ')', 50);
	}
}
if(numberOfParticipants) {
	showAnimationFrameInNumberOfParticipants(0);
}




