$(window).load(function() {
	$('#slideshow').css('display','block');
	
	// Init slideshow
	$('#slideshow img:first').addClass('active');
	
	// Fadein slideshow topimages
	$('div#slideshow').animate({
		opacity: 1
	},1000);
});

// Slideshow topimages
function slideSwitch() {
	var $active = $('#slideshow img.active');
	
	if ($active.length == 0 ) $active = $('#slideshow img:last');
	
	var $next =  $active.next().length ? $active.next()
		: $('#slideshow img:first');
	
	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
	});
}

$(function() {
	setInterval( "slideSwitch()", 6500 );
});

$(document).ready(function() {  	
	// External linking
	$('a.extern').click(function() { 
		window.open(this.href);
		return false;
	});
	
  // Show project title on hover
  $(".project").hover(function () {
			$(".title",this).animate({
				bottom: '0'
		},300);
		},function(){
			var titleH = $(".title",this).height()+1;
			$(".title",this).animate({
	  			bottom: '-'+titleH+'px'
		},150);
	});
	
	// Contactform validation
	$.tools.validator.localize("nl", {
		'*'			: 'Corrigeer deze waarde',
		':email'  	: 'Vul a.u.b. een geldig e-mailadres in',
		':number' 	: 'Vul a.u.b. een getal in',
		':url' 		: 'Vul a.u.b. een geldige URL in',
		'[max]'	 	: 'Vul a.u.b. een waarde in die kleiner is dan $1',
		'[min]'		: 'Vul a.u.b. een waarde in die groter is dan $1',
		'[required]': 'Dit is een verplicht veld'
	});
	
	if ($('#contactform').length ) {
		// Form validation
		$("#contactform").validator({
			speed: 500,
			lang: 'nl'
		});
	};
});

// Galleria
if($('#gallery').length) {
	$('#gallery').galleria({
		width: 510,  	// breedte foto + 10px
		height: 445,	// hoogte foto + 70px
		transition_speed: 750,
		transition: 'fade',
		show_counter: false,
		carousel_speed: 750,
		clicknext: true,
		thumb_quality: true,
		
		// Adding keyboard control
		extend:function() {
			this.attachKeyboard({
			left: this.prev,
			right: this.next
			});
		}	
	});	
};
