

//***************************************************
// setting zoom and form clearance
//***************************************************

function SetZoom() {
	//--- add a colorbox wrapper for custom alerts
	var colorwrap = $("<div />").css({display: "none"});
	var color = $("<div />").attr("id", "inline_alert").appendTo(colorwrap);
	var trigger = $("<a />").attr("href", "#").attr("class", "triggerme").attr("id", "triggerme").css({display: "none"});
	$('body').append(colorwrap);
	$('body').append(trigger);
	
	//--- setup the colorboxzoom itself
	$('a.zoom').colorbox({opacity:0.5});
	$("a#mlr-alert").colorbox({opacity:0.5, width:"420px", inline:true, href:"#inline_alert"});
	//--- colorbox used for collezione collection
	$("a#triggerme").colorbox({
		opacity  	: 0.5, 
		inline 	 	: true, 
		href 	 	: "#inline_alert",
		onClosed 	:	function(){ $('#inline_alert').html('') }
	});	
	
	$("#gmaps").colorbox({
		opacity : 0.5, 
		innerWidth:'575px', 
		innerHeight:'425px', 
		iframe:true
	});
	
}

function SetForm() {
	$('input:text').clearingInput();
	$('textarea').clearingInput();
}


//***************************************************
// equal height
//***************************************************

function SetHeights(wrap) {

	var tl = 0; //tallest
	var hg = 0; //height
	
	wrap.each(function() {
		
		hg = $(this).height();
		//alert(hg);
		if(hg > tl) {
			tl = hg;
		}
	});				
	
	wrap.height(tl);

}


//***************************************************
// setting zoom and form clearance
//***************************************************

jQuery.easing.def = "easeInOutQuint";

$(document).ready(function() {
		
	$('#sitewrap h1').click(function(e){
		location.href='/';
		e.preventDefault();
	}).css('cursor','pointer');		
	
	//--- trigger link for inline alerts
	$('#triggerme').hide();
	$('.jhideme').hide();

	$(document).pngFix();
	SetZoom();
	SetForm();
	
	//------------------------------------------------ MAINNAV
	
	var base = $('base').attr('href');
	
	$('#mainnav').append('<li><a href="'+base+'werkwijze/aanmeldformulier/">Aanmelden</a></li>');
	
	//------------------------------------------------ SUBNAV
	
	$('.subnav').easyListSplitter();
	$('.subnav a').prepend('&rsaquo; ');
	
	//------------------------------------------------ SITEMAP
	
	$('#sitemap').find('li:first').addClass('first').end().find('ul li a').prepend('&rsaquo; ');
	SetHeights($('#sitemap>li'));
	
	//------------------------------------------------ SCROLLPANE
	if($('#scrollpain').length>0){
		var setheight = $('#scrollpain').parent('.section').height();
		var scrollapi = $('#scrollpain').height(setheight).jScrollPane({
				verticalGutter: 10
			}).data('jsp');
	}
	//------------------------------------------------ SECTION
	
	var t=300
	var s=0
	
	$('.section').hide().each(function(i){
		s=t*i;	
		var thisli = $(this);		
		setTimeout( function(){
			thisli.fadeIn(1200)
		}, s);
	
	});
	
	//------------------------------------------------ BIGIMG
	
	if($('#bigimg').attr('rel')=='yes') {
		var bgheight = -1*($('#bigimg').height());
		$('#bigimg').css({bottom:bgheight }).animate({bottom:0}, 2600, "easeOutElastic");
	}
	
	//------------------------------------------------ AGENDA
	
	function agenda_hover(){
		$('.agenda li').hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		})
	}
	agenda_hover();
	
	$('.agenda li a, #agendanav li a').live('click',function(){
		return false;
	});
	
	// -- get calendar items when clicked
	$('#agendanav li').click(function(){
	
		var _container 	= $('#agendawrap');
		var url 		= $(this).find('a').attr('href');
		
		$('#agendanav li a').removeClass('act');
		$(this).find('a').addClass('act')
		
		_container.fadeTo(400, 0.2,function(){
		
			$.get(url, function(data){
				_container.html(data).fadeTo(400,1,function(){
					scrollapi.reinitialise();
				});
				agenda_hover();
			
			});
		
		})
		
	});
	
	// -- get single item from list
	$('.agenda li').live('click',function(){
		
		var url = $(this).find('a').attr('href');
		$.get(url, function(data){
		
			$('#inline_alert').html(data);
			$('#triggerme').trigger('click');
		
		})
	
	});


	if($('#agendawrap').length>0){
		var agrel = $('#agendawrap').attr('rel');
		setTimeout(function(){
			$('#agendanav li[rel="'+agrel+'"]').trigger('click');
		},800);
	}
	
	//------------------------------------------------ SEND CONTACTFORM

	$('input.subm').hover(function() {
	  $(this).addClass('hover');
	}, function() {
	  $(this).removeClass('hover');
	});
	
	$('input.subm').bind('click',function(){
		$(this).parent().addClass('loading');						 
	});	

	$('#contactform').ajaxForm({
			beforeSubmit: BeforeSendCnt,
			success		: SendSuccesCnt,
			clearForm	: false
	});

	function BeforeSendCnt(resp, stat)  {
		$('#contactform input[value=]').addClass('empt');
	}	
	
	function SendSuccesCnt(resp, stat)  {
		
		$('.loader').removeClass('loading');
		
		var json = eval('(' + resp + ')');
		
		if (json.send=='yes') {
			//--- als bericht verzonden is melding geven en alles resetten
			$('#inline_alert').html(json.msg);
			$('#triggerme').trigger('click');
			//$('#mlr-alert').html(json.msg).fadeIn('slow', function(){ setTimeout( "$('#mlr-alert').fadeOut('slow')" ,3000)  });
			$('#contactform input').removeClass('empt');
			$('#contactform').resetForm();
			SetForm();
		}else{
			//--- als er een error is deze zichtbaar maken
			$('#contactform input.empt').clearingInput();
			$('#contactform input').removeClass('empt');
			$('#inline_alert').html(json.msg);
			$('#triggerme').trigger('click');
		}		
		
	}
	
	//------------------------------------------------ AANMELDFORMULIER
	
	$('input[name^="loc"]').change(function(){
		
		$('input[name^="loc"]').each(function(){
		
			var chk = $(this).attr('checked');
			
			if(chk===false){
				$(this).parent().next().find('li').each(function(){
					$('input',this).attr('checked',false);
				});
			}		
		
		})
			
	});
	
	//-------------------------------------------------------------------//		

	$('a.noclick').bind('click',function(e){
		e.preventDefault();
	});
	
	//-------------------------------------------------------------------//

});
