// ajuste le  ratio de l'image hauteur largeur

function adjustRatio(img){
	if($('body').height() < img.height()) {
        img.height('100%');
        img.width('auto');
    }

    if($('body').width() > img.width()){
        img.width('100%');
        img.height('auto');
    }
}

$(document).ready(function(){
	$(window).resize(function(){
  		adjustRatio($('.slider1Image img'));
	});
})

$(window).load(function(){
	$('.slider1Image img').css("visibility", "visible"); 
  	adjustRatio($('.slider1Image img'));
});

// ajuste le  ratio de l'image hauteur largeur
	


//**** hauteur home ***************//

	$(document).ready(function() {
						
			///alert($(window).height());						
			if($(window).height() > 500) 
			{
				var h = $(window).height();
				$('#global.home').css('margin-top', (h/2)-200 + "px");
			}
			else
			{
				$('#global.home').css('margin-top', 'auto');
			}
	});

	$(window).resize(function() {
					
		if($(window).height() > 500) 
		{
			var h = $(window).height();
			$('#global.home').css('margin-top', (h/2)-200 + "px");
		}
		else
		{
			$('#global.home').css('margin-top', 'auto');
		}
	});
	
//**** hauteur home ***************//


/* menu */
function mainmenu(){
$(" #arbo ul ul ").css({display: "none"}); // Opera Fix
$(" #arbo ul li").hover(function(){
        var q = $(this).find('ul:first').queue();
        if (q && (q.length > 0))
            return true;

		$(this).find('ul:first').css({visibility:"visible", display:"none"}).fadeIn(400);

		},function(){
		$(this).find('ul:first').fadeOut(300);
		});
}

$(document).ready(function(){
	mainmenu();
});
/* menu */


// menu img home
$(document).ready(function(){
	$('#cartouches div div, #bandeau').hover(
		function() {
			$(this).addClass("current");
		},
		function() {
			$(this).removeClass("current");
		}
	);
});
// menu img home

// acces plan site
$(document).ready(function(){
	$("#transNav").css({display: "none"}); // Opera Fix
	$("#acces04 a").hover(
		function() {
			$("#transNav").slideDown(300);
		}
	);
	$("#transNav").mouseleave(
		function() {
			$(this).slideUp(200);
		}
	);
});
// acces plan site



$(document).ready(function() {
						   

	//Examples of how to assign the ColorBox event to elements.
	// popup zoom
	$(".slideshow").colorbox
	(
		{
			slideshow:true, 
			transition:"elastic", 
			slideshowSpeed:5000, 
			speed:800, 
			//iframe:true, 
			opacity:0.6,
			preloading:true,
			//width:"684px", 
			//height:"550px", 
			
			previous : "précédent",
			next : "suivant",
			close : "fermer",
			slideshowStart: "démarrer le diaporama",
			slideshowStop: "arrêter le diaporama",
			current : "image {current} sur {total}"
		}/*,
		// taille iframe auto colobox
		function () 
		{
			$('#cboxIframe').ready(function() 
			{ 			
				var w = $('#cboxIframe').contents().find('#imgzoompopup').width();
				var h = $('#cboxIframe').contents().find('#imgzoompopup').height();

				if ((!h) || (!w))
					return true;
				// taille iframe auto colobox
				$(' #colorbox, #cboxContent, #cboxWrapper, #cboxLoadedContent').width(w + 16);
				$(' #colorbox, #cboxContent, #cboxWrapper, #cboxLoadedContent').height(h + 48);
				
				$('#colorbox').css('left', ($(document).width() - $('#cboxContent').width()) / 2 + 'px');
				//$('#colorbox').css('top', ($(document).height() - $('#cboxContent').height()) / 2 + 'px');
			});
		}*/	
	);
	
	
});





/*  ------------------------------------------------*
 *			    Javascript test navigateurs         *
 *  ------------------------------------------------*/
 
// Version de navigateur
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
var version2 = navigator.appVersion;

// Javascript enable
var jvsenable = false;
if ( browser == "Microsoft Internet Explorer" && version > 3 ) jvsenable = true;
if ( browser == "Netscape" && version >= 3 ) jvsenable = true;

