$(document).ready(function(){



// EFFET ANCRES
	// pas de point dans les ancres #
	// li[rel=current] a[href*=#]
	if ($('a[href*=#], a[href*=#page]').length) {
		$('a[href*=#], a[href*=#page]').click(function() {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			var cible = $target.offset().top - $('#page').eq(0).offset().top + 8; /* reference + ajustement hauteur */
			//var cible = $target.offset().top -20; /* reference + ajustement hauteur */
			$('html, body').animate({ scrollTop: cible },1000); /* div ou html,body par defaut */
			return false;
		})
	}
	// EFFET ANCRES



	
	
	// Changement de page avec animation
	$('a').click(function() {

		var rel = $(this).attr('rel');
		if (rel == 'noanim')  // rel="noanim" desactive l'animation
	       return true;
		   
		if (rel == 'zoom')  // class="iframe" desactive l'animation
	       return true;

		if ($(this).hasClass('iframe'))  // class="iframe" desactive l'animation
	       return true;

		var lien = $(this).attr('href');
	    if (!lien)
	       return true;
	    if (lien.length < 3)  // lien superieur a 3 caracteres
	       return true;
		if (lien.indexOf('#') == 0)  // ancres
	       return true;
		if (lien.indexOf('mailto:') == 0)  // mailto:
	       return true;
		if (lien.indexOf('zoom.php') >= 0)  // zoom.php
	       return true;

    	var redir_ok = false;

		$('#page, #home').not('.encart').fadeTo(0,0.3, function() { // fondu image menu

			$(this).not('.encart').fadeTo(500, 1);
		});
       if (lien && !redir_ok) { redir_ok = true; document.location.href = lien; }
	   
        return false;
	});
		
	/* click sous menu */
		$(".smeco li a").click(function() {
									  	   
			$("#smecob01 li").removeClass("current");
			
			$(".smeco li").removeClass("current");
			$(this).parent('li').addClass("current");
		});
		
		$("#smenu li a").click(function() {
									  	   
			$("#smenu li").removeClass("current");
			$(this).parent('li').addClass("current");
		});
		
		$("#smecob01 li a").click(function() {
									  	   
			$(".smeco li").removeClass("current");
			
			$("#smecob01 li").removeClass("current");
			$(this).parent('li').addClass("current");
		});
		
				
		// encart
		$('.encart').hover(
			function() {
				$(this).addClass("current");
			},
			function() {
				$(this).removeClass("current");
			}
		);
		// encart
		
		// zoomimg
		$('.zoomimg').hover(
			function() {
				$(this).find('span:first').fadeIn(200);
			},
			function() {
				$(this).find('span:first').fadeOut(300);
			}
		);
		// zoomimg

	/**** COLOR BOX *****/
	//Examples of how to assign the ColorBox event to elements
	$(".iframe").colorbox({
		width:"90%",
		height:"90%",
		iframe:true,
		opacity: 0.8,
		
		previous : "précédent",
		next : "suivant",
		close : "fermer",
		slideshowStart: "démarrer le diaporama",
		slideshowStop: "arrêter le diaporama",
		current : "image {current} sur {total}"
	});
	
	$("a[rel='zoom']").colorbox({
		opacity: 0.8,
		//slideshow:true,
		transition:"elastic",
		
		previous : "précédent",
		next : "suivant",
		close : "fermer",
		slideshowStart: "démarrer le diaporama",
		slideshowStop: "arrêter le diaporama",
		current : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{current} sur {total}"
	});
	
	
	/**** COLOR BOX *****/





});


/**** SOUS MENU ECO *****/

function mainmenu(){
$("#menueco ul ul ").css({display: "none"}); // Opera Fix
$("#menueco ul li").hover(function(){
        var q = $(this).find('ul:first').queue();
        if (q && (q.length > 0))
            return true;

		$(this).find('ul:first').fadeIn(200);

		},function(){
		$(this).find('ul:first').fadeOut(300);
		});
}

$(document).ready(function(){
	mainmenu();
});


// On attend quelques fractions de seconde avant d'afficher le sous menu au changemment de page
setTimeout(
	function() { 
		$("#menueco ul li[class=current]").find('ul:first').fadeIn(500);
		},500);
