var montim;

function Element_Selected(id , intitule)
{
	if (intitule.length >= 25)
	{
		intitule = intitule.substr(0 , 25) + '...';	
	}
	
	$('Slide_Ouvre').innerHTML = intitule;
}

////////////////////////////  	  (\  /)
// SLIDERS PAGE D'ACCUEIL //	 (  0_o  )
////////////////////////////	 ("'") ("'")
	
	
	function initiate_ajax_loaded_droite (rubrique)
	{
		// Slides Page d'accueil
//		var myVerticalSlide = new Fx.Slide('Menu_Deroulant');
//		$('Menu_Deroulant').setStyle('display' , 'block');
//		$('Slide_Ouvre').addEvent('click', function(e){
//			e.stop();
//			myVerticalSlide.toggle();
//		});
//		var Array_Close = $$('a.Slide_Fermer');
//		Array_Close.addEvent('click' , function () { myVerticalSlide.slideOut(); });
		
		var menu_ouvert = false;
		var MenuDeroulant = new Fx.Morph($('Menu_Deroulant') , {duration: 'normal'});
		$('Slide_Ouvre').addEvent('click' , function () {
				if (menu_ouvert) 
				{
					$clear(montim);
					$('droit_b').setStyle('overflow' , 'auto');
					$('droit_b').setStyle('display' , 'block');
					MenuDeroulant.start( { 'margin-top' : [-1000] } );
					menu_ouvert = false;
					$('Menu_Deroulant').setStyle('overflow' , 'hidden');
				}
				else 
				{
					$('droit_b').setStyle('overflow' , 'hidden');
					MenuDeroulant.start( { 'margin-top' : [0] } );
					menu_ouvert = true;
					var cachage = function cachage_F() { 
						$('Menu_Deroulant').setStyle('overflow' , 'auto');
						$('droit_b').setStyle('display' , 'none');
					}
					montim = cachage.delay(500);
				}
			  }
		);
		
		// Diaporama
		if ($('Diapo_Conteneur'))
		{
			var max_page = Math.ceil( $('Diapo_Conteneur').getAttribute('rel')  / 3);
			var page = 0;
			var diapoFX = new Fx.Morph($('Diapo_Conteneur') , {duration: 'normal'});
			
			if ( parseInt($('Diapo_Conteneur').getAttribute('rel')) == 0 ) $('avant').setStyle('visibility' , 'hidden');
			
			$('avant').addEvent('click' , function () {
				var margLeft = $('Diapo_Conteneur').getStyle('margin-left');
				if (page < max_page-1 )
				{
					$('apres').setStyle('visibility' , 'visible');
					var margLeftNew = parseInt(margLeft)-375;
					diapoFX.start( { 'margin-left' : [margLeft , margLeftNew] } );
					page++;
					if (page == max_page-1 ) $('avant').setStyle('visibility' , 'hidden');
				}
			  }
			);
			$('apres').addEvent('click' , function () {
				var margLeft = $('Diapo_Conteneur').getStyle('margin-left');
				if (parseInt(margLeft) != 0)
				{
					$('avant').setStyle('visibility' , 'visible');
					var margLeftNew = parseInt(margLeft)+375;
					diapoFX.start( { 'margin-left' : [margLeft , margLeftNew] } );
					page--;
					if (page == 0 ) $('apres').setStyle('visibility' , 'hidden');
				}
			  }
			);
			
			setupZoom();
		}
		
		// Tips table des matières
		var myTips = new Tips('.thisisatooltip' , {className:'Bulle' , fixed:false , offsets:{'x':-10 , 'y':16}});
		var opened = false;
		
		
		// Outils
		if ($('Flottant_Print_Save'))
		{
			var mon_time;
			var opened = false;
			var outilFX = new Fx.Morph($('Flottant_Print_Save'));
			
			$('Flottant_Print_Save').addEvent('mouseover' , function () {
					
					$clear(mon_time);
					outilFX.start( { 'margin-top' : 0 } ); 
					opened = true; 
				
			});
			
			$('Flottant_Print_Save').addEvent('mouseout' , function () {
		
					var fermeture = function () { outilFX.start( { 'margin-top' : '-24' } ); }
					mon_time = fermeture.delay(1000);
					opened = false;
				
			});
		}
		
		if ($('o_2'))
		{
			var bgnow =  $('Onglets').getStyle('background-image').toString();
			
			if (bgnow.indexOf('/images/onglet/onglet1.gif') != '-1')
			{
				$('o_1').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet1.gif)'); });
				$('o_1').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_2').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_2_on.gif)'); });
				$('o_2').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_3').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_3_on.gif)'); });
				$('o_3').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('Tab_Mat_Ouvre').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_4_on.gif)'); });
				$('Tab_Mat_Ouvre').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
			}
			else if (bgnow.indexOf('/images/onglet/onglet2.gif') != '-1')
			{
				$('o_1').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_21_on.gif)'); });
				$('o_1').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_2').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet2.gif)'); });
				$('o_2').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_3').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_22_on.gif)'); });
				$('o_3').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('Tab_Mat_Ouvre').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_23_on.gif)'); });
				$('Tab_Mat_Ouvre').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });				
			}
			else if (bgnow.indexOf('/images/onglet/onglet3.gif') != '-1')
			{
				$('o_1').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_31_on.gif)'); });
				$('o_1').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_2').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_32_on.gif)'); });
				$('o_2').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_3').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet3.gif)'); });
				$('o_3').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('Tab_Mat_Ouvre').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_33_on.gif)'); });
				$('Tab_Mat_Ouvre').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });				
			}
			else if (bgnow.indexOf('/images/onglet/onglet0.gif') != '-1')
			{
				
				$('o_1').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet0.gif)'); });
				$('o_1').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_3').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_03_on.gif)'); });
				$('o_3').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('Tab_Mat_Ouvre').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_04_on.gif)'); });
				$('Tab_Mat_Ouvre').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });				
			}
			else if (bgnow.indexOf('/images/onglet/onglet4.gif') != '-1')
			{
				$('o_1').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_41_on.gif)'); });
				$('o_1').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('o_3').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet4.gif)'); });
				$('o_3').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });
				
				$('Tab_Mat_Ouvre').addEvent('mouseover' , function () { $('Onglets').setStyle('background-image' , 'url(/images/onglet/onglet_44_on.gif)'); });
				$('Tab_Mat_Ouvre').addEvent('mouseout' , function () { $('Onglets').setStyle('background-image' , bgnow); });				
			}
		}
		
	}
	
	function initiate_ajax_loaded_gauche(rubrique, menu) {
		
		////////////////////////////////////////////////
		// Gestion de la partie de gauche pour les acteurs
		////////////////////////////////////////////////
		if (rubrique == 3)
		{		
			var bulleFX1 = new Fx.Morph($('Bulle_Ferme') , {link:'cancel' , duration:'short'});
			var bulleFX2 = new Fx.Morph($('Bulle_Distri') , {link:'cancel' , duration:'short'});
			var bulleFX3 = new Fx.Morph($('Bulle_Entr') , {link:'cancel' , duration:'short'});
			var bulleFX4 = new Fx.Morph($('Bulle_Fede') , {link:'cancel' , duration:'short'});
			
			$('Open_Masque_Entreprise').addEvent('mouseover' , function () {
				bulleFX3.start( { 'opacity' : [0,1] } );	
			});
			$('Open_Masque_Entreprise').addEvent('mouseout' , function () {
				bulleFX3.start( { 'opacity' : [1,0] } );	
			});
			
			
			$('Open_Masque_SuperM').addEvent('mouseover' , function () {
				bulleFX2.start( { 'opacity' : [0,1] } );	
			});
			$('Open_Masque_SuperM').addEvent('mouseout' , function () {
				bulleFX2.start( { 'opacity' : [1,0] } );	
			});
			
			
			$('Open_Masque_Fede').addEvent('mouseover' , function () {
				bulleFX4.start( { 'opacity' : [0,1] } );	
			});
			$('Open_Masque_Fede').addEvent('mouseout' , function () {
				bulleFX4.start( { 'opacity' : [1,0] } );	
			});
			
			
			$('Open_Masque_Prod').addEvent('mouseover' , function () {
				bulleFX1.start( { 'opacity' : [0,1] } );		
			});
			$('Open_Masque_Prod').addEvent('mouseout' , function () {
				bulleFX1.start( { 'opacity' : [1,0] } );		
			});
			
			
	
		}
		
		if (rubrique == 4)
		{
	
			var bulleFX5 = new Fx.Morph($('Bulle_Import') , {link:'cancel' , duration:'short'});
			var bulleFX6 = new Fx.Morph($('Bulle_Regl') , {link:'cancel' , duration:'short'});
			
			$('R4_Import').addEvent('mouseover' , function () {
				bulleFX5.start( { 'opacity' : [0,1] } );	
			});
			$('R4_Import').addEvent('mouseout' , function () {
				bulleFX5.start( { 'opacity' : [1,0] } );	
			});
			
			
			$('R4_Regle').addEvent('mouseover' , function () {
				bulleFX6.start( { 'opacity' : [0,1] } );	
			});
			$('R4_Regle').addEvent('mouseout' , function () {
				bulleFX6.start( { 'opacity' : [1,0] } );	
			});
			
		}
		
		//////////////////////////////////////////////////
		// Gestion de la partie de gauche pour le frigo //
		//////////////////////////////////////////////////
		if (rubrique == 1)
		{	
			
			
			
			if (menu == undefined)
			{
				$('Ouvre_PostIt_Midi').addEvent('mouseover' , function () {
						var EffetPostIt = new Fx.Morph($('PostIt') , {duration: 'short'});
						$('PostIt').setStyle('opacity',0);
						$('PostIt').setStyle('display','block');
						EffetPostIt.start( { 'opacity' : [0,1] } );
				});
			}
			
			if (menu == 1)
			{
				
				$('PostIt_Close').addEvent('click' , function () {
						var EffetPostIt = new Fx.Morph($('PostIt') , {duration: 'short'});
						EffetPostIt.start( { 'opacity' : [1,0] } );
				});
			}
			else if (menu == 2)
			{
				var mes_area_masque = $$('area.ReactFrigoOuvertMasque');
				
				mes_area_masque.each(function(item, index){
						$(item).addEvent('mouseout', function(){
							$('Image_Frigo').src  = 'images/frigo/ouvert_midi.jpg';
						});
						
						$(item).addEvent('mouseover', function(){
							$('Image_Frigo').src  = 'images/frigo/ouvert_midi_masque.jpg';
						});
						
				});				
			
			}
			
			var ardoiseFX = new Fx.Morph($('Ardoise_Big') , {link: 'cancel'});
			$('Ardoise').addEvent('click' , function () {
				ardoiseFX.start( { 'opacity' : [0,1] } );	
			});
			$('Ardoise_Fermer').addEvent('click' , function () {
				ardoiseFX.start( { 'opacity' : [1,0] } );	
			});
			
		}
		
		var myTips = new Tips('.thisisatooltip' , {className:'Bulle' , fixed:false , offsets:{'x':-10 , 'y':16}});
		
		if (rubrique == 2)
		{
			$('Process-cafe').addEvent('mouseover' , function () { $('Process-etiqu-cafe').setStyle('display' , 'block'); });
			$('Process-cafe').addEvent('mouseout' , function () { $('Process-etiqu-cafe').setStyle('display' , 'none'); });
			
			$('Process-choco').addEvent('mouseover' , function () { $('Process-etiqu-choco').setStyle('display' , 'block'); });
			$('Process-choco').addEvent('mouseout' , function () { $('Process-etiqu-choco').setStyle('display' , 'none'); });
			
			$('Process-carotte').addEvent('mouseover' , function () { $('Process-etiqu-carotte').setStyle('display' , 'block'); });
			$('Process-carotte').addEvent('mouseout' , function () { $('Process-etiqu-carotte').setStyle('display' , 'none'); });
			
			$('Process-pain').addEvent('mouseover' , function () { $('Process-etiqu-pain').setStyle('display' , 'block'); });
			$('Process-pain').addEvent('mouseout' , function () { $('Process-etiqu-pain').setStyle('display' , 'none'); });
			
			$('Process-jambon').addEvent('mouseover' , function () { $('Process-etiqu-jambon').setStyle('display' , 'block'); });
			$('Process-jambon').addEvent('mouseout' , function () { $('Process-etiqu-jambon').setStyle('display' , 'none'); });
			
			$('Process-yaourt').addEvent('mouseover' , function () { $('Process-etiqu-yaourt').setStyle('display' , 'block'); });
			$('Process-yaourt').addEvent('mouseout' , function () { $('Process-etiqu-yaourt').setStyle('display' , 'none'); });
			
			$('Process-pates').addEvent('mouseover' , function () { $('Process-etiqu-pates').setStyle('display' , 'block'); });
			$('Process-pates').addEvent('mouseout' , function () { $('Process-etiqu-pates').setStyle('display' , 'none'); });
			
			$('Process-eau').addEvent('mouseover' , function () { $('Process-etiqu-eau').setStyle('display' , 'block'); });
			$('Process-eau').addEvent('mouseout' , function () { $('Process-etiqu-eau').setStyle('display' , 'none'); });
		}
			
}

