/* This script by $criptMaster B Duall 2011 */
/* JQuery 1.6.1 needed */
/* www.duall.be */

////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function(){
	SIZnav();
	SIZie();
	SIZinfoSchools();
	SIZform();
	SIZvalidate();
	SIZslide();
	SIZ_dl_showHide();
});
////////////////////////////////////////////////////////////////////////////////////////////


function SIZie() {
	
	if ($('div.ie').length) {
		$('div.ie').html("<p>U gebruikt een oude en onveilige versie van Internet Explorer.</p>\n<p>U bekijkt deze site dan ook best met een andere browser zoals <a href='http://www.microsoft.com/windows/internet-explorer/default.aspx'>Internet Explorer 9</a>, <a href='http://www.mozilla-europe.org/nl/firefox/'>Firefox</a> of <a href='http://www.apple.com/safari'>Safari</a>.</p>"	)
		};
}

////////////////////////////////////////////////////////////////////////////////////////////

function SIZnav() {
	$('ul#main_nav li ul').hide();
	$('body#merci ul#main_nav li a.active').next('ul').show();
	$('ul#main_nav li ul li a.active').parent().parent().show();

	sectieActive = $('a.active:first').text();
	sectieActive = sectieActive.split(' ').join('-').toLowerCase();
	$('body').addClass(sectieActive);
	
}

////////////////////////////////////////////////////////////////////////////////////////////

function SIZinfoSchools(){

	SIZdivInfo();
	SIZh4Klik();
	SIZopenExtraInfo();
	SIZcleanEmptyGroep();

	function SIZdivInfo(){
		$("div.schoolInfo").hide();
	}
	
	function SIZh4Hover(){
	$("div.school h4").hover(
		function(){
			$(this).toggleClass("hover");
		},
		function(){
			$(this).toggleClass("hover");
		});
	}
	
	function SIZh4Klik(){

	$("div.school h4 a").click(function(){
	 	var infoDiv = $(this).parents("div.school").children("div.schoolInfo");
	 	var extraDiv = $(this).parents("div.school").children("div.schoolExtraInfo");
		if (infoDiv.is(":visible")){
				infoDiv.slideUp();
 				extraDiv.hide();
 				return false;
			} else {
				$("div.schoolInfo").slideUp();
				infoDiv.slideDown();
				return false;

			}
		});
	}
	
	function SIZdivExtraInfo(){

		$("div.school").each(function(){
			var titel = $(this).find("h4").html();
			$("div.schoolExtraInfo").hide();
		});
	}
	
	function SIZopenExtraInfo() {
	
		$("div.school a.meerInfoLink").click(function(){
			var extraDivHTML = $(this).parents().children('div.schoolExtraInfo').html();
			$('body').append('<div class="mask"></div>')
			$('<div class="popup ExtraInfo"></div>').appendTo('div.mask').parent().hide();
			$('div.popup').html(extraDivHTML);
			$('div.popup').prepend('<a href="#" class="sluit">&times;</a>');

			windowH = $(document).height();
			$('div.mask').height(windowH);
			$('div.mask').fadeIn();
			SIZclosePopup();
			return false;
		});
	}
	

	
	function SIZcleanEmptyGroep(){
		$("div.groep").each(function(){
			if ($(this).find("h4").size() < 1) {
				$(this).remove();
			}
		});
	}
	
}
////////////////////////////////////////////////////////////////////////////////////////////

function SIZclosePopup() {
$("a.sluit").click(
	function(){
	$('div.mask').fadeOut('slow',function(){
		$(this).remove();
	
	});
	return false;
	
	}
)}

////////////////////////////////////////////////////////////////////////////////////////////

function SIZform() {
	
	$("#SIZcontactForm").hide();
	
	$('p.formOpen a').click(function(e) {
		e.preventDefault();
		formLink = $(this).attr('href');
		
		$('body').append('<div class="mask"></div>');
		$('<div class="popup Form" id="SIZcontactForm"></div>').appendTo('div.mask').parent().hide();
		
		$("#SIZcontactForm").empty().load(formLink+" div#loadForm", function(){
			
			$('h4.open input.checkbox').click(function(){
					
				if($(this).is(':checked')){
					$(this).parent().next('fieldset').slideDown();
				} else {
					$(this).parent().next('fieldset').slideUp();
					}
			});	
			$('#FSsubmit').append('<button type="submit">Verzend</button>');	
			/*
			$('div.formSchoolList').each(function(){
				if ($(this).find('li').size() < 1) {
					$(this).remove();
				}
			});
			*/

		$('div.popup').prepend('<a href="#" class="sluit">&times;</a>');
		
		windowH = $(document).height();
		$('div.mask').height(windowH);
		$('div.mask').fadeIn();
		
		SIZclosePopup();
		SIZvalidate();
		});
	});
	
}