setTimeout(
	function() { 
		$("#menueco ul li[class=current]").find('ul:first').fadeOut(300);
	},2000);

/**** SOUS MENU ECO *****/




/**** DEPLACEMENT BLOC VERTICAL *****/
// scrollBloc(' ID ', decalage , hauteur initialitation du bloc absolu , hauteur mininimum );
function scrollBloc1(id_bloc, decalage, hauteur_init_bloc, hauteur_min)
{
	var topB = $(window).stop(true, true).scrollTop() + decalage;
	if (topB + hauteur_init_bloc > $(window).height())
		topB = $(window).height() - 100 + $(window).stop(true, true).scrollTop() - hauteur_init_bloc;
		
	if (topB < hauteur_min)
		topB = hauteur_min;
		
	$("#" + id_bloc).stop(true, true).animate({ 
		top : topB
	}, 500 );
}

function scrollBloc(id_bloc, decalage, hauteur_init_bloc, hauteur_min)
{
	scrollBloc1(id_bloc, decalage, hauteur_init_bloc, hauteur_min);
	$(window).scroll(function() {			
	    scrollBloc1(id_bloc, decalage, hauteur_init_bloc, hauteur_min);
	});
	$(window).resize(function() {			
	    scrollBloc1(id_bloc, decalage, hauteur_init_bloc, hauteur_min);
	});
}
$(document).ready(function(){
	scrollBloc('smecob01', 0, 881, 0);
});
/**** DEPLACEMENT BLOC VERTICAL *****/

/**** POINTS ECO *****/
$(document).ready(function(){
	  

	$('#point01, #point02, #point03, #point04, #point05, #point06').css({display: "none"}); // Opera Fix
	$('#cache').css({opacity: "0.4"}); // fondu image menu
	
	
    // On attend quelques fractions de seconde avant d'afficher le toolTip 
    setTimeout(
		function() { 
			$('#cache').stop(true,true).fadeIn(500);
			$('#point01, #point02, #point03, #point04, #point05, #point06').stop(true,true).fadeIn(500);
		},2000);
	         	



	// points img
	$('#imgeco').hover(
		function() {
			$('#cache').stop(true,true).fadeIn(500);
			$('#point01, #point02, #point03, #point04, #point05, #point06').fadeIn(500);
		},
		function() {
			$('#cache').stop(true,true).fadeOut(500);
			$('#imgeco dl').css({display: "none"}); // Opera Fix
		}
	);
	// points img


	// points 01
	$('#meco01, #point01').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point01').not(this).stop(true,true).fadeIn(500);
			$('#meco01').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco01').find('ul:first').fadeOut(300);
		}
	);
	// points 01


	// points 02
	$('#meco02, #point02').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point02').not(this).stop(true,true).fadeIn(500);
			$('#meco02').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco02').find('ul:first').fadeOut(300);
		}
	);
	// points 02

	// points 03
	$('#meco03, #point03').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point03').not(this).stop(true,true).fadeIn(500);
			$('#meco03').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco03').find('ul:first').fadeOut(300);
		}
	);
	// points 03


	// points 04
	$('#meco04, #point04').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point04').not(this).stop(true,true).fadeIn(500);
			$('#meco04').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco04').find('ul:first').fadeOut(300);
		}
	);
	// points 04

	// points 05
	$('#meco05, #point05').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point05').not(this).stop(true,true).fadeIn(500);
			$('#meco05').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco05').find('ul:first').fadeOut(300);
		}
	);
	// points 05

	// points 06
	$('#meco06, #point06').hover(
		function() {
			$('#imgeco dl').not(this).css({display: "none"}); // Opera Fix
			$('#cache').stop(true,true).fadeIn(500);
			$('#point06').not(this).stop(true,true).fadeIn(500);
			$('#meco06').find('ul:first').fadeIn(200);
		},
		function() {
			$('#point01, #point02, #point03, #point04, #point05, #point06').not(this).stop(true,true).fadeIn(500);
			$('#meco06').find('ul:first').fadeOut(300);
		}
	);
	// points 06

});
/**** POINTS ECO *****/