////////////////////////////  	  (\  /)		/////////////
// SLIDERS PAGE D'ACCUEIL //	 (  0_o  )		// THE END //
////////////////////////////	 ("'") ("'")	/////////////

function get_elem_form(id , url_now)
{
	var chaine = '&action=validation_form';
	var monForm = document.forms[id].elements;
	for (var i=0 ; i< monForm.length ; i++)
	{
		if (monForm[i].checked == true) 
		{
			chaine +=  '&' + monForm[i].name + '=' + monForm[i].value;
		}
	}
	//alert(url_now + chaine);
	ajax('centre_droit' , url_now + chaine);
	return false;
}

function set_footer(rubrique , url)
{	
	if (rubrique == 1) 
	{
		
		$('Footer_Img').setStyle('background-image' , 'url(img/footer/produit.gif)');
		if (get_objet(url) != '') ajax('footer' , 'insertion/tpl/footer.php?obj=' + get_objet(url));
		
	}
	else if (rubrique == 2) $('Footer_Img').setStyle('background-image' , 'url(img/footer/process.gif)');
	else if (rubrique == 3) $('Footer_Img').setStyle('background-image' , 'url(img/footer/acteurs.gif)');
	else if (rubrique == 4) $('Footer_Img').setStyle('background-image' , 'url(img/footer/marches.gif)');
	
}

