function diaporama() {
	photocount = 0;
	mynbrphotos = $('#nbrphotos').val();
	if (mynbrphotos > 1) {	
		$('#mainphoto').everyTime(4500,function() {
				photocount = photocount + 1;
				$(this).fadeOut("slow", function () {
					$(this).attr({ 
					src: $("#miniphotohide" + photocount).attr("src")
					});
					$(this).fadeIn("slow");
				 });
				
				if (photocount == mynbrphotos ) {
					photocount = 0;
				}
				
		});	
	}
}


$(document).ready(function(){

photocount = 0;
diaporama();



	$('[@id^=miniphoto_]').mouseover(function(){
		_idselected = $(this).attr("id");
		_strlength = _idselected.length;
		_idselected = _idselected.substring(10, _strlength);	
		$('#mainphoto').stopTime();
		$('#mainphoto').attr({ 
        	src: $("#miniphotohide" + _idselected).attr("src")
        });		
	});

	$('[@id^=miniphoto_]').mouseout(function(){
		diaporama();		
	});	

	$('#mainphoto').mouseover(function(){
		$('#mainphoto').stopTime();
	});

	$('#mainphoto').mouseout(function(){
		diaporama();
	});	

	$('#box_fichephoto_titre').click(function(){									  
		$('#box_fichevideo').hide();
		$('#box_fichephoto').show();
		/*$(this).attr({
			'class': "box_fichephoto_titre_active"
		});
		$('#box_fichevideo_titre').attr({
			class: "box_fichevideo_titre"
		});*/
		$(this).removeClass().addClass('box_fichephoto_titre_active');
		$('#box_fichevideo_titre').removeClass().addClass('box_fichevideo_titre');
	});

	$('#box_fichevideo_titre').click(function(){
		$('#box_fichephoto').hide();
		$('#box_fichevideo').show();
		/*$(this).attr({ class: "box_fichevideo_titre_active"});
		$('#box_fichephoto_titre').attr({ class : "box_fichephoto_titre" });*/
		$(this).removeClass().addClass('box_fichephoto_titre_active');
		$('#box_fichephoto_titre').removeClass().addClass('box_fichevideo_titre');
	});

	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var langVal = $("#lang").val();
		var annoncetxt = $("#annoncetxt").val();
		
		var nomVal = $("#nom").val();
		if(nomVal == '') {
			if (langVal == 'fr') {
				$("#nom").after("<div class=\"error\">Vous avez oublié d'entrer votre nom.</div>");
			} else {
				$("#nom").after("<div class=\"error\">U bent vergeten uw naam te vermelden.</div>");
			}
			hasError = true;
		}
		
		var emailVal = $("#email").val();
		if(emailVal == '') {
			if (langVal == 'fr') {
				$("#email").after("<div class=\"error\">Vous avez oublié d'entrer votre adresse E-mail.</div>");
			} else {
				$("#email").after("<div class=\"error\">U bent vergeten uw e-mail adres te vermelden.</div>");
			}
			hasError = true;
		} else if(!emailReg.test(emailVal)) {
			if (langVal == 'fr') {
				$("#email").after("<div class=\"error\">Veuillez entrer une adresse E-mail valide.</div>");
			} else {
				$("#email").after("<div class=\"error\">Gelieve een geldig e-mail adres te vermelden.</div>");
			}
			hasError = true;
		}
		
		var telephoneVal = $("#telephone").val();
		if(telephoneVal == '') {
			if (langVal == 'fr') {
				$("#telephone").after("<div class=\"error\">Vous avez oublié d'entrer votre numéro de téléphone.</div>");
			} else {
				$("#telephone").after("<div class=\"error\">U bent vergeten uw telefoonnummer te vermelden.</div>");
			}
			hasError = true;
		}
		
		var questionVal = $("#question").val();
		if(questionVal == '') {
			if (langVal == 'fr') {
				$("#question").after("<div class=\"error\">Vous avez oublié d'entrer votre question.</div>");
			} else {
				$("#question").after("<div class=\"error\">U bent uw vraag vergeten te vermelden.</div>");
			}
			hasError = true;
		}
		
		var toVal = $("#to").val();
		var subjectVal = $("#subject").val();
		
		var retourVal = 0;
		if(document.getElementById('retour').checked == true) {
			var retourVal = 1;
		}
		
		
		if(hasError == false) {
			$(this).hide();
			
			$("#sendEmail").append('<img src="pictures/loading.gif" alt="Loading" id="loading" />');
			
			$.post("includes/sendemail.php",
   				{ to: toVal, sujet: subjectVal, nom: nomVal, email: emailVal, telephone: telephoneVal, question: questionVal, retour: retourVal, lang: langVal, annoncetxt: annoncetxt },
   					function(data){
						$("#sendEmail").slideUp("normal", function() {
							if (langVal == 'fr') {
								$("#sendEmail").before("<p>L'E-mail a été envoyé.</p>");
							} else {
								$("#sendEmail").before("<p>De e-mail werd verstuurd.</p>");
							}
						});
   					}
				 );
		}
		
		return false;
	});	






});

