var homeCounter =0;
var scroll = 0;
var currentunit;
var nextunit;
var previousunit;
var hightlights = new Array();
var homeid;
var interval;

sfHover = function() {
	if(!$('nav')) return; // Klaas: voorkomt errors bij het bestelformulier
	
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

window.addEvent('load', function(){


	if ($('promos'))
		initPromos();
		
	init_sitemap();
	init_agendafilter();
	

	if($('flashheader')) zetFlashheader();
	//if($('flashfooter')) zetFlasfooter();
	
	
	if($('flashhome')){ 
			zetFlashhome();
	 }
	
});


window.addEvent('scroll', function(){

});

window.addEvent('resize', function(){

});

function zetFlashhome(){
		FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
		var so = new SWFObject("fileadmin/templates/flash/rpo_menu_concert_home.swf", "flashhomeid", "936", "130", "8");
		so.addVariable('sGatewayUrl', 'http://'+location.hostname+'/amfphp/gateway.php');
		so.addVariable('sWebroot', 'http://'+location.hostname+'/');
		so.addVariable('homepage', true);
		so.addParam("wmode", "transparent");
		so.addVariable("identiteit", identiteit);
		so.write("flashhome");
}


function zetFlasfooter(){

		FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
		var so = new SWFObject("fileadmin/templates/flash/rpo_menu_myagenda.swf", "flashfooterid", "936", "115", "8");
		so.addVariable('sGatewayUrl', 'http://'+location.hostname+'/amfphp/gateway.php');
		so.addVariable('sWebroot', 'http://'+location.hostname+'/');
		so.addParam("wmode", "transparent");
		so.addVariable("identiteit", identiteit);
		so.write("flashfooter");
}


function zetFlashheader(){
		FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
		var so = new SWFObject("fileadmin/templates/flash/rpo_menu_concert.swf", "flashheaderid", "936", "115", "8");
		so.addVariable('sGatewayUrl', 'http://'+location.hostname+'/amfphp/gateway.php');
		so.addVariable('sWebroot', 'http://'+location.hostname+'/');
		so.addParam("wmode", "transparent")
		so.addVariable("identiteit", identiteit);
		so.write("flashheader");	

}

function fnTriggerTop()
{
	thisMovie("flashheaderid").doFilter("testing");
}

function fnPlaceInAgenda( oFlash )
{	/*
	var footerInt = $('footer').getStyle('height').toInt();
	if(footerInt<=30){
		fnShowHideAgenda();
		var showFooter = true;
	}else{
		var showFooter = false;
	}

	thisMovie("flashfooterid").placeInAgenda( oFlash );
	
	if(showFooter)
	setTimeout("fnShowHideAgenda()",1200);
	* */
}

function fnGetSeasonsAgenda(year)
{
	if($('flashheaderid'))thisMovie("flashheaderid").getSeasonsAgenda( year );
}

function fnShowHideAgenda()
{/*
	var footerInt = $('footer').getStyle('height').toInt();

	if(footerInt<=30){
		var to = 115;
		if($('home_footer'))
			$('home_footer').setStyle('height','200px');
	}else{
		footerInt = 115;
		var to = 30;
		if($('home_footer'))
			$('home_footer').setStyle('height','120px');
	}

	$('footer').effect('height',{
		duration:600,
		transition:Fx.Transitions.expoIn
	}).start(footerInt, to);
	*/
}

function replaceHtml(el, html) {
        var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
        var newEl = document.createElement(oldEl.nodeName);
        // Preserve the element's id and class (other properties are lost)
        newEl.id = oldEl.id;
        newEl.className = oldEl.className;
        // Replace the old with the new
        newEl.innerHTML = html;
        oldEl.parentNode.replaceChild(newEl, oldEl);
        /* Since we just removed the old element from the DOM, return a reference
        to the new element, which can be used to restore variable references. */
        return newEl;
};


function fnHighLight(uids){	

	if(thisMovie("flashhomeid"))
		clearInterval(interval);
	
	if(thisMovie("flashheaderid"))
		thisMovie("flashheaderid").doHighLight(uids);
	
	if(thisMovie("flashhomeid"))
		thisMovie("flashhomeid").doHighLight(uids);
}




function htmlPlaatsInAgenda(fnmonthid, fnseasonid, fnday, fnmonth, fnyear, fndagnr, fndatum, fnuid){
	/*
	var oFlash = {
		monthid : fnmonthid,
		seasonid : fnseasonid,
		day : fnday,
		month : fnmonth,
		year :fnyear,
		dagnr : fndagnr,
		date: fndatum,
		titel: '',
		concertcode : ''
	};
	
	var footerInt = $('footer').getStyle('height').toInt();
	if(footerInt<=30){
		fnShowHideAgenda();
		var showFooter = true;
	}else{
		var showFooter = false;
	}	
	
	if($('icon_'+fnuid)){
		$('icon_'+fnuid).setStyle('display','none');
	}
	
	if($('homeplanner_'+fnuid)){
		$('homeplanner_'+fnuid).setStyle('display','none');
	}		
	
	if($('flashfooter')){
		thisMovie("flashfooterid").placeInAgenda( oFlash );
		if(fnuid){
			plaatsInAgenda(fnuid);
		}
	}
	* */
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}


function initFooterPosition() {
	/*
	if ($('footer').getStyle('position') == 'fixed') {
		$('footer').setStyle('position', 'absolute');
	}
	setFooterPosition();
	* */
}

function setFooterPosition() {
	viewportWidth = window.getWidth().toInt();
	$('footer').setStyle('width', viewportWidth);
	
	footerHeight = $('footer').getStyle('height');
	viewportHeight = window.getHeight().toInt();
	viewportScrollTop = window.getScrollTop();
	offsetHeight = (viewportHeight.toInt() - footerHeight.toInt()) + viewportScrollTop;
	$('footer').setStyle('top', offsetHeight);
}

// NIEUWSBRIEF JAVASCRIPTS
// Popup-scherm voor tonen Subscribe/unsubscribe informatie.
// (c) Mailinglijst.nl, 2002

function subscribe(lijstnr){
var stroptions, strURL
var lngtop, lngleft

	strURL = "http://www.mailinglijst.nl/nieuwsbrief/subscribe.asp?l=" + lijstnr
	lngtop = 50
	lngleft = 50
	stroptions= "width=400,height=500,top="+lngtop + ",left=" +lngleft + ",scrollbars=1"
	whandle = window.open(strURL,'nieuwsbrief',stroptions);
	whandle.focus();
}

function unsubscribe(lijstnr){
var stroptions, strURL
var lngtop, lngleft

	strURL = "http://www.mailinglijst.nl/nieuwsbrief/edit.asp?l=" + lijstnr
	lngtop = 50
	lngleft = 50
	stroptions= "width=400,height=400,top="+lngtop + ",left=" +lngleft + ",scrollbars=1"
	whandle = window.open(strURL,'nieuwsbrief',stroptions);
	whandle.focus();
}


function initPromos() {

	promoos = $$('div#promos div.promo');
	slideNr = 0;
	promosManual = false;
	
	var prev = document.getElementById('button_prev');
	if (prev) {
		prev.onclick = function() {
			promosManual = true;
			clearTimeout(promoTimer);
			prevPromo();
		}
	}
	
	var nxt = document.getElementById('button_next');
	if (nxt) {
		nxt.onclick = function() {
			promosManual = true;
			clearTimeout(promoTimer);
			nextPromo();
		}
	}
	
	// beginnen met de eerste slide
	promoos[slideNr].style.display = 'block';
	aantalSlides = promoos.length;
	
	if (promosManual == false) promoTimer = setTimeout('nextPromo();', 10000); // pas deze interval ook aan onderin de functie nextPromo()
}

function nextPromo() {
	if (slideNr < (aantalSlides-1)) {
		vorigeSlide = slideNr;
		slideNr = slideNr + 1;
	}
	else {
		vorigeSlide = aantalSlides-1;
		slideNr = 0;
	}
	
	promoos.each(function(element) {
		element.style.display = 'none';
	});
	
	promoos[vorigeSlide].style.display = 'block';
	promoos[vorigeSlide].style.zIndex = '0';
	promoos[slideNr].style.zIndex = '9';
	promoos[slideNr].style.display = 'block';
	
	if (promosManual == false) promoTimer = setTimeout('nextPromo();', 10000);
}


function prevPromo() {
	if (slideNr == '0') {
		volgendeSlide = slideNr;
		slideNr = aantalSlides-1;
	}
	else {
		volgendeSlide = slideNr;
		slideNr = slideNr - 1;
	}
	
	promoos.each(function(element) {
		element.style.display = 'none';
	});
	
	promoos[volgendeSlide].style.display = 'block';
	promoos[volgendeSlide].style.zIndex = '0';
	promoos[slideNr].style.zIndex = '9';
	promoos[slideNr].style.display = 'block';
}


function fnOtherSeasonConcertHome()
{
	thisMovie("flashhomeid").otherSeason();			
}

function fnOrderConcert(url) {
	window.open(url,'FEopenLink','status=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,toolbar=0,width=1000,height=670');
}

function fnGetSeasonsAgendaHome( year )
{
	thisMovie("flashhomeid").getSeasonsAgenda( year );
}
var laatsteSeizoen = '';
function initUnits() {
	
	var previous = $('button_prev2');
	var next = $('button_next2');
	var units = $$('.home_items');
	var items = $$('.home_item');
	var unitArray = new Array();

	currentunit = currentunit.toInt();
	
	zetAfbeeldingAan(currentunit);
	var unitlength = 936;
	nextunit = currentunit+1;
	previousunit = currentunit-1;

	// hide all
	units.each(function(element) {
		element.style.left = unitlength+'px';
	});

	// show first
	if(units[currentunit])
	units[currentunit].style.left = '0';
	
	hightlights = new Array();
	var rs = units[currentunit].getChildren();
	rs.each(function(el){
		var days = el.id.split(',');
		days.each(function(el){
			hightlights.push(el);
		});
	});

	interval = setInterval("fnHighLight(hightlights)",1000);
	
	
	next.onclick = function() {
		nextUnit();
	}
	previous.onclick = function() {
		previousUnit();
	}
}

var afbeeldinAanwezig = new Array();

function zetAfbeeldingAan(id){
	
	var els = $$('.home_items');
	if (!afbeeldinAanwezig.contains(id)){
		afbeeldinAanwezig.push(id);
		var curr_items = els[id].getChildren();
		
		curr_items.each(function(el){
		
			var hide = el.getElement('.afbeelding');
			
			var Imageurl = hide.value;
			if (Imageurl.length > 1) {
				var img = new Element('img', {
					'src': Imageurl,
					'width': '234px',
					'height': '156px',
					'border': '0px',
					'class': 'visual'
				});
				
				img.injectAfter(hide);
			}
		});
	}
}


function nextUnit() {
	var units = $$('.home_items');
	var items = $$('.home_item');
	var unitArray = new Array();

	// current unit slideout
	var fx = new Fx.Styles(units[currentunit], {duration:1000, wait:false, transition: Fx.Transitions.Quint.easeInOut});
 	fx.start({
			'left': [0,'-936px']
	});
	
	
	// next unit slidein
	var fx = new Fx.Styles(units[nextunit], {duration:1000, wait:false, transition: Fx.Transitions.Quint.easeInOut});
 	fx.start({
			'left': ['936px',0]
	});
	
	if (nextunit == units.length-1) {
		currentunit++;
		nextunit = 0;
		previousunit = units.length-2;
		homeCounter = (homeCounter==0?4:homeCounter+=4);
	}
	else if(currentunit == units.length-1) {
		currentunit = 0;
		nextunit = 1;
		previousunit = units.length-1;
		homeCounter = (homeCounter==0?4:homeCounter-=4);
	}
	else {
		currentunit++;
		nextunit++;
		previousunit=currentunit-1;
		homeCounter = (homeCounter==0?4:homeCounter+=4);
	}
	
	zetAfbeeldingAan(currentunit);
	
	hightlights = new Array();
	var rs = units[currentunit].getChildren();
	rs.each(function(el){
		var days = el.id.split(',');
		days.each(function(el){
			hightlights.push(el);
		});
	});
	var start = rs[0].id.split(',');
	if(start[0]>425 && laatsteSeizoen==0){
		fnOtherSeasonConcertHome();
		laatsteSeizoen = 1;
	}
	fnHighLight(hightlights);	

}

function previousUnit() {
	var units = $$('.home_items');
	
	// current unit slideout
	var fx = new Fx.Styles(units[currentunit], {duration:1000, wait:false, transition: Fx.Transitions.Quint.easeInOut});
 	fx.start({
			'left': [0,'936px']
	});
	
	
	// previous unit slidein
	var fx = new Fx.Styles(units[previousunit], {duration:1000, wait:false, transition: Fx.Transitions.Quint.easeInOut});
 	fx.start({
			'left': ['-936px',0]
	});
	
	if (previousunit == 0) {
		currentunit = 0;
		nextunit=currentunit+1;
		previousunit = units.length-1;
	}
	else if(currentunit == 0) {
		currentunit = units.length-1;
		nextunit = 0;
		previousunit = units.length-2;
	}
	else {
		currentunit--;
		nextunit=currentunit+1;
		previousunit=currentunit-1;
	}
	
	zetAfbeeldingAan(currentunit);
	
	hightlights = new Array();
	var rs = units[currentunit].getChildren();
	rs.each(function(el){
		var days = el.id.split(',');
		days.each(function(el){
			hightlights.push(el);
		});
	});
	
	var start = rs[0].id.split(',');
	if(start[0]<425 && laatsteSeizoen==1){
		fnOtherSeasonConcertHome();
		laatsteSeizoen=0;
	}	
	
	fnHighLight(hightlights);	
	
}


function fontgrootte(grootte) {
	var PIXEL = /^\d+(px)?$/i;

	if(PIXEL.test($E('body').getStyle('fontSize'))){
		if (grootte == 'a'){
			$E('body').effect('fontSize',{duration:300,unit:'px'}).start($E('body').getStyle('fontSize'), '12px');
		}else if (grootte == 'aa'){
			$E('body').effect('fontSize',{duration:300,unit:'px'}).start($E('body').getStyle('fontSize'), '14px');
		}else if (grootte == 'aaa'){
			$E('body').effect('fontSize',{duration:300,unit:'px'}).start($E('body').getStyle('fontSize'), '16px');
		}
	}else{
		if (grootte == 'a'){
			$E('body').effect('fontSize',{duration:300,unit:'em'}).start($E('body').getStyle('fontSize'), 0.75);
		}else if (grootte == 'aa'){
			$E('body').effect('fontSize',{duration:300,unit:'em'}).start($E('body').getStyle('fontSize'), 1);
		}else if (grootte == 'aaa'){
			$E('body').effect('fontSize',{duration:300,unit:'em'}).start($E('body').getStyle('fontSize'), 1.3);
		}	
	}
}


function init_sitemap() {
	// deze functie verzorgt het open- en dichtklappen van de subitems in de sitemap
	
	if(!$('sitemap')) return;
	
	var switches = $ES('span', 'sitemap');
	switches.each(function(item) {
		item.addEvent('click', function() {
			if(item.parentNode.className == 'open') {
				// klap het aangeklikte item dicht
				item.parentNode.className = 'closed';
				item.parentNode.parentNode.parentNode.className = '';
				item.title = 'openvouwen';
			} else {
				// klap alle items dicht...
				switches.each(function(item2) {
					item2.parentNode.className = 'closed';
					item2.parentNode.parentNode.parentNode.className = '';
					item2.title = 'openvouwen';
				});
				// ... en klap het aangeklikte item open
				item.parentNode.className = 'open';
				item.parentNode.parentNode.parentNode.className = 'highlight';
				item.title = 'sluiten';
			}
		});
	});
}

function init_agendafilter() {
	// deze functie verzorgt het open- en dichtklappen van de filtercategorie?n in de concertagenda
	// en het markeren van het toegepaste filter
	
	if(!$('agenda_filter')) return;
	
	var categorieen = $ES('h3', 'agenda_filter');
	categorieen.each(function(item) {
		item.addEvent('click', function() {
			categorieen.each(function(item2) {
				item2.parentNode.className = '';
			});
			item.parentNode.className = 'open';
		});
	});
	
	var filters = $$('li.filter');
	filters.each(function(item) {
		item.addEvent('click', function() {
			filters.each(function(item2) {
				item2.className = 'filter';
			});
			item.className = 'filter selected_filter';

			// AJAX doe je ding hier ...

		});
	});
}

function verbergMijnAgenda() {
	return; // GIJS WAS ER KLAAR MEE
	if ($('footer').style.height == '115px' || $('footer').style.height == '') {
	
		if (window.ie6) {
			$('footer').style.height = '19px';
			setFooterPosition();
		}
		else {
			var fx = new Fx.Styles($('footer'), {duration:500, wait:true, transition: Fx.Transitions.Expo.easeOut});
			fx.start({
				'height': '19px'
			});
		}
	}
	else {
		
		if (window.ie6) {
			$('footer').style.height = '115px';
			setFooterPosition();
		}
		else {
			var fx = new Fx.Styles($('footer'), {duration:500, wait:true, transition: Fx.Transitions.Expo.easeOut});
			fx.start({
				'height': '115px'
			});
		}
	}
}

function toonMijnAgenda() {
	
	if (window.ie6) {
		$('footer').style.height = '115px';
		setFooterPosition();
	}
	else {
		var fx = new Fx.Styles($('footer'), {duration:500, wait:true, transition: Fx.Transitions.Expo.easeOut});
		fx.start({
			'height': '115px'
		});
	}
	
}

function alle(nummer) {
	var myElements 			= $(document.body).getElements('div[class^=alle]');
	
	myElements.each(function(el){
		el.setStyle('display','none');
	});
	
	if ($('alle'+nummer).style.display == 'block')
		$('alle'+nummer).style.display = 'none';
	else
		$('alle'+nummer).style.display = 'block';
}

function loadPlayer(fragment) {
	var el = $('player');
	
	var so = new SWFObject("http://www.muziekweb.nl/audio/mwplayer.swf", "mwplayer1", "250", "85", "9");
	so.addParam('allowScriptAccess', 'always');
	so.addParam('movie', 'http://www.muziekweb.nl/audio/fms3test/emff_mw.swf');
	so.addParam('quality', 'high');
	so.addParam("wmode", "transparent");
	so.addVariable('playlist', fragment);
	so.addVariable('autostart', 'yes');
	so.write("player");	
	
	//var player = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='250' height='85' id='mwplayer1' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www.muziekweb.nl/audio/fms3test/emff_mw.swf' /><param name='quality' value='high' /><param name='FlashVars' value='playlist="+fragment+"&amp;autostart=no'><embed src='http://www.muziekweb.nl/audio/mwplayer.swf' quality='high' width='250' height='85' name='mwplayer1' align='middle' allowScriptAccess='always'	FlashVars='playlist="+fragment+"&amp;autostart=no' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /></object>";
	//el.innerHTML = player;
	
	el.setStyle('display','block');

}