function aff_onglet(id)
{
	$('Onglet_15').setStyle('display' , 'none');
	$('Onglet_16').setStyle('display' , 'none');
	$('Onglet_17').setStyle('display' , 'none');
	$('Onglet_' + id).setStyle('display' , 'block');	
}

function lancer_telechargement(url)
{
	$('Telechargement').innerHTML = '<iframe src="impression2.php?' + url + '"></iframe>';	
}

function aff_trait_horiz(rub_id , obj_id , lien_id)
{
	$('Horiz-'+rub_id+'-'+obj_id+'-'+lien_id).setStyle('visibility' , 'visible');
}

function mask_trait_horiz(rub_id , obj_id , lien_id)
{
	$('Horiz-'+rub_id+'-'+obj_id+'-'+lien_id).setStyle('visibility' , 'hidden');
}

function set_table_desc (nom)
{
	$('Table_Matieres_Desc').innerHTML = '';
	var delayage = function () { $('Table_Matieres_Desc').innerHTML = '<b>' + nom + '</b>'; }
	delayage.delay(300);
}

function initiate_ajax_loaded_tabmat()
{
	// Table des matières
	var EffetTab = new Fx.Morph($('tab_mat_acc'));
	
	$('Tab_Mat_Ouvre').addEvent('click' , function () {
			$('tab_mat_acc').setStyle('opacity','0');
			$('tab_mat_acc').setStyle('display','block');
			EffetTab.start( { 'opacity' : [0,1] } );
	});
	
	$('TabMat_Fermer').addEvent('click' , function () {
			EffetTab.start( { 'opacity' : [1,0] } );
	});
	var myTips = new Tips('.thisisatooltip' , {className:'Bulle' , fixed:false , offsets:{'x':-10 , 'y':16}});
	
}