/*  --------------------------------------------------------------------------------------------------------------	*
 *											FONCTION PRELOAD GLOBAL													*
 *																													*
 *	preload global des images >>>> onLoad="preloadcommun(); SwitchRub (rub);"										*
 *  --------------------------------------------------------------------------------------------------------------	*/
/*  ------------------------------------------------*
 *			    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 AFFICHE TITRE													*
 *																													*
 *		<A HREF="xxx.shtml"                                      													*
 *					onMouseOver = " SwitchImg ('menu_02',    '../img/menu_02_on.gif');   							*
 *									SwitchLeg ('TITRE RUBRIQUE','100px');" 											*
 *					onMouseOut  = " SwitchLeg ('','');																*
 *									if (rub != 'menu_02')															*
 *									SwitchImg ('menu_02',     '../img/menu_02.gif'); "> 							*
 *		<IMG SRC="img/menu_02.gif" NAME="menu_02" WIDTH=90 HEIGHT=31 BORDER="0" ALT="DESCRIPTION"></A>				*
 *																													*
 *																													*
 *		<TD ID="LEG">TITRE PAR DEFAUT</TD>																			*
 *																													*
 *  --------------------------------------------------------------------------------------------------------------	*/

	// Variable par defaut et padding par defaut
    var LegDefaut = "";
	var PadDefaut = 0;

	// Fonction qui affiche le titre et le padding
	function SwitchLeg (info,pad)
	{
		var obj;
		obj = document.getElementById("LEG");
		if (obj)
			{
			if (LegDefaut == "")
				{
				LegDefaut = obj.innerHTML;
				PadDefaut = obj.style.paddingLeft;
				}

			if (info != "")
				{
				obj.innerHTML = info;
				obj.style.paddingLeft = pad;
				}
			else
				{
				obj.innerHTML = LegDefaut;
				obj.style.paddingLeft = PadDefaut;
				}

			}
	}



/*  ----------------------------------------------------------------------------------------------------------	*
 *	popupfull																									*
 *	se redimensione par raport a l'ecran																		*
 *	<a href="xxxxx" onclick="popupfull(this.href,'popupfull','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);"> 		*
 *  ----------------------------------------------------------------------------------------------------------	*/
/*
	function popupall(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="+((screen.width)-WIDTH)+",height="+((screen.height)-HEIGHT)+",top="+TOP+",left="+LEFT;
		window.open(URL,FRAME,param);
	}
*/
	// popupall

	function popupall(URL,FRAME,RESIZABLE)
	{
		var param = "menubar=no,location=yes,directories=no,status=no,toolbar=yes,scrollbars=yes,resizable="+RESIZABLE+",width="+((screen.width)-200)+",height="+((screen.height)-200)+",top=20,left=100";
		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+40,document.i.height+120);
				else
					window.resizeTo(document.i.width+40,document.i.height+120);

			window.focus();
			}


/*  ------------------------------------------------
 *  Kyxar Dhtml Lib                                *
 *    Librairie de manipulation d'objets DHTML     *
 *  [C] Kyxar / RS - 2001,2002,2003                *
 *  Contact, Info : http://www.kyxar.fr            *
 *                                                 *
 *  Basé sur Next Generation cross-browser DHTML   *
 *  de http://devedge.netscape.com                 *
 *  Compatibilité : IE5+ NS6+ Opera6+              *
 *  ---------------------------------------------- */

function positionner_layers()
{
var x,y;

    win_w=document.body.clientWidth;
	//win_h=document.body.clientHeight;

	// Position de la signature
    oP2=document.getElementById('P2');
	if (oP2)
		{
	    oP2.style.left = win_w - 135;
		//oP2.style.top  = win_h - 22;
        oP2.style.visibility = "Visible";
		}
}




