// JavaScript Document
$(document).ready(function() {
	var count=1;
	$('#slider').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 0, 
		next:   '.next', 
		prev:   '.prev' 
		});
	
	$('#direct1').click(function() {
		$('#slider').cycle(0);
		count = 1;
		checkActive(count);
		return false; 
	});
	
	$('#direct2').click(function() {
		$('#slider').cycle(2); 
		count = 3;
		checkActive(count);
		return false; 
	});
	
	$('#direct3').click(function() {
		$('#slider').cycle(4); 
		count = 5;
		checkActive(count);
		return false; 
	});

	$('.next').click(function(){
		if(count == 6){count = 1;}else{count++;}
		checkActive(count);
	})
	
	$('.prev').click(function(){
		if(count == 1){count = 6;}else{count--;}
		checkActive(count);
	});
	
	$("#slider a").fancybox();
	
	function checkActive(a){
		$('.file a').each(function(){
			$(this).css({
				'font-weight'	: 'normal',
				'color'			: '#a9acb0'
			})
		})
		p = Math.ceil((a/2)-1);
		$('.file a.foto:eq('+p+')').css({
			'font-weight'	: 'bold',
			'color'			: '#f39200'
		})
	}
})

function checkContactValues(lang){
   
    //define fields
    var firstname = document.getElementById('voornaam');
    var lastname = document.getElementById('naam');
    var city = document.getElementById('gemeente');
    var tel = document.getElementById('tel');
    var email = document.getElementById('email');
   
    var ok = true;
    var contactform = document.getElementById("formcontact");
   
    //define fields array
    var fields = new Array(firstname,lastname,city,tel,email);
   
    //comments in different languages
    var commentnl = new Array("Gelieve uw voornaam in te vullen.","Gelieve uw familienaam in te vullen.", "Gelieve uw stad in te vullen.", "Gelieve uw telefoonnummer in te vullen.", "Gelieve een correct e-mailadres in te vullen.");
    var commentfr = new Array ("Entrez votre prénom, s'il vous plaît.", "Entrez votre nom de famille, s'il vous plaît.", "Entrez votre ville, s'il vous plaît.","Entrez votre numéro de téléphone, s'il vous plaît.","Entrez une adresse e-mail correcte, s'il vous plaît.");
    var commenten = new Array("Please fill in your first name.", "Please enter your surname.", "Please fill in your address.", "Please fill in your postal code.", "Please enter your city.", "Please enter your telephone number.", "Please enter a correct e-mail address.");
   
    //check language and set comment
    eval("var comment = comment"+lang);
   
    //comment if needed
    for(i=0; i<fields.length; i++){
        if(fields[i] != email){
            if(fields[i].value.length==0){alert(comment[i]); return false}
        } else {
            if(!validMail(email.value)){alert(comment[i]); return false}
        }
    }
   
    //if ok
   
		return true;

}

/*function checkContactValues(){
	
	var voornaam = document.getElementById('voornaam');
	var naam = document.getElementById('naam');
	var tel = document.getElementById('tel');
	var email = document.getElementById('email');
	var gemeente = document.getElementById('gemeente');

	if(voornaam.value.length==0){window.alert("Please enter your first name.");return false;}
	if(naam.value.length==0){window.alert("Please enter your name.");return false;}
	if(tel.value.length==0){window.alert("Please enter your telephone number.");return false;}
	if(!validMail(email.value)){window.alert("Please enter a correct e-mail address");return false;}
	if(opmerkingen.value.length==0){window.alert("Please enter a city.");return false;}

	return true;
}*/
//contact mail validate
function validMail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){return false;}
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if(str.indexOf(at,(lat+1))!=-1){return false;}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if(str.indexOf(dot,(lat+2))==-1){return false;}	
	if(str.indexOf(" ")!=-1){return false;}
	return true;		
}