////////////////////////////////////////////////////////////////////////////////////////////
//opgelet Packed version niet gebruiken voor IE

function SIZvalidate() {
	$("div#loadForm form").validate({ 
		rules: {
		NAAM: "required",
		CODE: "required",
		GEBOORTEJAAR: "required",
                AANTAL_PERSONEN_OPEN: "required",
		MAIL: {
		       required: true,
		       email: true
		     			}
	  		},
		messages:{
		MAIL: {
			required: "&uarr; we hebben jouw e-mail nodig om je te contacteren",
			email: "&uarr; e-mail moet in het volgende formaat: naam@domein.com"
			},
		NAAM: {
			required: "&uarr; sorry, maar we hebben jouw naam en voornaam nodig"
			},
		CODE: {
			required: "&uarr; sorry, maar we hebben jouw postcode nodig"
			},	
		GEBOORTEJAAR: {
			required: "&larr; graag invullen"
			},
		AANTAL_PERSONEN_OPEN: {
			required: "&larr; graag invullen"
			}
			
			}
		});

	$("#SIZcontactForm.studienamiddag form").validate({ 
		rules: {
		NAAM: "required",
		STRAAT: "required",
		CODE: {
				required: true,
				digits: true,
				maxlength: 4,
				minlength: 4
		
				},
		PLAATS: "required",
		MAIL: {
		       required: true,
		       email: true
		     			}
	  		},
		messages:{
		MAIL: {
			required: "&uarr; we hebben uw e-mail nodig om u te contacteren",
			email: "&uarr; e-mail moet in het volgende formaat: naam@domein.com"
			},
		CODE: {
			required: "&uarr; graag uw postcode invullen",
			digits: "&uarr; postcode moet uit 4 getallen bestaan",
			maxlength: "&uarr; postcode moet uit 4 getallen bestaan",
			minlength: "&uarr; postcode moet uit 4 getallen bestaan"
			},
		PLAATS: {
			required: "&uarr; graag uw woonplaats invullen"
			},
		STRAAT: {
			required: "&uarr; graag uw straatnaam invullen"
			},
		NAAM: {
			required: "&uarr; sorry, maar we hebben uw naam en voornaam nodig"
			}
			
			}
		});
}

////////////////////////////////////////////////////////////////////////////////////////////

function SIZslide(){
	
	if($('.slideshow').length) {	
	$('.slideshow').cycle({
		fx: 'scrollLeft',
		pause: 1,
		timeout: 4000
	});	
	}
}

////////////////////////////////////////////////////////////////////////////////////////////


function SIZ_dl_showHide() {
$("dd").hide();
$("dt").wrapInner("<span></span>");
$("dt span").addClass("dtBody");
$("dt").prepend("<span class='pijl'>&rarr; </span>");
 
$("dt").hover(
	function(){
		$(this).addClass("dtHover");
		$(this).children("span.pijl").remove();
		$(this).prepend("<span class='pijl'>&darr; </span>");
		},
	function(){
		$(this).removeClass("dtHover");
		if($(this).hasClass("dtActive")){
		} else {
		$(this).children("span.pijl").remove();
		$(this).prepend("<span class='pijl'>&rarr; </span>");
		}
	}
);
 
$("dt").toggle(
	function(){
		$(this).addClass("dtActive");
		$(this).children("span.pijl").remove();
		$(this).prepend("<span class='pijl'>&darr; </span>");
		$(this).next("dd").slideDown();
	},
	function(){
		$(this).removeClass("dtActive");
		$(this).children("span.pijl").remove();
		$(this).prepend("<span class='pijl'>&rarr; </span>");
		$(this).next("dd").slideUp();
	});
}