function initiate_ajax_loaded_recherche()
{
	// Table des matières
	var EffetTab = new Fx.Morph($('flottant_recherche'));
	
	$('Recherche_Fermer').addEvent('click' , function () {
			EffetTab.start( { 'opacity' : [1,0] } );
	});
	
}

function initiate_ajax_loaded_contact()
{
	// Table des matières
	var EffetTab = new Fx.Morph($('flottant_contact'));
	
	$('Contact_Fermer').addEvent('click' , function () {
			EffetTab.start( { 'opacity' : [1,0] } );
	});
	
}

function tips_process ()
{
	window.addEvent('domready', function(){
										 		
//		$('Process-carotte').store('tip:title', '<img src="data/img_menu/1218102903.gif" />');
//		$('Process-carotte').store('tip:text', ' &nbsp;Carottes râpées');
//	
//		$('Process-jambon').store('tip:title', '<img src="data/img_menu/1218102927.gif" />');
//		$('Process-jambon').store('tip:text', ' &nbsp;Jambon');
//	
//		$('Process-pates').store('tip:title', '<img src="data/img_menu/1218102942.gif" />');
//		$('Process-pates').store('tip:text', ' &nbsp;Pâtes');
//	
//		$('Process-yaourt').store('tip:title', '<img src="data/img_menu/1218102948.gif" />');
//		$('Process-yaourt').store('tip:text', ' &nbsp;Yaourt');
//	
//		$('Process-cafe').store('tip:title', '<img src="data/img_menu/1218102896.gif" />');
//		$('Process-cafe').store('tip:text', ' &nbsp;Café');
//	
//		$('Process-choco').store('tip:title', '<img src="data/img_menu/1218102913.gif" />');
//		$('Process-choco').store('tip:text', ' &nbsp;Chocolat');
//	
//		$('Process-eau').store('tip:title', '<img src="data/img_menu/1218102920.gif" />');
//		$('Process-eau').store('tip:text', ' &nbsp;Eau minérale');
//	
//		$('Process-pain').store('tip:title', '<img src="data/img_menu/1218102934.gif" />');
//		$('Process-pain').store('tip:text', ' &nbsp;Pain');
		
		var myTips = new Tips('.Menu_Process_Lien' , {className:'Bulle' , fixed:false , offsets:{'x':-10 , 'y':16}});
	
	});
	
}


