// JavaScript Document

//JQUERY FUNCTIONS:
$(function() {
		
	$(this).find("a.selected").css("color","red");
	
	$("form[name=contact]").submit(function(e){
		if ($("form[name=contact] input[name=name]").val().length==0) {
			alert("Vous devez entrer un nom");
			return false;
		}
		if ($("form[name=contact] input[name=tel]").val().length==0) {
			alert("Vous devez entrer un téléphone");
			return false;
		}
		if ($("form[name=contact] textarea[name=msg]").val().length==0) {
			alert("Vous devez entrer un message");
			return false;
		}
		return true;
	});
	
	if ($("input[name=date]").length) {
		$('.datepickerDiv').datepick({inline:true,minDate: +14,onSelect: function(dates) { $("input[name=date]").val(dates); }});
		$('.datepicker').datepick({minDate: +14,onSelect: function(dates) { $("input[name=date]").val(dates); $('form[name=service]').submit(); }});
		var d1 = new Date();
		var num = d1.valueOf();
		num += 1000 * 60 * 60 * 24 * 14;
		var myDate = (new Date(num));
		$("input[name=date]").val(myDate);
	}
	
	$('select[name=cat-list]').change(function(e){
		e.preventDefault();
		var cat = $("select[name=cat-list] option:selected").val();
		var pselect = "select"+cat;
		$('#'+pselect).show().removeClass("plist");
		$('.plist').remove();
		$("select[name=cat-list]").attr("disabled","disabled");
		$("select[name=cat-list]").after(" &nbsp;<a href='compte.html'>Changer la catégorie</a>");
	});
	
	$("form[name=product]").submit(function(e){
		
		var where_to= confirm("Vous êtes sur le point de faire une demande d'achat, voulez vous continuer?");
		if (where_to== true) { return true; } else { return false; }
		 
	});
	
	$("form[name=service]").submit(function(e){
		
		var where_to= confirm("Vous êtes sur le point de faire une demande de rendez-vous, voulez vous continuer?");
		if (where_to== true) { return true; } else { return false; }
		 
	});
	
	$("#buyprod").click(function(e){
		
		var where_to= confirm("Vous êtes sur le point de faire une demande d'achat, voulez vous continuer?");
		if (where_to== true) { $("form[name=buyprod]").submit(); } else { return false; }
		 
	});
	
	$("#alogin").click(function(e){
		e.preventDefault();
		$("#formlogin").show();
		$(this).hide();
	});
	/*
    $('#flash').cycle({
		fx: 'scrollHorz',
		continuous: 1,
		timeout:0,
		speed: 20000,
		easeIn:  0,
        easeOut: 0  
	});
	*/

	
});

	
	var speed = 35;
	var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 
	
	$(window).load(function(){
		pic = $("#slider").children("img");
		numImgs = pic.length;
		arrLeft = new Array(numImgs);
	
		for (i=0;i<numImgs;i++){
	
			totalWidth=0;
			for(n=0;n<i;n++){
				totalWidth += $(pic[n]).width();
			}
	
			arrLeft[i] = totalWidth;
			$(pic[i]).css("left",totalWidth);
		}
	
		myInterval = setInterval("flexiScroll()",speed);
		$('#imageloader').hide();
		$(pic).show();
	});
	
	function flexiScroll(){
	
		for (i=0;i<numImgs;i++){
			arrLeft[i] -= 1;		
	
			if (arrLeft[i] == -($(pic[i]).width())){
				totalWidth = 0;
				for (n=0;n<numImgs;n++){
					if (n!=i){
						totalWidth += $(pic[n]).width();
					}
				}
				arrLeft[i] =  totalWidth;
			}
			$(pic[i]).css("left",arrLeft[i]);
		}
	}