// print enable
var printenable = false;
if ( browser == "Microsoft Internet Explorer" && version > 3 && version2.indexOf("MSIE 4") < 0 ) printenable = true;
if ( browser == "Netscape" && version >= 3 ) printenable = true;

// detecte IE
var iedetect = true;
if ( browser == "Netscape") iedetect = false;

function SwitchImg (im,sr)
{
	if (jvsenable)
	{
		if ( document[im] != null ) document [im].src = sr;
	}
}


/*  --------------------------------------------------------------------------------------------------------------	*
 *											FONCTION AFFECTER CLASS													*
 *		<script language="JavaScript">																				*
 *		affecter_class("a01","LienMenuOn");																			*
 *		</script>																									*
 *																													*
 *		<A HREF="#" CLASS="LienMenu" ID="a01">TITRE</A>																*	
 *																													*		
 *  --------------------------------------------------------------------------------------------------------------	*/
			
		function affecter_class(obj_name,class_name)
		{
		var obj;
		
			obj = document.getElementById(obj_name);
			if (obj) 
				obj.className = class_name;
		}

/*  --------------------------------------------------------------------------------------------------------------	*
 *											FONCTION AFFECTER CLASS	POUR LISTE (01,02 etc)							*
 *																													*		
 *		affecter_class_liste('blocz',12,'blocznormal');																*
 *																													*		
 *		affecter_class_liste('id sans nombre',nombre d'objets,'style a appliquer');									*
 *																													*		
 *  --------------------------------------------------------------------------------------------------------------	*/
		function affecter_class_liste(prefixe_name, max_cpt, class_name)
		{
		var obj;
		var cpt_str;
		
			for (var i=0 ; i<=max_cpt ; i++)
			{
				if (i < 10)
					cpt_str = '0' + i;
				else
					cpt_str = i;
				obj = document.getElementById(prefixe_name + cpt_str);
				if (obj) 
					obj.className = class_name;
			}
		}

	
/*  --------------------------------------------------------------------------------------------------------------	*
 *											FONCTION AJOUTER À VOS FAVORIS											*
 *		<a href="url" title="titre"																					*
 *		onClick="javascript:bookmarksite('titre', 'url'); return(false);">											*
 *		Ajouter à vos favoris</a>																					*
 *																													*
 *  --------------------------------------------------------------------------------------------------------------	*/

function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
	}


	
	/*  --------------------------------------------------------------------------------------------------------------	*
 *											FONCTION AFFICHER DIV													*
 *		onclick="	javascript:showDiv('aff01');																	*
 *					javascript:hideDiv('aff02');																	*
 *					affecter_class('l01','current');																*
 *					affecter_class('l02','nor');																	*
 *																													*		
 *  --------------------------------------------------------------------------------------------------------------	*/

	function  showDiv(objid)
	{
	document.getElementById(objid).style.display="block";
	}
	function  hideDiv(objid)
	{
	document.getElementById(objid).style.display="none";
	}


/*  ----------------------------------------------------------------------------------------------------------	*
 *	popupfull																									*
 *	se redimensione par raport a l'ecran																		*
 *	<a href="xxxxx" onclick="popupfull(this.href,'popupall','yes','yes','60','80','10','40'); return(false);">	*
 *  <a href="fichier.htm" onclick="window.open(this.href);return false;">										*
 *  ----------------------------------------------------------------------------------------------------------	*/

	function popupfull(URL,FRAME,SCROLLBARS,RESIZABLE,WIDTH,HEIGHT,TOP,LEFT)
	{
		var param = "menubar=yes,location=yes,directories=yes,status=yes,toolbar=yes,scrollbars="+SCROLLBARS+",resizable="+RESIZABLE+",width="+((screen.width)-WIDTH)+",height="+((screen.height)-HEIGHT)+",top="+TOP+",left="+LEFT;
		window.open(URL,FRAME,param); 
	}