window.addEvent('domready', function(){

	var myTips = new Tips('.thisisatooltip' , {className:'Bulle' , fixed:false , offsets:{'x':-10 , 'y':16}});
	if ($('Tab_Mat_Ouvre')) initiate_ajax_loaded_tabmat();
	initiate_ajax_loaded_contact();

});

function afftmat ()
{
	var EffetTab = new Fx.Morph($('tab_mat_acc'));
	if ($('tab_mat_acc').getStyle('opacity') > 0) $('tab_mat_acc').setStyle('opacity','0');
	$('tab_mat_acc').setStyle('display','block');
	EffetTab.start( { 'opacity' : [1] } );
}

function affcontact ()
{
	var EffetContact = new Fx.Morph($('flottant_contact'));
	if ($('flottant_contact').getStyle('opacity') > 0) $('flottant_contact').setStyle('opacity','0');
	$('flottant_contact').setStyle('display','block');
	EffetContact.start( { 'opacity' : [1] } );
}

function affrecherche ()
{	
	var recherche = $('moteur_recherche').value.toString();
	
	if (recherche.length < 3) 
	{
		alert('Votre recherche doit comporter un minimum 3 caractères');
		return false;
	}
	
	var EffetRecherche = new Fx.Morph($('flottant_recherche'));
	if ($('flottant_recherche').getStyle('opacity') > 0) $('flottant_recherche').setStyle('opacity','0');
	$('flottant_recherche').setStyle('display','block');
	EffetRecherche.start( { 'opacity' : [1] } );
	
	ajax('flottant_recherche' , 'ajax/ajax_recherche.php?recherche=' + $('moteur_recherche').value);
}

function verifMail()
{
	
	var erreur = '';
	if ($('contact_email').value == '') { erreur += "Le champ eMail est obligatoire\n"; $('contact_email').setStyle('background-color' , '#FF0'); }
	if ($('contact_nom').value == '') { erreur += "Le champ Nom & Prénom est obligatoire\n"; $('contact_nom').setStyle('background-color' , '#FF0');  }
	if ($('contact_message').value == '') { erreur += "Le champ Message est obligatoire\n"; $('contact_message').setStyle('background-color' , '#FF0');  }
	if ($('captcha').value == '') { erreur += "Le champ Code de vérification est obligatoire\n"; $('captcha').setStyle('background-color' , '#FF0');  }
	
	if (erreur != '')
	{
		alert(erreur);
		return false;
	}
	else
	{
		$('formcontact').submit();
	}
}

function aff_trait_vert(id , current)
{
	$('Trait_Vert_' + id).setStyle('display' , 'block');
}

function mask_trait_vert(id , current)
{
	if (current != id) $('Trait_Vert_' + id).setStyle('display' , 'none');
}