$(document).ready(function(){
	initSlideshow();
	showSub();
	initFotoslider();
	tulpenRollover();
	albumRollover();
	initFotosliderGroot();
	contact();
	
	var nJan = $('.tulp_item').size();
	
	for(var nI = 1; nI <= nJan; nI++){
		$('a[rel=lightbox_'+nI+']').lightBox({
			containerResizeSpeed: 150						 
		});	
	}
});


function initSlideshow() {
	$('#sfeer_foto').cycle({
		fx:     'fade',
		timeout: 5000,
		speed:	 2500
	});
}

function showSub() {
	$('#menu li').hover(function(){
		$(this).children('a').addClass('hover');
		$(this).children('.submenu').show();
   }, function(){
	   	$(this).children('a').removeClass('hover');
		$(this).children('.submenu').hide();
   });
}

function initFotoslider() {
	$('.fotos').cycle({
		fx:     'fade',
		timeout: 0,
		speed:	 250,
		next:   '#btn_next', 
		prev:   '#btn_prev',
		after: function(curr,next,opts) {
			$("#foto_aantal").html('Foto ' + (opts.currSlide + 1) + ' van ' + opts.slideCount);
		}
	});
}


function initFotosliderGroot() {
	$('#slider').cycle({
		fx:     'fade',
		timeout: 0,
		speed:	 250,
		next:   '#btn_next', 
		prev:   '#btn_prev',
		after: function(curr,next,opts) {
			$("#foto_aantal").html('Foto ' + (opts.currSlide + 1) + ' van ' + opts.slideCount);
		}
	});
}

function tulpenRollover() {
	$('.tulp_item').hover(function(){
		$(this).children('.tulp_afbeelding').children('.tulp_afbeelding_roll_over').show();
	   }, function(){
			$(this).children('.tulp_afbeelding').children('.tulp_afbeelding_roll_over').hide();
	   }
   );
}

function albumRollover() {
	$('.foto_item_wrapper').hover(function(){
		$(this).children('.album_foto').children('.foto_roll_over').show();
	   }, function(){
			$(this).children('.album_foto').children('.foto_roll_over').hide();
	   }
   );
}

var iconOK = '<img src="images/template/vink_oke.gif" alt="" />';
var iconError = '<img src="images/template/fout.gif" alt="" />';
var iconDisabled = '<img src="images/template/vink_leeg.gif" alt="" />';

function contact() {
	$('span.icon').html(iconDisabled);
	$('#contactformulier').validate({
		debug: true,
		rules: {
			naam: 'required',
			onderwerp: 'required',
			vraag: 'required',
			emailadres: {
				required: true,
				email: true
			}
		},
		messages: {
			naam: 'Vul a.u.b. uw naam in.',
			onderwerp: 'Vul a.u.b. een onderwerp in.',
			vraag: 'Vul a.u.b. een vraag of opmerking in.',
			emailadres: {
				required: 'Vul a.u.b. uw e-mailadres in.',
				email: 'Vul a.u.b. een geldig e-mailadres in.'
			}
		},
		errorPlacement: function(error, element) {
			error.insertAfter(element.parent().next('span'));
			element.parent().next('span.icon').html(iconError);
		},
		success: function(label) {
			label.prev('span.icon').html(iconOK);
			label.remove();
		},
		submitHandler: function(form) {
			var options = {
				url: 'requests/formulier.php',
				type: 'POST',
				success: function(data) {	
					if(data == 'goed'){
						$('#form_wrapper').html('<p>Uw bericht is succesvol verzonden.</p>');
						$('#form_wrapper').hide();
						$('#form_wrapper').fadeIn('slow');
						$('#form_wrapper').clearForm();
					} else {
						alert(data);
					}
				}
			}
			$(form).ajaxSubmit(options);
			return false;
		}
	});	
}
