/* 
blokken update:
set the correct 'blokken' at setCurrentMonth()
change links and positions of li's in header.inc + colors (background and text)
adjust dayslength in blokken_itemList
*/

/*global window*/
/*global $*/
/*global blokken_itemList*/
/*global language*/
/*global loadVideos*/
/*global sixRegistrationFormSubmit*/
/*global swfobject*/
/*global monthNames*/

function isDefined(val){
	if(val === '' || val === null || typeof val == 'undefined') { return false; }
	else { return true; }
}

var monthsATimeout,
	jsonUrl = 'https://6.sixmo.com/eventmanager/register',
	act,
	focusField,
	leftNavMonthSpecificContent = -1,
	teller = 0,
	ani99; var ani99_is_on = false,
	audio = [],
	vrijePlaatsen = [],
	month,
	todaysMonth = new Date(),
	loc,
	args,
	m=99,
	currentMaandVlak,
	currentMaandVlakSet = false,
	str = document.location.href.split('#')[1],
	i, j, k, l,
	blokkenOrder = [4,5,6,0,1,2,3],
	targetAttr,
	targetCheck;
	

var IE = navigator.userAgent.indexOf("MSIE")!=-1;
var favicon = {
	change: function(iconURL) {
		var __IFrame = !window.__IFrame;
		if (arguments.length == 2) { document.title = arguments[1]; }
		this.addLink(iconURL, "icon");
		this.addLink(iconURL, "shortcut icon");
		if(!IE) {
			if (!__IFrame) {
				__IFrame = document.createElement('iframe');
				var s = __IFrame.style;
				s.height = s.width = s.left = s.top = s.border = 0;
				s.position = 'absolute';
				s.visibility = 'hidden';
				document.body.appendChild(__IFrame);
			}
			__IFrame.src = 'about:blank';
		}
	},
	addLink: function(iconURL, relValue) {
		var link = document.createElement("link");
		link.type = "image/x-icon";
		link.rel = relValue;
		link.href = iconURL;
		this.removeLinkIfExists(relValue);
		this.docHead.appendChild(link);
	},
	removeLinkIfExists: function(relValue) {
		var links = this.docHead.getElementsByTagName("link");
		for (var i=0; i<links.length; i++) {
			var link = links[i];
			if (link.type == "image/x-icon" && link.rel == relValue) {
				this.docHead.removeChild(link);
				return;
			}
		}
	},
	docHead: document.getElementsByTagName("head")[0]
};

if(isDefined(str)) { loc = '#'+ str; }
function parseQueryString() {
	if(isDefined(str)) {
		var args = {};
		var fields = str.split('&');
		for (var f = 0; f < fields.length; f++) {
			var field = fields[f].split('=');
			field[1] = isDefined(field[1]) ? field[1] : '';
			args[decodeURIComponent(field[0].replace(/\+/g, ' '))] = decodeURIComponent(field[1].replace(/\+/g, ' '));
		}
		return args;
	}
}
args = parseQueryString();
for(var arg in args) { if(arg=='m'){ currentMaandVlak = parseInt(args[arg],10); currentMaandVlakSet = true; } }

function arrowPosition(index){
	var totalWidth = 0;
	var firstLeftPos;
	$('#monthsOl li[index='+ index +']').each(function(i){
		if(i === 0) { firstLeftPos = $(this).position().left; }
		totalWidth += $(this).width();
	});
	var arrowPositionLeft = firstLeftPos + totalWidth/2 + 9;
	return parseInt(arrowPositionLeft, 10);
}