/*  ----------------------------------------------------------------------------------------------------------	*
 *	popupall																									*
 *	se redimensione par raport a l'ecran																		*
 *	<a href="xxxxx" onclick="popupall(this.href,'popupall','yes','yes','60','80','10','40'); return(false);">	*
 *  <a href="fichier.htm" onclick="window.open(this.href);return false;">										*
 *  ----------------------------------------------------------------------------------------------------------	*/

	function popupall(URL,FRAME,SCROLLBARS,RESIZABLE,WIDTH,HEIGHT,TOP,LEFT)
	{
		var param = "menubar=no,location=no,directories=no,status=yes,toolbar=no,scrollbars="+SCROLLBARS+",resizable="+RESIZABLE+",width="+((screen.width)-WIDTH)+",height="+((screen.height)-HEIGHT)+",top="+TOP+",left="+LEFT;
		window.open(URL,FRAME,param); 
	}


/*  ----------------------------------------------------------------------------------------------------------	*
 *	Popup fenêtre javascript																					*
 *	<a href="xxxxx" onclick="popupwin('xxxxx','Popupwin','yes','yes','550','370','20','40');return(false);">	*
 *	<a href="xxxxx" onclick="popupwin(this.href,'popupwin','no','yes','100','100','20','60'); return(false);">	*
 *  ----------------------------------------------------------------------------------------------------------	*/

	function popupwin(URL,FRAME,SCROLLBARS,RESIZABLE,WIDTH,HEIGHT,TOP,LEFT)
	{
		var param = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars="+SCROLLBARS+",resizable="+RESIZABLE+",width="+WIDTH+",height="+HEIGHT+",top="+TOP+",left="+LEFT;
		window.open(URL,FRAME,param); 
	}


/*  --------------------------------------------------------------------------------------------------------------	*
 *	retaille fenetre																								*
 *	<body onload="window.focus(); RetaillerFenetre();">																*
 *	<a href="javascript:window.close();"><IMG SRC="xxx" name="i" border=0 alt="Cliquer pour fermer la fenêtre"></a>	*
 *	valeur defaut IE : document.i.width+12,document.i.height+30														*
 *	valeur defaut FIREFOX : document.i.width+8,document.i.height+48													*
 *  --------------------------------------------------------------------------------------------------------------	*/
	

		function retaillerfenetre()
			{
				if (iedetect == true)
					window.resizeTo(document.i.width+100,document.i.height+140);
				else 
					window.resizeTo(document.i.width+100,document.i.height+140);
					
			window.focus();
			}

		



/*  -----------------------------------------------------------------*
 *			    print	<a href="javascript:imprimer();">            *
 *  -----------------------------------------------------------------*/

	// fonction print

	function imprimer()
	{

		if (printenable)
		{
			window.print();
		}
		else
		{
			alert("Votre navigateur n'est pas compatible.\nCliquez sur ok, puis faire clic droit sur la souris\nenfin cliquez sur \"Imprimer\" dans menu contextuel.\nOu Appuyez sur les touches CTRL + P sur PC.")
		}

	}


/*  -----------------------------------------------------------------*
 *			    			test email  					         *
 *  -----------------------------------------------------------------*/

	function testmail(mail)
	{
		var cpt=0;
		if( mail.length==0)
			return false;
		
		var taille=mail.length;
		
		if(mail.charAt(taille-2)!='.')
			{
			//window.alert(mail.charAt(mail.length-1));
			var pos=0;	
			for( i=0; i<mail.length; i++)
				{
				var verif=mail.charAt(i);

				if(verif=='@' && i>=1)
					{
					cpt++;
					pos=i;
					}
				//window.alert(pos);
				if(pos<=i && pos!=0)
					{
					if(verif=='.') cpt++;
					}
				}
				
			}
				
		if (cpt<2)
			return false;

		return true;
	}




