/* menu jquery */

$(document).ready(function() {
		
		/* menu deroulant droite */	
		function mainmenu()
        {
    		$("#home #mh ul ul ").css({display: "none"}); // Opera Fix
    		$("#home #mh ul li, #page #mh ul ul li").hover(
            
                function() {
                
                    var ul = $(this).find('ul:first').stop(true,true);
                    
                    ul.css({visibility:"visible", display:"none"}).fadeIn(300);

                    // Repositionnement des menus qui apparaissent trop bas
                    if (ul.attr('rel') != 'deplace')
                    {
                        var pos = ul.offset();
                        var ul_top = pos.top;
                        var ul_h = ul.outerHeight();
                        var win_h = $(window).height();
                        
                        var diff = ul_top + ul_h - win_h;
                        
                        if (diff > 0)
                        {
                            ul.css('left', ul.position().left + 'px')
                              .css('top', ul.position().top - diff + 'px')
                              .css('position', 'absolute')
                              .attr('rel', 'deplace');
                        }
                    }                		
				},
                function() {
                
				    $(this).find('ul:first').stop(true,true).fadeOut(300);
				}
            );
		}
		
		mainmenu();

        /* fond menu */
		$('#page #mh a')
			.css( {backgroundPosition: "0 -530px"} )
			.mouseover(function()
			{
					$(this).stop(true).animate({backgroundPosition:"(0 0)"}, {duration:500})
			})
						
			.mouseout(function()
			{
			    if (!$(this).hasClass('current'))
					$(this).stop(true).animate({backgroundPosition:"(0 -530px)"}, {duration:800});
		    });	
		
		
		// menu current
		//$('#mh01, #smh102, #ssmh10202, #sssmh1020201').addClass('current');
			
		// On attend quelques fractions de seconde avant d'afficher l'onglet current
		setTimeout(
			function() { 
				$(".current").stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
			},500);
		
		
		//**** EFFET ANCRES **********//
		if ($('a[href*=#]').length) {
			$('a[href*=#]').click(function() {
			  var $target = $(this.hash);
			  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			  $('html,body').animate({ scrollTop: $target.offset().top },1000);
			  return false;
			})
		}
		//***** EFFET ANCRES ********//
		
		// hauteur assiette
		//var h = $('#contenu').height();
		//$('#assiette').css( {top: (h/12) + "px"} );
		
		
        function hauteurHome()
        {
            var hh =  $('#home').height() + 50;
            if($(window).height() > hh) 
            {
                var marg = ($(window).height() - hh) / 2 + "px";
                $('#home').css('margin-top', marg);
            }
            else
            {
                $('#home').css('margin-top', 'auto');
            }        
        }
        
		// hauteur home
        hauteurHome();
		$(window).resize(hauteurHome);
		

    // ------------------------------------------------------------------------------------
	// defilement txt home
	$("#defiltxt").css({left:"40em"});
	function defil()
	{
		$("#defiltxt")
			.animate( { top: "0", left:"-40em"}, 9000 )
			.animate( {top: "-20px", left:"40em" }, 0 )
			.animate( { top: "0", left:"40em" }, 0, '', function() { defil();} );					 
	}	
	defil();
	// defilement txt home
    // ------------------------------------------------------------------------------------







    // ------------------------------------------------------------------------------------
	// Effet Bulle home
	function bulle()
	{
		$("#motifmenu1 img, #motifmenu2 img, #motifmenu3 img, #motifmenu4 img").css({width: "90%", height: "90%"}); // Opera Fix 
		$("#blochome2 .mht").css({background:"#fff",opacity: 0}); // Bug ie lien survol background
		
		/* presentation */
		$("#blochome2 #mh1").hover(
			function() {
				$("#motifmenu1").stop().animate({bottom: "211px", left: "129px" }, 150);
				$("#motifmenu1 img").stop().animate({width: "100%", height: "100%"}, 150);
			},
			function() {
				$("#motifmenu1").stop().animate({bottom: "206px", left: "134px" }, 150);
				$("#motifmenu1 img").stop().animate({width: "90%", height: "90%" }, 150);
			}
		);
		/*/ presentation */
		
		/* ecole */
		$("#blochome2 #mh2").hover(
			function() {
				$("#motifmenu2").stop().animate({bottom: "122px", left: "70px" }, 150);
				$("#motifmenu2 img").stop().animate({width: "100%", height: "100%"}, 150);
			},
			function() {
				$("#motifmenu2").stop().animate({bottom: "117px", left: "75px" }, 150);
				$("#motifmenu2 img").stop().animate({width: "90%", height: "90%" }, 150);
			}
		);
		/*/ ecole */
		
		/* college */
		$("#blochome2 #mh3").hover(
			function() {
				$("#motifmenu3").stop().animate({bottom: "92px", left: "227px" }, 150);
				$("#motifmenu3 img").stop().animate({width: "100%", height: "100%"}, 150);
			},
			function() {
				$("#motifmenu3").stop().animate({bottom: "87px", left: "232px" }, 150);
				$("#motifmenu3 img").stop().animate({width: "90%", height: "90%" }, 150);
			}
		);
		/*/ college */
		
		/* vie pratique */
		$("#blochome2 #mh4").hover(
			function() {
				$("#motifmenu4").stop().animate({bottom: "13px", left: "20px" }, 150);
				$("#motifmenu4 img").stop().animate({width: "100%", height: "100%"}, 150);
			},
			function() {
				$("#motifmenu4").stop().animate({bottom: "8px", left: "25px" }, 150);
				$("#motifmenu4 img").stop().animate({width: "90%", height: "90%" }, 150);
			}
		);
		/*/ vie pratique */
		
	}	
	bulle();	 
	// Effet Bulle home
    // ------------------------------------------------------------------------------------


		
});



/*  ------------------------------------------------*
 *			    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;




/*  --------------------------------------------------------------------------------------------------------------	*
 *											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";
	}


/*  ----------------------------------------------------------------------------------------------------------	*
 *	popupnews																									*
 *	se redimensione par raport a l'ecran																		*
 *	<a href="xxxxx" onclick="popupnews(this.href,'popupall','yes','yes','60','80','10','40'); return(false);">	*
 *  <a href="fichier.htm" onclick="window.open(this.href);return false;">										*
 *  ----------------------------------------------------------------------------------------------------------	*/

	function popupnews(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); 
	}


/*  ----------------------------------------------------------------------------------------------------------	*
 *	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','no','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+120);
				else 
					window.resizeTo(document.i.width+100,document.i.height+120);
					
			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;

	}