var ulImageAnimation_itemList =   [ {url: '/media/img/img_02-2011-03.jpg'}, {url: '/media/img/img_02-2011-02.jpg'} ],
	ulImageAnimation_itemList_0 = [ {url: '/media/img/img_00-01.jpg'}, {url: '/media/img/img_00-02.jpg'}, {url: '/media/img/img_00-03.jpg'}, {url: '/media/img/img_00-04.jpg'}, {url: '/media/img/img_00-05.jpg'}, {url: '/media/img/img_00-06.jpg'}, {url: '/media/img/img_00-07.jpg'}, {url: '/media/img/img_00-08.jpg'}, {url: '/media/img/img_00-09.jpg'} ],
	ulImageAnimation_itemList_1 = [ {url: '/media/img/img_01_2011-01.jpg'}, {url: '/media/img/img_03-02.jpg'}, {url: '/media/img/img_00-03.jpg'}, {url: '/media/img/img_00-05.jpg'} ],
	ulImageAnimation_itemList_2 = [ {url: '/media/img/img_02-2011-02.jpg'}, {url: '/media/img/img_02-2011-01.jpg'}, {url: '/media/img/img_02-2011-03.jpg'} ],
	ulImageAnimation_itemList_3 = [ {url: '/media/img/img_03-01.jpg'}, {url: '/media/img/img_03-02.jpg'}, {url: '/media/img/img_03-03.jpg'}, {url: '/media/img/img_03-04.jpg'} ],
	ulImageAnimation_itemList_4 = [ {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-01.jpg'}, {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-02.jpg'}, {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-03.jpg'}, {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-04.jpg'}, {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-05.jpg'}, {url: '/media/img/beeld/tentoonstellingen/jodendom-een_wereld_vol_verhalen/img_04-2011-06.jpg'} ],
	ulImageAnimation_itemList_5 = [ {url: '/media/img/img_05_2011-02.jpg'}, {url: '/media/img/img_05_2011-03.jpg'}, {url: '/media/img/img_05_2011-04.jpg'}, {url: '/media/img/img_05-03.jpg'}, {url: '/media/img/img_05-04.jpg'} ],
	ulImageAnimation_itemList_6 = [ {url: '/media/img/img_06-01.jpg'}, {url: '/media/img/img_06-02.jpg'}, {url: '/media/img/img_06-03.jpg'}, {url: '/media/img/img_06-04.jpg'}, {url: '/media/img/img_06-05.jpg'}, {url: '/media/img/img_06-06.jpg'}, {url: '/media/img/img_06-07.jpg'} ];
	
var blokken_itemList_general = [
		{ulImageAnimation: ulImageAnimation_itemList_0, ulAnimation: 'de_kerk_van_amsterdam', color: '#749f18', backgroundColor: '#89ba17', arrowPosition: arrowPosition(1), favicon: '/media/ico/0.ico', dateStart: new Date(2012, 6, 1), dateEnd: new Date(2012, 7, 1)},
		{ulImageAnimation: ulImageAnimation_itemList_1, ulAnimation: 'de_kerkmeester', color: '#93117e', backgroundColor: '#93117e', arrowPosition: arrowPosition(2), favicon: '/media/ico/1.ico', dateStart: new Date(2012, 7, 1), dateEnd: new Date(2012, 9, 1)},
		{ulImageAnimation: ulImageAnimation_itemList_2, ulAnimation: 'het_meesterwerk', color: '#00a5e6', backgroundColor: '#00a5e6', arrowPosition: arrowPosition(3), favicon: '/media/ico/2.ico', dateStart: new Date(2012, 9, 1), dateEnd: new Date(2012, 10, 1)},
		{ulImageAnimation: ulImageAnimation_itemList_3, ulAnimation: 'gesloten', color: '#6c6c7a', backgroundColor: '#6c6c7a', arrowPosition: arrowPosition(4), favicon: '/media/ico/3.ico', dateStart: new Date(2012, 10, 1), dateEnd: new Date(2012, 11, 1)},
		{ulImageAnimation: ulImageAnimation_itemList_4, ulAnimation: 'tentoonstellingen', color: '#826464', backgroundColor: '#998d87', arrowPosition: arrowPosition(5), favicon: '/media/ico/4.ico', dateStart: new Date(2011, 11, 1), dateEnd: new Date(2012, 3, 15)},
		{ulImageAnimation: ulImageAnimation_itemList_5, ulAnimation: 'herdenken_en_vieren', color: '#b7a400', backgroundColor: '#dcc900', arrowPosition: arrowPosition(6), favicon: '/media/ico/5.ico', dateStart: new Date(2012, 3, 16), dateEnd: new Date(2012, 5, 1)},
		{ulImageAnimation: ulImageAnimation_itemList_6, ulAnimation: 'de_religieuze_muziek', color: '#455ea4', backgroundColor: '#455ea4', arrowPosition: arrowPosition(7), favicon: '/media/ico/6.ico', dateStart: new Date(2012, 5, 1), dateEnd: new Date(2012, 6, 1)}
	];

// define preloadImages plugin
$.preloadImages = function(){ for(var i = 0; i<arguments.length; i++){ $('<img>').attr('src', arguments[i]); } };

todaysMonth = todaysMonth.getMonth();

function setCurrentMonth(){
	if(todaysMonth == 11 || todaysMonth === 0 || todaysMonth == 1 || todaysMonth == 2) { month = 4; /*december - maart*/ }
	else if(todaysMonth == 4 || todaysMonth == 3) { month = 5; /*april en mei*/ }
	else if(todaysMonth == 5) { month = 0; /*juni*/ }
	else if(todaysMonth == 6) { month = 0; /*juli*/ }
	else if(todaysMonth == 7) { month = 1; /*augustus*/ }
	else if(todaysMonth == 8) { month = 1; /*september*/ }
	else if(todaysMonth == 9) { month = 2; /*oktober*/ }
	else if(todaysMonth == 10) { month = 3; /*november*/ }
	else { month = 4; }
	return month;
}

var todaysMaandVlak = setCurrentMonth();
if(!currentMaandVlakSet){ currentMaandVlak = setCurrentMonth(); }
if(isNaN(currentMaandVlak)) { currentMaandVlak = 4; }

function startAni99(){
	ani99_is_on = true;
	$($('#ani99 img')[teller]).css('z-index',$($('#ani99 img')[teller]).css('z-index') + 7);
	if(teller < 6) { teller++; }
	else { teller = 0; }
	ani99 = setTimeout(startAni99, 3500);
}
function showMailOffice(){
	$('#mailOffice, #greyedout').show();
	$('#mailOfficeFirstname').focus();
}
function hideMailOffice(){ $('#greyedout, #mailOffice').hide(); }

function parseScript(_source){
	var source = _source;
	var scripts = [];
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);
		scripts.push(source.substring(s_e+1, e));
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	for(var i=0; i<scripts.length; i++) {
		try { eval(scripts[i]); }
		catch(ex) {}
	}
}

function contentLoaded(){
	$($('#content .item')[0]).css('border','none');
	$('#content a').each(function(){
		// only target internal links
		targetAttr = $(this).attr('target');
		targetCheck = true;
		if(isDefined(targetAttr) && targetAttr.length > 0 && targetAttr.indexOf('blank') != -1) { targetCheck = false; }
		
		if(targetCheck && isDefined($(this).attr('href'))){
			if($(this).attr('href').indexOf('?m=') == -1 && $(this).attr('href').indexOf('mailto:') == -1 && $(this).attr('href').indexOf('#') == -1){
				var currentHref = $(this).attr('href');
				var sep = '?';
				if(currentHref.indexOf('?') > -1) { sep = '&'; }
				$(this).attr('href','/'+ language +'/'+ currentHref.concat(sep +'m='+ currentMaandVlak).split('/'+ language +'/')[1]);
				$(this).bind('click',function(){
					$.address.value($(this).attr('href'));
					return false;
				});
			}
			if($(this).attr('href').indexOf('?m=') != -1){
				$(this).bind('click',function(){
					$.address.value($(this).attr('href'));
					return false;
				});
			}
		}
	});
	$('.bovenrand').each(function(){
		$(this).before($('<img src="/media/img/img_bovenrand.png" width="523" height="12" class="rand" />')).removeClass('bovenrand').addClass('bovenrandActive');
	});
	$('div.artwork').addClass('clearfix');
	$('div.artwork img, img.artwork').click(function(){ $(this).toggleClass('beeldGroot'); });
	loadVideos();
	$('#sixRegistrationForm').submit(sixRegistrationFormSubmit);
	$.each(audio, function(i){
		var params = { loop: 'false', menu: false, wmode: 'transparent' };
		swfobject.embedSWF('/media/swf/mp3player.swf', audio[i][0], '520', '20', '8.0.0', '/media/swf/expressInstall.swf', '', params, '');
		$('#'+ audio[i][0]).parent().append('<img src="/media/img/sp.png" id="'+ audio[i][0] +'Img" style="width: 520px; height: 20px; position: absolute; left: 0; top: -10px; z-index: 1000; cursor: pointer;" />');
	});
	$('img.pioniers').bind("contextmenu",function(e){ return false; });
	$('#content, #ajaxContent').show();
}
function loadContent(loc,parameter){
	$('#content').load(loc.replace('#','') +' #ajaxContent', null, function(html){
		if(isDefined(parameter) && parameter != 99) { favicon.change(blokken_itemList[parameter].favicon, html.substring(html.indexOf('<title>') + 7,html.indexOf('</title>'))); }
		parseScript(html);
		contentLoaded();
		if(parameter == 99) { $('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6').addClass('corpContent'); }
	});
}
function ulImageAnimation_getItemHTML(item,i){ return '<img src="' + item.url + '" height="285" />'; }
function ulImageAnimation_itemVisibleInCallback(carousel, item, i, state, evt){
	var idx = carousel.index(i, ulImageAnimation_itemList.length);
	carousel.add(i, ulImageAnimation_getItemHTML(ulImageAnimation_itemList[idx - 1],i));
}
function ulImageAnimation_itemVisibleOutCallback(carousel, item, i, state, evt){ carousel.remove(i); }
function startMaandVlakAnimation(maandVlak){
	var maandvlakAni = blokken_itemList[maandVlak].ulAnimation;
	if(maandVlak != currentMaandVlak){
		$('#'+ blokken_itemList[currentMaandVlak].ulAnimation +' div').stop();
		currentMaandVlak = maandVlak;
	}
	$('#'+ maandvlakAni +' div').css('left',0);
	var imgWidth = $('#'+ maandvlakAni +' div img').width();
	$('#'+ maandvlakAni +' div img').addClass('temp');
	$('#'+ maandvlakAni +' div').width($('#'+ maandvlakAni +' div').width() * 2).append($('#'+ maandvlakAni +' div img').clone().removeClass('temp'));
	$('#'+ maandvlakAni +' div').animate(
		{ left: -imgWidth },
		{
			duration: imgWidth * 25,
			specialEasing: { left: 'linear' },
			complete: function(){
				$('#'+ maandvlakAni +' div img.temp').remove();
				if(maandVlak == currentMaandVlak) { startMaandVlakAnimation(maandVlak); }
			}
		}
	);	
}
function initMaandVlakAnimation(maandVlak){ if(maandVlak != currentMaandVlak) { startMaandVlakAnimation(maandVlak); }}
function stopMaandvlakAnimation(){ $('#'+ blokken_itemList[currentMaandVlak].ulAnimation +' div').stop(); currentMaandVlak = null; }
function begunstAni(){
	var currentBegunst = arguments[0];
	var nextBegunst = currentBegunst + 1;
	if(currentBegunst == $('#begunstDiv div').length - 1) { nextBegunst = 0; }
	$($('#begunstDiv div')[currentBegunst]).css('z-index',25);
	$($('#begunstDiv div')[nextBegunst]).css('z-index',24);
	$($('#begunstDiv div')[currentBegunst]).animate({ opacity: 0 }, 1000, 'linear', function(){ $($('#begunstDiv div')[currentBegunst]).css('opacity',20).css('z-index',1).show(); });
	setTimeout(function(){ begunstAni(nextBegunst); },7000);
}
function addTrackToPlayer(id){
	var oFlash = document.getElementById(audio[id][0]);
	oFlash.SetVariable('bandID', 0);
	oFlash.SetVariable('songID', 0);
	oFlash.SetVariable('songName', audio[id][3]);
	oFlash.SetVariable('bandName', audio[id][2]);
	oFlash.SetVariable('songPath', audio[id][1]);
	oFlash.TCallLabel('/', 'addSong');
	$('#'+ audio[id][0]).parent().attr('onclick','');
	$('#'+ audio[id][0] +'Img').remove();
}
function eventManagerDateOnChange(thisValue){
	$('#cardsAmountEventManager').html('').append('<option value="">Selecteer een aantal kaarten</option>');
	for(var i = 1; i < 5; i++){
		if(vrijePlaatsen[thisValue] < i){ break; }
		else {
			$('#cardsAmountEventManager').append('<option value="'+ i +'">'+ i +'</option>');
		}
	}
	$('.currentEvent').removeClass('currentEvent');
	$('.'+ thisValue).addClass('currentEvent');
}
function eventManagerSetFocusField(id){ if(!isDefined(focusField)) { focusField=id; }}
function eventManagerFormSubmit(){
	$('#emailEventManager').val($.trim($('#emailEventManager').val()));
	$('label.errors').removeClass('errors');
	$('#eventManagerErrorDiv, #eventManagerResultDiv').hide();
	if($('#reservationDateEventManager').val() === '' || $('#cardsAmountEventManager').val() === '' || $('#lastnameEventManager').val() === '' || $('#emailEventManager').val() === '') {
		$('#eventManagerErrorDiv').html('<ul></ul>').show();
		if($('#reservationDateEventManager').val() === '') { $('#reservationDateEventManager').parent().find('label').addClass('errors'); $('#eventManagerErrorDiv ul').append('<li>De <em>Datum</em> is niet ingevuld</li>'); }
		if($('#cardsAmountEventManager').val() === '') { $('#cardsAmountEventManager').parent().find('label').addClass('errors'); $('#eventManagerErrorDiv ul').append('<li>Het <em>Aantal kaarten</em> is niet ingevuld</li>'); }
		if($('#lastnameEventManager').val() === '') { eventManagerSetFocusField('#lastnameEventManager'); $('#lastnameEventManager').parent().find('label').addClass('errors');$('#eventManagerErrorDiv ul').append('<li>U heeft uw <em>Achternaam</em> niet ingevuld</li>'); }
		if($('#emailEventManager').val() === '') { eventManagerSetFocusField('#emailEventManager'); $('#emailEventManager').parent().find('label').addClass('errors'); $('#eventManagerErrorDiv ul').append('<li>U heeft uw <em>E-mailadres</em> niet ingevuld</li>'); }
		$(focusField).focus(); focusField = null;
	}
	else {
		var submitUrl = jsonUrl +'/save.json?'+ $('#eventManagerForm').serialize() +'&jsoncallback=?';
		$.getJSON(submitUrl, null, function(data){
			if(isDefined(data.errors)){
				$('#eventManagerErrorDiv').html('').append('<ul>').show();
				$.each(data.errors, function(i,item){
					$('#eventManagerErrorDiv ul').append('<li>'+ item.message +'</li>');
					//setFocusField(item.name)
					if(isDefined(item.name)) { $('[name='+ item.name +']').parent().find('label').addClass('errors'); }
				});
				$('[id='+ focusField +'EventManager]').focus(); focusField = null;
			}
			else {
				$('#jsonDiv').hide().parent().append('<p>Dank voor uw inschrijving. U ontvangt per mail een bevestiging van uw reservering.</p><button onclick="openTicketShop(\'/nl/shop/?${reservationDate}\')" class="ticketButton">Bestel</button>');
				if($('#newsletterEventManager').is(':checked')) {
					$('#jsonDiv').parent().append('<h3>Nieuwsbrief</h3><div id="newsletterSubscription"><img src="/media/img/ani_loading.gif" /></div>');
					var submitUrl = 'https://6.sixmo.com/mailoffice/registrant/register.json?lang=nl&firstname='+ $('#firstnameEventManager').val() +'&tussenvoegsel='+ $('#tussenvoegselEventManager').val() +'&lastname='+ $('#lastnameEventManager').val() +'&email='+  $('#emailEventManager').val() +'&list=DNKA';
					$.getJSON(submitUrl +'&jsoncallback=?', function(data){
						if(isDefined(data.errors)){
							$('#newsletterSubscription').html('<p>Het inschrijven voor de nieuwsbrief is mislukt. Probeert u het nog eens via de link in de rechterkolom.</p>');
						}
						else {
							$('#newsletterSubscription').html('<p>'+ data.fullname +' &lt;'+ data.email +'> is toegevoegd aan ons adressenbestand. Er is een e-mail gestuurd ter bevestiging.</p>');
						}
					});
				}
			}
		});
	}
}
function leadingZero(num,count){
	var numLeadingZero = num + '';
	while(numLeadingZero.length < count) {
		numLeadingZero = "0" + numLeadingZero;
	}
	return numLeadingZero;
}
function activiteitenCheck(){
	var ttl = 'Geweest';
	if(language=='en') { ttl = 'Past'; }
	$('#ajaxContent').append('<div class="item" id="activiteitenGeweest"><h1>'+ ttl +'</h1></div>');
	var currentDate = new Date();
	var dateClass = ''+ currentDate.getFullYear().toString().substring(2) + leadingZero(currentDate.getMonth() + 1,2) + leadingZero(currentDate.getDate(),2);
	if(dateClass.substring(0,1) == '0'){ dateClass = dateClass.substring(1); }
	$('.activiteit').each(function(){
		var thisDate = $(this).attr('class').substring(11);
		if(thisDate.substring(0,1) == '0'){ thisDate = thisDate.substring(1); }
		
		if(parseInt(thisDate, 10) < parseInt(dateClass, 10)){
			$('#activiteitenGeweest').append('<div class="activiteit">'+ $(this).html() +'</div>');
			$(this).remove();
			$('#activiteitenGeweest').show();
		}
	});
}
function vakantieCheck(){
	var currentDate = new Date();
	var dateClass = ''+ currentDate.getFullYear().toString().substring(2) + leadingZero(currentDate.getMonth() + 1,2) + leadingZero(currentDate.getDate(),2);
	if(dateClass.substring(0,1) == '0'){ dateClass = dateClass.substring(1); }
	$('.vakantie').each(function(){
		var thisDate = $(this).attr('class').substring(9).split('t');
		if(thisDate[0].substring(0,1) == '0'){ thisDate[0] = thisDate[0].substring(1); }
		if(thisDate[1].substring(0,1) == '0'){ thisDate[1] = thisDate[1].substring(1); }
		
		if(parseInt(dateClass, 10) >= parseInt(thisDate[0], 10) && parseInt(dateClass, 10) <= parseInt(thisDate[1], 10)) { $(this).show(); }
		else { $(this).remove(); }
	});
	$($('#content .item')[0]).css('border','none');
}

$(document).ready(function(){
	var a=navigator.userAgent.toLowerCase();
	$.browser.chrome=/chrome/.test(navigator.userAgent.toLowerCase());
	if($.browser.msie){$('body').addClass('browserIE');$('body').addClass('browserIE'+$.browser.version.substring(0,1));}
	if($.browser.chrome){$('body').addClass('browserChrome');a=a.substring(a.indexOf('chrome/')+7);a=a.substring(0,1);$('body').addClass('browserChrome'+a);$.browser.safari=false;}
	if($.browser.safari){$('body').addClass('browserSafari');a=a.substring(a.indexOf('version/')+8);a=a.substring(0,1);$('body').addClass('browserSafari'+a);}
	if($.browser.mozilla){if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){$('body').addClass('browserFirefox');a=a.substring(a.indexOf('firefox/')+8);a=a.substring(0,1);$('body').addClass('browserFirefox'+a);}else{$('body').addClass('browserMozilla');}}
	if($.browser.opera){$('body').addClass('browserOpera');}
	
	var parameter = currentMaandVlak;
	if(currentMaandVlak >= 6) { currentMaandVlak = 4; }
	contentLoaded();
	$('#ajaxContent').show();
	$($('#ulAnimation li')[currentMaandVlak]).find('div').append($(blokken_itemList[currentMaandVlak].content)).next().text(blokken_itemList[currentMaandVlak].text);
	if(isDefined(loc)) { loadContent(loc); }
	$('#ulImageAnimation').jcarousel({ auto: 6, scroll: 1, animation: 2000, easing: 'linear', wrap: 'circular', buttonNextHTML: null, buttonPrevHTML: null, itemVisibleInCallback: {onBeforeAnimation: ulImageAnimation_itemVisibleInCallback}, itemVisibleOutCallback: {onAfterAnimation: ulImageAnimation_itemVisibleOutCallback} });
	$('#ulAnimation').jcarousel({ scroll: 1, start: currentMaandVlak + 1, buttonNextHTML: null, buttonPrevHTML: null });
	$('#rightNav').height($('#rightNav').height() + 170);
	if($('#rightNav').height() > $('#leftNav').height()) { $('#leftNav').css('min-height',$('#rightNav').height()); }
	else { $('#rightNav').css('min-height',$('#leftNav').height()); }
	$('#islamnu a').each(function(){ $(this).bind('click',function(){ $.address.value($(this).attr('href')); return false; }); });
	
	$('#months a').each(function(){
		$(this).bind('click',function(){
			$.address.value($(this).attr('href'));
			$('#leftNavGeneral ul').hide();
			$('#leftNav a').removeClass('actSel');
			return false;
		}).bind('mouseover',function(){
			clearTimeout(monthsATimeout);
			var index = $(this).parent().attr('index') - 1;
			if(index != month) { blokken_itemList[index].arrowPosition = arrowPosition(parseInt(index, 10) + 1); }
			$('#arrowTodaysDate').animate({
				left: blokken_itemList[index].arrowPosition
			}, 100).css('background-color',blokken_itemList[index].color);
			$('#months h1')
				.css('color',blokken_itemList[index].color)
				.text(blokken_itemList[index].text)
				.append('<span>'+ blokken_itemList[index].dates +'</span>');
			if($('#arrowTodaysDate, #monthTitle').hasClass('corpHidden')) { $('#arrowTodaysDate, #monthTitle').addClass('corpShow'); }
		}).bind('mouseout',function(){
			if($('#arrowTodaysDate, #monthTitle').hasClass('corpHidden')) { $('#arrowTodaysDate, #monthTitle').removeClass('corpShow'); }
			monthsATimeout = setTimeout(
				function(){
					$('#arrowTodaysDate').animate({
						left: blokken_itemList[currentMaandVlak].arrowPosition
					}, 100).css('background-color',blokken_itemList[currentMaandVlak].color);
					$('#months h1')
						.empty()
						.css('color',blokken_itemList[currentMaandVlak].color)
						.text(blokken_itemList[currentMaandVlak].text)
						.append('<span>'+ blokken_itemList[currentMaandVlak].dates +'</span>');
				}, 300
			);
		});
	});
	$('#leftNav a').each(function(){
		$(this)
			.mouseover(function(){ $(this).addClass('actHov'); })
			.mouseout(function(){ $(this).removeClass('actHov'); })
			.attr('href', $(this).attr('href') +'?m=99')
			.click(function(){
				$('#leftNav a').removeClass('actSel');
				$(this).addClass('actSel');
				$(this).parent().next('ul').toggle().find('ul').hide();
				$.address.value($(this).attr('href'));
				return false;
			});
	});
	$('#rightNav a').each(function(){
		// only target internal links
		targetAttr = $(this).attr('target');
		targetCheck = true;
		if(isDefined(targetAttr) && targetAttr.length > 0 && targetAttr.indexOf('blank') != -1) { targetCheck = false; }
		
		if(targetCheck && isDefined($(this).attr('href'))){
			if($(this).attr('href').indexOf('mailto:') == -1 && $(this).attr('href') != '#'){
				$(this).attr('href',$(this).attr('href') +'?m=99');
				$(this).bind('click', function(){
					$('#leftNav a').removeClass('actSel');
					$.address.value($(this).attr('href'));
					return false;
				});
			}
		}
	});
	$.address.change(function(event){
		$('#content').hide();
		parameter = event.parameters.m ? event.parameters.m : currentMaandVlak;
		var location = event.value;
		if(location.indexOf('http://nieuwekerk.nl/') > -1) { location = location.substring(21,location.length); }
		if(location.indexOf('http://www.nieuwekerk.nl/') > -1) { location = location.substring(25,location.length); }
		if(location.indexOf('http://localhost:81/') > -1) { location = location.substring(20,location.length); }
		if(location != '/') { loadContent(location, parameter); }
		else {
			loadContent('/'+ language +'/', parameter);
			parameter = todaysMaandVlak;
			currentMaandVlak = todaysMaandVlak;
		}
		if(parameter != 99){
			$('#ani99').hide(); clearTimeout(ani99); ani99_is_on = false;
			$('#ulAnimation').data('jcarousel').scroll($.jcarousel.intval(parseInt(parameter, 10) + 1));
			initMaandVlakAnimation(parameter);
			/*if(parameter == 3) $('#leftNavMonthSpecific').hide();
			else */$('#leftNavMonthSpecific').show().css('background-color',blokken_itemList[parameter].backgroundColor);
			$('#arrowTodaysDate').css('left',blokken_itemList[currentMaandVlak].arrowPosition).css('background-color',blokken_itemList[currentMaandVlak].backgroundColor);
			$('#arrowTodaysDate, #monthTitle').removeClass('corpHidden');
			$('#content, #content a, #months h1').css('color',blokken_itemList[parameter].color);
			$('#months h1').text(blokken_itemList[parameter].text).append('<span>'+ blokken_itemList[parameter].dates +'</span>');
		}
		else {
			$('#leftNavMonthSpecific').hide();
			$('#ani99').show();
			if(!ani99_is_on) { ani99 = setTimeout(startAni99, 3500); }
			$('#arrowTodaysDate, #monthTitle').addClass('corpHidden').removeClass('corpShow');
			$('#content, #content a').css('color','#5F616F');
			$('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6').addClass('corpContent');
			parameter = currentMaandVlak;
		}
		// get block specific content
		if(event.parameters.m != leftNavMonthSpecificContent){
			$.ajax({
				url: '/'+ language +'/ssi/blok_'+ blokken_itemList[parameter].ulAnimation +'.inc',
				type: 'GET',
				dataType: 'html',
				success: function(txt){
					leftNavMonthSpecificContent = currentMaandVlak;
					$('#leftNavMonthSpecific').html(txt);
					ulImageAnimation_itemList = blokken_itemList[currentMaandVlak].ulImageAnimation;
					$(ulImageAnimation_itemList).each(function(i){ $.preloadImages(ulImageAnimation_itemList[i].url); });
					$('#leftNavMonthSpecific li h5, #leftNavMonthSpecific li h6')
						.unbind('click')
						.click( function(){ $(this).next().toggle(); } );
					$('#leftNavMonthSpecific a')
						.each(function(){
								
							// bind event handlers
							$(this)
								.mouseover(function(){ $(this).addClass('actHov'); })
								.mouseout(function(){ $(this).removeClass('actHov'); });
							if(isDefined($(this).attr('href'))){
								// only target internal links
								targetAttr = $(this).attr('target');
								targetCheck = true;
								if(isDefined(targetAttr) && targetAttr.length > 0 && targetAttr.indexOf('blank') != -1) { targetCheck = false; }

								if(targetCheck && $(this).attr('href').indexOf('mailto:') == -1){
									$(this).bind('click',function(){
										$('#leftNav a').removeClass('actSel');
										$(this).addClass('actSel');
										$.address.value($(this).attr('href'));
										return false;
									});
								}
							}
					});
					vakantieCheck();
				}
			});
		}
		window.scroll(0,0);
		$('#content').show();
	});
	$('#leftNav li h4, #leftNav li h5, #leftNav li h6').unbind('click').click( function(){ $(this).next().toggle(); $(this).next().find('ul').hide(); } );

	var todaysDate = new Date();
	var todaysDatePosition;
	var todaysBlokWidth = 0;
	$('#months ol li[index='+ $($('#months ol li')[0]).attr('index') +']:not(.hyphen)').each(function(){ todaysBlokWidth = todaysBlokWidth + $(this).width(); });
	var extraWidth = 18;
	if(todaysMonth === 0) { extraWidth = 74 + 18; }
	if(todaysMonth == 1) { extraWidth = 74 + 57 + 18; }
	if(todaysMonth == 2) { extraWidth = 74 + 57 + 62 + 18; }
	//if(todaysMonth == 3) { extraWidth = 74 + 57 + 62 + 51 + 18; }
	if(todaysMonth == 7) { extraWidth = 18; }
	if(todaysMonth == 8) { extraWidth = 65 + 18; }
	if(todaysMonth == 10) { extraWidth = 18; }
	var todaysDateLeft = parseInt(todaysDate.getDate()*(todaysBlokWidth/blokken_itemList[todaysMaandVlak].dayslength) + extraWidth, 10);
	$('#todaysDate').text(todaysDate.getDate() +'.'+ (todaysDate.getMonth() + 1) +'.'+ todaysDate.getFullYear()).css('left',todaysDateLeft);
	blokken_itemList[todaysMaandVlak].arrowPosition = todaysDateLeft - 6;
	$('#arrowTodaysDate').css('left',blokken_itemList[todaysMaandVlak].arrowPosition).css('background-color',blokken_itemList[todaysMaandVlak].backgroundColor);
	$('#currentYear').width($('#yearStart').position().left - $('#currentYear').position().left + 15);
	$('#nextYear').width($('#months ol').width() - $('#currentYear').width() - 5);
	
	$(blokken_itemList).each(function(i){
		var currentDiv = $($('#ulAnimation li')[i]).find('div');
		if($(currentDiv).html() === '') { $(currentDiv).append($(blokken_itemList[i].content)); }
		var currentH1 = $($('#ulAnimation li')[i]).find('h1');
		if($(currentH1).html() === '') { $(currentH1).text(blokken_itemList[i].text); }
	});
	/*if(parameter != 99) */setTimeout(function(){ startMaandVlakAnimation(currentMaandVlak); }, 2000);
	ulImageAnimation_itemList = blokken_itemList[currentMaandVlak].ulImageAnimation;
	$(ulImageAnimation_itemList).each(function(i){ $.preloadImages(ulImageAnimation_itemList[i].url); });
	for(var i=0; i<7; i++){ $('#ani99').append('<img src="/nl/media/img/99/'+ i +'.png" class="ani99-'+ i +'" style="z-index: 1'+ i +'">'); }
	$('#mailOffice').mailoffice();
	$(document).keyup(function(event){ if(event.keyCode == 27) { $('#mailOffice, #greyedout').hide(); } });
	begunstAni(0);
	
	var startingMonth = blokken_itemList_general[blokkenOrder[0]].dateStart.getMonth();
	var dayWidth = 696 / 365;
	//$('#months').append('<ol id="blocksOl" style="top: 10px;" />');
	//$('#months').append('<ol id="monthsOl2" style="top: 10px;" />');
	//$('#months').append('<ol id="blocksOlClickable" style="top: 10px;" />');
	for(i=0, j=startingMonth; i < 12; i ++, j++){
		var daysInMonth = new Date(2010, j, 0).getDate();
		var monthWidth = daysInMonth * dayWidth;
		$('<li style="width: '+ monthWidth +'px; min-width: 0; text-align: center; overflow:hidden;">'+ monthNames[j] +'</li>').appendTo('#monthsOl2');
		if(j === 11){ j = -1; }
	}
	$(blokkenOrder).each(function(i){
		var liWidth = Math.round(((blokken_itemList_general[blokkenOrder[i]].dateEnd - blokken_itemList_general[blokkenOrder[i]].dateStart)/(1000*60*60*24)) * dayWidth);
		var blocksOlLi = $('<li style="height: 12px; width: '+ liWidth +'px; background-color: '+ blokken_itemList_general[blokkenOrder[i]].backgroundColor +'"></li>');
		var blocksOlClickable = $('<li style="height: 12px; width: '+ liWidth +'px;"><a href="bla"></a></li>');
		//blocksOlLi.appendTo('#blocksOl');
		//blocksOlClickable.appendTo('#blocksOlClickable');
	});
});
