$(document).ready(function() {

	$(".scrollable").scrollable();

	$(".items img").click(function() {
		
		$('.fotos').each(function(index) {
			$(this).hide();
		});
	
		var id = $(this).attr("id").replace("show","");
		
		$('#foto' + id).show();
	
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();	
	
	// VALIDATOR
	$.validator.messages.required = "";
	$.validator.messages.email = "";
		
	$('#contactForm').submit(function() {
		$("#contactForm").validate();
		return $("#contactForm").valid();
	});
	
	$('#kanaalbotenForm').submit(function() {
		$("#kanaalbotenForm").validate();
		return $("#kanaalbotenForm").valid();
	});
	
	$('#noordzeebotenForm').submit(function() {
		$("#noordzeebotenForm").validate();
		return $("#noordzeebotenForm").valid();
	});
	
	$('#wereldwijdForm').submit(function() {
		$("#wereldwijdForm").validate();
		return $("#wereldwijdForm").valid();
	});
	
	$('#opleidingForm').submit(function() {
		$("#opleidingForm").validate();
		return $("#opleidingForm").valid();
	});
	
	
			
	$('#searchInput').formatInput();
	
	var refreshIntervalId = setInterval ( "loophomepage()", 6000 );
	//loophomepage();
	
	$(".hpitems").hover(function () {
		clearInterval(refreshIntervalId);

   		setinactive();
   		var id = $(this).attr("id").replace("hpitem","");
   		
   		$("#hpitem"+id).addClass("active");
		
		var fotourl = $('#foto' + id).val();
		$('#imagehp').attr("src", fotourl);
		
		var link = $('#link' + id).val();
		$('#hpNavMoreLink').attr("href", link);
		
		var titel = $('#titel' + id).val();
		var subtitel = $('#subtitel' + id).val();
		var titel = titel + subtitel;
		
		$('#bloktitel').html(titel);
	});
	
	$(".thumb").hover(function () {   	
	
		$('.img').each(function(index) {
			$(this).hide();
		});
   		
   		var id = $(this).attr("id").replace("thumb","");
   		
   		$('#img' + id).show();
   		
		return false;
		
	});
	
	$(".kijker").click(function () {   
	
		var id = $(this).attr("id").replace("kijker","")
   		
   		if($('#indekijker' + id ).hasClass("open"))
   		{
   			$('#indekijker' + id ).removeClass("open");
   		}
   		else
   		{
   			$('#indekijker' + id ).addClass("open");
   		}
   		
		return false;
		
	});

	
	$(".vraag").click(function () {   	
		
		var id = $(this).attr("id").replace("vraag","");  		
		
		if($(this).hasClass("open"))
   		{
   			$(this).removeClass("open");   
   			$('#antwoord' + id).hide();
   		}
   		else
   		{						
			$('.antwoord').each(function(index) {
				$(this).hide();
			});
			
			$('.vraag').each(function(index) {
				$(this).removeClass("open");
			});
			
			$('#vraag' + id).addClass("open");
			$('#antwoord' + id).show();
		}
   		
		return false;
		
	});	

});

$.fn.formatInput = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
		
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

function loophomepage ( )
{
  $('.hpitems').each(function(index) {
  	var check = $(this).hasClass("active");
  	if(check)
  	{
  		var id = $(this).attr("id").replace("hpitem","");  		
  		
		id++;
		if(id > 6)
		{
			id = 1;
		}	

		$(this).removeClass("active");
		$("#hpitem"+id).addClass("active");
		
		var fotourl = $('#foto' + id).val();
		$('#imagehp').attr("src", fotourl);
		
		var link = $('#link' + id).val();
		$('#hpNavMoreLink').attr("href", link);
		
		var titel = $('#titel' + id).val();
		var subtitel = $('#subtitel' + id).val();
		var titel = titel + subtitel;
		
		$('#bloktitel').html(titel);
		return false;
  	}
  });
}

function setinactive ( )
{
  $('.hpitems').each(function(index) {
  	$(this).removeClass("active");
  });
}

