window.addEvent('domready', function() {
	initNavmainHover();
	toggleGastenboek();
	clearDefaultInputs();
});


window.addEvent('load', function() {
	if ($('fotoboeknav')) initNavFotoboek();
	schokkend();
});


function validateForm(){
	
	return true;
	
}

function initNavmainHover() {
	try{
		$$('#navmain li').remove($E('#navmain li.active')).each(function(item) {
			$E('a', item).addEvents({
				'mouseenter': function() {
					item.addClass('active');
				},
				'mouseleave': function() {
					item.removeClass('active');
				}
			});
		});
	}
	catch(e){
		
	}
}

function schokkend () {
	var verloopt = new Date();
	verloopt.setHours(verloopt.getHours() + 3); 
	
	if($$('.schokkend').length >0) {
		$ES('p.verberg', 'div.schokkend').each(function(item){
			item.addEvent('click', function() {
				document.cookie = "toonschokkendefotos=1;expires="+verloopt+";path=/";
				location.reload(true);
				//$ES('p', item.getParent()).each(function(item2) {
					//item2.setStyle('display', 'none');
					//$ES('img',item2.getParent()).setStyle ('display','block');
				//});	
			});
		});
	}
}

function ajaxCall(element, actie, extra){
	var test = location.href.split('?');

	if(test.length<=1){
		var url =  location.href+'?type=105';
	}else{
		var url =  location.href+'&type=105';
	}
	
	new Ajax(url, {
		update: element,
		//Patch Daan
		//evalScripts: true, 
		postBody: {actie: actie, extra: extra }, 
			onComplete: function(){
			// doe iets
		}
	}).request();
}

function toggleGastenboek() {
	if(!$('berichttoevoegen')) return;
	
	try{
		gastenboekFormContainer = $('gastenboekformcontainer');
		berichtToevoegen = $('berichttoevoegen');
		
		sluitFormulier = $E('span.sluitformulier', 'gastenboekform');
		
		berichtToevoegen.setStyle('visibility', 'hidden');
		
		if(gastenboekFormContainer.hasClass('open'))  {
			gastenboekFormContainer.setStyle('height', 360);
		} else {
			gastenboekFormContainer.setStyle('height', '1px');
			berichtToevoegen.setStyle('visibility', 'visible');
		}
			
		berichtToevoegen.addEvent('click', function() {
			berichtToevoegen.removeEvents();
			berichtToevoegen.setStyle('visibility', 'hidden');
			gastenboekFormContainer.effect('height',{
				duration: 300
			}).start(gastenboekFormContainer.scrollHeight);
		});
		
		sluitFormulier.addEvent('click', function() {
			
			berichtToevoegen.setStyle('visibility', 'visible');
	
			sluitFormulier.removeEvents();
			gastenboekFormContainer.effect('height',{
				duration: 300,
				onComplete: function() { toggleGastenboek() }
			}).start(1);
			
			gastenboekFormContainer.removeClass('open')
			
		});
	}catch(e){
		
	}
		
}

function openGastenboek () {
	
	$('gastenboekformcontainer').setStyle('height', 325);
		
}

function clearDefaultInputs() {
	/*	
	var inputfields = document.getElements('input[type=text]').extend(document.getElements('textarea'));

	inputfields.each(function(item) {
		item.defaultText = item.title;
		item.addEvents({
			'focus': function() {
				if (item.value == item.defaultText) item.value = '';
			},
			'blur': function() {
				if (item.value == '') item.value = item.defaultText;
			}
		});
	});*/
}


function clearZoekterm(el){

	if(el){
				if(el.value=='Typ hier uw zoekterm in'){
						el.value='';
				}else if(el.value==''){
					el.value=='Typ hier uw zoekterm in';
				}
	}
}


function initNavFotoboek() {
	try{
		paginas = $$('span.thumbs');
		thumbs = $$('img.thumb');
		currentpagina = 0;
		swapFotoboekPagina();
		
		/* alle pijlen uit */
		document.getElementById('buttonvorig').style.visibility = 'hidden';
		document.getElementById('buttonvolgend').style.visibility = 'hidden';
	
		/* eventueel volgende pijl aan */
		if (paginas.length > 1) {
			document.getElementById('buttonvolgend').style.visibility = 'visible';
		}
		
		/* onclick volgende */
		document.getElementById('buttonvolgend').onclick = function() { 
			
			if (currentpagina < paginas.length - 1) { 
				currentpagina ++; 
				swapFotoboekPagina() 
			} 
			
			if (currentpagina == (paginas.length - 1)) {
				document.getElementById('buttonvolgend').style.visibility = 'hidden';
			}
			
			if (currentpagina > 0 ) { 
				document.getElementById('buttonvorig').style.visibility = 'visible';
			}
			
		};
		
		/* onclick vorige */
		document.getElementById('buttonvorig').onclick = function() { 
							
			if (currentpagina > 0 ) { 
				currentpagina --; 
				swapFotoboekPagina() 
			} 
			
			if (currentpagina == 0) {
				document.getElementById('buttonvorig').style.visibility = 'hidden';		
			}
			
			if (currentpagina < paginas.length) { 
				document.getElementById('buttonvolgend').style.visibility = 'visible';
			}
			
		};
		
		for (var thumb in thumbs) {
			if (thumb/1 >= 0) {
				thumbs[thumb].id = thumb;
				thumbs[thumb].onclick = function() { swapFoto(this.id) };
			}
		}
		
		if (thumbs != '') {
			thumbs[0].className = thumbs[0].className + ' active';
		}
	}catch(e){
		
	}
}


function swapFotoboekPagina() {
	
	for (var pagina in paginas) {
		if (pagina/1 >= 0) paginas[pagina].style.display = 'none';
	}
	try{
	paginas[currentpagina].style.display = 'inline';
	document.getElementById('carousselCurrentPage').innerHTML = currentpagina + 1;
	}catch(e){
		
	}
	
}


function swapFoto(id) {
	
	for (var thumb in thumbs) {
		if (thumb/1 >= 0)	thumbs[thumb].className = thumbs[thumb].className.replace(/ active/, '');
	}
	
	document.getElementById('fotogroot').src = "../../" + thumbs[id].alt;	
	document.getElementById('onderschrift').innerHTML = thumbs[id].title;
	thumbs[id].className = thumbs[id].className + ' active';
	
}

function ge(id) {
	return document.getElementById(id);
}
