$(document).ready(function(){
    
    //- INITIALISATION ---------------------------------------------------------------------------
	    
    $('#connu-info').css('display','none').val('');
		
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 30, /* padding for each side of the picture */
		opacity: 0.40, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){} /* Called when prettyPhoto is closed */
	});
	
	$.datepicker.regional['fr'];
    $("#date-deb,#date-fin").datepicker({showOn:'both',buttonImage:'/images/admin/calendar.png',dateFormat:'dd/mm/yy',buttonImageOnly:true});
	
    $("#arrivee").datepicker({
		showOn:'both',
		buttonImage:'/images/admin/calendar.png',
		dateFormat:'dd/mm/yy',
		buttonImageOnly:true,
		onClose: function(){				
			var date = $(this).val();			
			var aDate = date.split('/');			
			
			$("#fday").val( aDate['0'] );
			$("#fmonth").val( aDate['1'] );
			$("#fyear").val( aDate['2'] );
		}
	});
	
	$("#depart").datepicker({
		showOn:'both',
		buttonImage:'/images/admin/calendar.png',
		dateFormat:'dd/mm/yy',
		buttonImageOnly:true,
		onClose: function(){				
			var date = $(this).val();
			var aDate = date.split('/');
			
			$("#tday").val( aDate['0'] );
			$("#tmonth").val( aDate['1'] );
			$("#tyear").val( aDate['2'] );
		}
	});
    
    
    
        //- Menu principal version lavalamp        
        $(".menu").lavaLamp({speed: 400,click: function(event, menuItem) {return false;}});
		
		if( $('.SlideTab').size() ){			
			$('.SlideTab').tabSwitch('create', {type: 'toggle', toggle: 'fade', height: 362, width: 790});
			$('.SlideTab').tabSwitch('startAuto',{interval: 5000});			
		}
		
		if( $('.slidetab1').size() ){			
			$('.slidetab1').tabSwitch('create', {type: 'toggle', toggle: 'fade', height: 259, width: 193});
			$('.slidetab1').tabSwitch('startAuto',{interval: 5000});			
		}
		
		if( $('.slidetab2').size() ){
			$('.slidetab2').tabSwitch('create', {type: 'toggle', toggle: 'fade', height: 129, width: 193});
			$('.slidetab2').tabSwitch('startAuto',{interval: 5000});
		}
		
		if( $('.slidetab3').size() ){
			$('.slidetab3').tabSwitch('create', {type: 'toggle', toggle: 'fade', height: 129, width: 193});
			$('.slidetab3').tabSwitch('startAuto',{interval: 5000});
		}
    
    
    //--------------------------------------------------------------------------------------------
    
    
    //- EVENEMENTS -------------------------------------------------------------------------------
    
        //- ONCHANGE ----------------------------------------------------------------------------
        
			$('#connu').change(function(){
				if($(this).val() == 1 || $(this).val() == 2 || $(this).val() == 6 || $(this).val() == 7){
					$('#connu-info').fadeIn();
				}else{
					$('#connu-info').fadeOut();
				}
			});
        
        //---------------------------------------------------------------------------------------
    
        //- ONCLICK ----------------------------------------------------------------------------
        
			$("#current-diapo").click(function(){
				
				var $size = $(".diapo img").size();				
				var id = parseInt( $(this).attr('alt') );
				
				( id != $size ) ? newId = id+1 : newId = 1;
				
				var newSrc = $(".diapo img[alt='"+newId+"']").attr('src');				
				$("#current-diapo").attr('src', newSrc).attr('alt', newId);
				
			});
        
			$("#current-diapo1").click(function(){
				
				var $size = $(".diapo1 img").size();				
				var id = parseInt( $(this).attr('alt') );
				
				( id != $size ) ? newId = id+1 : newId = 1;
				
				var newSrc = $(".diapo1 img[alt='"+newId+"']").attr('src');				
				$("#current-diapo1").attr('src', newSrc).attr('alt', newId);
				
			});
        
			$("#current-diapo2").click(function(){
				
				var $size = parseInt( $(".diapo2 img").size() );				
				var id = parseInt( $(this).attr('alt') );
				
				( id != ( $size + 4 ) ) ? newId = id+1 : newId = 5;
				
				var newSrc = $(".diapo2 img[alt='"+newId+"']").attr('src');				
				$("#current-diapo2").attr('src', newSrc).attr('alt', newId);
				
			});
        
        //---------------------------------------------------------------------------------------
        
    //--------------------------------------------------------------------------------------------
	
	//-- Tests formulaire de contact -------------------------------------------------------------
	
		$("#envoyer").live("click", function(){
			$("#nom").css("border","1px solid #B09580");
			$("#prenom").css("border","1px solid #B09580");
			$("#tel").css("border","1px solid #B09580");
			$("#email").css("border","1px solid #B09580");
			
			var nom 	= $("#nom").val();
			var prenom 	= $("#prenom").val();
			var tel 	= $("#tel").val();
			var email 	= $("#email").val();
			var message = "";
			var erreur 	= 0;
			
			if(nom == ''){
				message += 'Le champs "Nom" est requis.<br />';
				$("#nom").css("border","1px solid #AF4C4C");
				erreur++;
			}
			if(prenom == ''){
				message += 'Le champs "Prenom" est requis.<br />';
				$("#prenom").css("border","1px solid #AF4C4C");
				erreur++;
			}
			if(tel == ''){
				message += 'Le champs "T&eacute;l." est requis.<br />';
				$("#tel").css("border","1px solid #AF4C4C");
				erreur++;
			}
			if(email == ''){
				message += 'Le champs "Email" est requis.<br />';
				$("#email").css("border","1px solid #AF4C4C");
				erreur++;
			}
			
			if(erreur > 0){
				$("#check").addClass('erreur').empty().html(message);
			}else{
				$("form#contact").submit();
			}
			
		});
	
	//--------------------------------------------------------------------------------------------
    
});