/*  -----------------------------------------------------------------*
 *			    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 nom ou societe									  //
	 //						test objet 1,2,3 et different rhone-alpes popup région				 //
	//                                                                                          //
   //////////////////////////////////////////////////////////////////////////////////////////////


	function testform()
	{

		var erreur="";
		var resultat=0;

		if	(document.f.societe.value.length<3 && document.f.nom.value.length<3)
		{
			erreur+="Veuillez remplir le champ société ou le champ nom (3 caractères minimum)\n\n";
		}

		if	(document.f.ville.value.length<3)
		{
			erreur+="Veuillez remplir le champ ville (3 caractères minimum)\n\n";
		}
		/*if(document.f.pays.value.length<2)
		{
			erreur+="Veuillez remplir le champ pays (2 caractères minimum)\n\n";
		}*/
		if	(!testmail(document.f.email.value))
		{
			erreur+="Veuillez remplir l'adresse email\n\n";
		}

		if	(document.f.objet.selectedIndex < 2)
		{
			erreur+="Veuillez choisir l\'objet de votre requête\n\n";
		}

		if	(document.f.region.selectedIndex < 2)
		{
			erreur+="Veuillez choisir votre région\n\n";
		}

		if	(erreur.length>0)
		{
			resultat=1;
		}
		else
		{
			objet=new String(document.f.objet.selectedIndex);
			region=new String(document.f.region.selectedIndex);

			//	window.alert(objet+'-'+region);

			if (	(objet >= 2) && (objet <= 4) && (region != 23)	)
			{
				erreur="Attention : En raison de notre implantation en Rhône-Alpes,\nnous ne pouvons garantir de prendre en compte votre demande.\nVeuillez nous en excuser.\n\nSi vous maintenez votre requête, cliquez sur \" OK \"\n\nSi vous annulez votre requête, cliquez sur \" Annuler \"";
				resultat=2;
			}
		}

		if	(resultat == 1)
			{
				window.alert(erreur);
				return false;
			}

		if	(resultat == 2)
			{
				return window.confirm(erreur);
			}

		return true;

	}



function initDhtmlFamilles(mode)
{
    width_yps = 200;
    if (mode == 1)
    {
        left_yps = 205;
        top_yps = 3;
        sens = 'right';
        espacement = 0; // 21 par defaut
		new ypSlideOutMenu("menu01", sens, left_yps, top_yps,                 280, 80);
		new ypSlideOutMenu("menu08", sens, left_yps, top_yps + 1*espacement,  280, 170);
		new ypSlideOutMenu("menu02", sens, left_yps, top_yps + 2*espacement,  280, 125);
		new ypSlideOutMenu("menu04", sens, left_yps, top_yps + /*3*espacement*/ 25,  280, 80);
		new ypSlideOutMenu("menu03", sens, left_yps, top_yps + /*4*espacement*/ 45,  280, 95);
		new ypSlideOutMenu("menu10", sens, left_yps, top_yps + /*5*espacement*/ 60,  280, 95);
		new ypSlideOutMenu("menu05", sens, left_yps, top_yps + /*6*espacement*/ 80,  280, 95);
		new ypSlideOutMenu("menu09", sens, left_yps, top_yps + /*7*espacement*/ 110,  280, 80);
		new ypSlideOutMenu("menu06", sens, left_yps, top_yps + /*8*espacement*/ 50,  280, 155);
    }
    else if (mode == 2)
    {
        left_yps = 402;
        top_yps = 212;
        sens = 'left';
        espacement = 0; // 19 par defaut
		new ypSlideOutMenu("menu01", sens, left_yps, top_yps,                 280, 80);
		new ypSlideOutMenu("menu08", sens, left_yps, top_yps + 1*espacement,  280, 170);
		new ypSlideOutMenu("menu02", sens, left_yps, top_yps + 2*espacement,  280, 125);
		new ypSlideOutMenu("menu04", sens, left_yps, top_yps + /*3*espacement*/ 19,  280, 80);
		new ypSlideOutMenu("menu03", sens, left_yps, top_yps + /*4*espacement*/ 25,  280, 95);
		new ypSlideOutMenu("menu10", sens, left_yps, top_yps + /*5*espacement*/ 40,  280, 95);
		new ypSlideOutMenu("menu05", sens, left_yps, top_yps + /*6*espacement*/ 60,  280, 95);
		new ypSlideOutMenu("menu09", sens, left_yps, top_yps + /*7*espacement*/ 90,  280, 80);
		new ypSlideOutMenu("menu06", sens, left_yps, top_yps + /*8*espacement*/ 15,  280, 155);
    }
}