/*  -----------------------------------------------------------------*
 *			    			test formulaire 				         *
 *  -----------------------------------------------------------------*/


	function testform()
	{
		var erreur="";

		if(document.getElementById('f').nom.value.length<3)
		{
			erreur+="Veuillez remplir le champ Nom / Lastname \n";
		}
		
		
		if(document.getElementById('f').tel.value.length<10)
		{
			erreur+="Veuillez remplir le champ Telephone / Phone \n";
		}/**/
		
		/*if (document.getElementById('f').fax.value.length<10)
		{	
			erreur+="Veuillez remplir le champ fax / Fax \n";
		}*/
		
		if	(!testmail(document.getElementById('f').email.value))
		{
			erreur+="Veuillez remplir le champ Email / Mail \n";
		}

		/*if(document.getElementById('f').societe.value.length<3)
		{
			erreur+="Veuillez remplir le champ Societe / Firm \n";
		}*/
		
		
		/*if(document.getElementById('f').adresse.value.length<5)
		{
			erreur+="Veuillez remplir le champ Adresse / Address \n";
		}
		
		if(document.getElementById('f').cp.value.length<5)
		{
			erreur+="Veuillez remplir le champ Code Postal / Zip \n";
		}
		
		
		if(document.getElementById('f').ville.value.length<3)
		{
			erreur+="Veuillez remplir le champ Ville / Town \n\n";
		}*/
		
		/*if((!document.getElementById('demande_gite').checked) && (!document.getElementById('demande_chambres').checked) )
		{
			erreur+="Veuillez remplir le type de demande \n\n";
		}*/		

		/* projet 

		if(document.getElementById('f').departement.value.length<3)
		{
			erreur+="Veuillez remplir le champ Département \n";
		}

		if(document.getElementById('f').ville_projet.value.length<3)
		{
			erreur+="Veuillez remplir le champ Ville de votre projet \n";
		}

		if(document.getElementById('f').altitude.value.length<3)
		{
			erreur+="Veuillez remplir le champ Altitude \n";
		}

		if(document.getElementById('f').surface.value.length<3)
		{
			erreur+="Veuillez remplir le champ Surface \n";
		}*/

		//if((!document.getElementById('demande_gite').checked) && (!document.getElementById('demande_chambres').checked) )
		//{
		//	erreur+="Veuillez remplir le type de demande \n";
		//}		


		if(erreur.length>0)
			{
			window.alert(erreur);
			return false;
			}

		return true;

	}



/*  -----------------------------------------------------------------*
 *			    			test formulaire 				         *
 *			    			Affiche le champ non remplie	         *
 *  -----------------------------------------------------------------*/
function checkInput(i,label)
{
    if (i.value=="")
        {
        i.style.border = '2px solid #E44000';
		i.style.paddingLeft = '3px';
		i.style.margin = '0px';
        return "  - " + label + "\n";
        }
    else
        i.style.border='';

    return "";
}

function reinitInput(i)
{
	i.style.border = '';
	i.style.paddingLeft = '';
	i.style.margin = '';
}

function checkFormContact(f)
{
var msg="";

    msg += checkInput(document.getElementById('f').nom,"Nom");
    msg += checkInput(document.getElementById('f').prenom,"Prénom");
	msg += checkInput(document.getElementById('f').adresse,"Adresse");
	msg += checkInput(document.getElementById('f').cp,"Code postal");
	msg += checkInput(document.getElementById('f').ville,"Ville");
    msg += checkInput(document.getElementById('f').tel,"Téléphone");
	checkInput(document.getElementById('f').email," ");
    if (!testmail(document.getElementById('f').email.value))
		msg += "  - " + 'Email' + "\n";
	msg += checkInput(document.getElementById('f').date_naissance,"Date de naissance");
	
	if ( (!document.getElementById('sexe_m').checked) && (!document.getElementById('sexe_f').checked) )
	{
		msg += "  - " + 'Votre Sexe' + "\n";
	}
	
	if ( (!document.getElementById('extra_cuisine').checked) && (!document.getElementById('extra_service').checked) )
	{
		msg += "  - " + 'Extra cuisine ou salle ?' + "\n";
	}
	
	if ( (!document.getElementById('semaine').checked) && (!document.getElementById('week-end').checked) )
	{
		msg += "  - " + 'Semaine ou Week end' + "\n";
	}
	

    if (msg != "")
    {
        alert("Merci de remplir les champs suivants \n"+msg);
        return false;
    }

    return true;
}


function inputChiffres(id)
{
	$('#' + id).keyup(function(e) {
				
		var reg = new RegExp("[^0-9]");		
		$('#' + id).val($('#' + id).val().replace(reg, ''));
	});
}


