/**
 * Navig.js
 * Agences de l'eau
**/                                                                                                                              
                  


	/**
	 * Animation Banner
	**/
	var AnimationBanner = function() {                
		$$('   li.menu-item:nth-child(first)').tween('border', '0');
		
		setTimeout(function() {                 
 			$('masqueLigne1').tween('opacity', '0');
		}, 900);                 
		setTimeout(function() {                 
 			$('masqueLigne2').tween('opacity', '0');
 		}, 1200);            
		setTimeout(function() {                 
 			$('masqueLigne3').tween('opacity', '0');
		}, 2100); 
		setTimeout(function() {                 
 			$('masqueLigne4').tween('opacity', '0');
 		}, 2400);                   
		setTimeout(function() {                 
 			$('masqueLigne5').tween('opacity', '0');
		}, 3600);           
	}
     
 
   
	/**
	 * Retourne la listes des communes par filtre aphabÃ©tique
	**/
	var requeteListeCommune = function(commune) {  

		req = new Request({
			url: '/v3/assets/ajax/controlleur.php',
			method:'get',
			data:{  
				a:'listeCommunes',
				commune:commune 
			},
			onSuccess: function(retourAjax) {    
				$('selecteurCommune').set('html', retourAjax);   
				$('loading').setStyle('display', 'none');
				$('selecteur').addEvent('change', function(e) { 
					var commune = $('selecteur').get('value');   
					requeteCommune(commune);
				}); 
			}, 
			onFailure: function() {
				alert(retourAjax);                        
				$('loading').setStyle('display', 'none');
			}
		});      
		if (commune.length>1) {
	 		req.send();                             
			$('loading').setStyle('display', 'block'); 
			$$('div.c_agence').each(function(bulle) {   
				bulle.setStyle('display', 'none');  				
			}); 
		};                
		
		commune = commune.substr(0,2);
		$$('.c_agence').tween('display', 'none');;
		$$('.'+commune).tween('display', 'block');;
		                          
	};
	        
 
	          
	/**
	 * Retourne Les informations d'une commune
	**/
	var requeteCommune = function(commune) {   
		req = new Request({
			url: '/v3/assets/ajax/controlleur.php',
			method:'get',
			data:{  
				a:'infosCommunes',
				commune:commune 
			},
			onSuccess: function(retourAjax) {    
				$('informationsCommune').set('html', retourAjax);   
				$('loading').setStyle('display', 'none');     
				var zone = $('informationsCommune').getElement('span.zone').get('html');
				AfficheZone(zone);
			}, 
			onFailure: function() {
				alert(retourAjax);                        
				$('loading').setStyle('display', 'none');
			}
		});             
		if (commune.length>1) {
			req.send(); 
			$('loading').setStyle('display', 'block');
		};    
		
	};
	        
    
	var AfficheZone = function(zone) {        
		$$('div.c_agence').each(function(bulle) {   
			if (bulle.getElement('span.zone').get('html')==zone) { 
				bulle.setStyle('display', 'block');  
			} else {
				bulle.setStyle('display', 'none');  				
			}
		});  
		
	}
	
	
	
	
	

	var eteindBoutons = function() {  

		if (!$('page').hasClass('agence')) {
 			$('navLarge1').getElement('a').setStyles({                     
			    'color': '#FFFFFF', 
			    'background-color': '#78b41e'  
			});  
		};   			
 		if (!$('page').hasClass('ambition')) {
			$('navLarge2').getElement('a').setStyles({
			    'color': '#FFFFFF', 
			    'background-color': '#91c8e6' 
			}); 	   
		}  		
 		if (!$('page').hasClass('action')) {
 			$('navLarge3').getElement('a').setStyles({
			    'color': '#FFFFFF', 
			    'background-color': '#00a0e1' 
			}); 	   
		}; 
		   	
	};



   

	var AjusteHauteurPage = function() {
		var pageClasse = $('page').get('class').split(' ');
		var page = pageClasse[1];
		switch (page) {                                                             
			case '19': 
				if (Browser.ie7) {
					$('content').setStyle('height', '930px'); 						
				} else {
					$('content').setStyle('height', '820px'); 											
				}

			
			break;    
			case '17': $('content').setStyle('height', '620px'); 	break;    
			case '41': $('content').setStyle('height', '820px'); 	break;    
			case '43': $('content').setStyle('height', '520px'); 	break;    
			case '37': $('content').setStyle('height', '920px'); 	break;    
			case '38': $('content').setStyle('height', '520px'); 	break;    
		}
	}



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

    AjusteHauteurPage();

	$$('p.texteLigne').each(function(ligne) {
		ligne.setStyle('opacity', '0'); 
	});          
	AnimationBanner();

	/**
	 * initialise les effets des boutons de la navigation
	**/                                    
	var FX_nav1 = new Fx.Morph( $('navLarge1').getElement('a') , { duration: 'short', transition: Fx.Transitions.Sine.easeOut });  
	var FX_nav2 = new Fx.Morph( $('navLarge2').getElement('a') , { duration: 'short', transition: Fx.Transitions.Sine.easeOut });  
	var FX_nav3 = new Fx.Morph( $('navLarge3').getElement('a') , { duration: 'short', transition: Fx.Transitions.Sine.easeOut });  

	 
	
   	/**
   	 * masque le loading de la recherche commune/agence
   	**/                                                
	if ($('loading')!==null) {
		$('loading').setStyle('display', 'none');  
	};
          



	/**
	 * Navigation Large
	**/         
	$$('li.navLarge').each(function(bouton) {
		bouton.getElement('a').addEvent('click', function(e) {
			e.stop();   
			var url = bouton.getElement('a').get('href');
			window.location = url;
		}); 		
	});   
	
 /* 
.vert { color: #78b41e; }	
.bleuClair { color:#91c8e6; }	
.bleuFonce { color:#00a0e1; }	
.gris { color:#ffffff; }	
   */   
	
	
	$('navLarge1').addEvent('mouseover', function(e) { 
		e.stop();                                        
        eteindBoutons(); 
		if (!$('page').hasClass('agence')) {      
			FX_nav1.start({
			    'color': '#78b41e', 
			    'background-color': '#ffffff' 
			}); 			
		};
 	});    
	$('navLarge1').addEvent('mouseout', function(e) {	   
		e.stop();    
        eteindBoutons();
	});  



	$('navLarge2').addEvent('mouseover', function(e) { 
		e.stop();           
        eteindBoutons();
		if (!$('page').hasClass('ambition')) {
			FX_nav2.start({
			    'color': '#91c8e6', 
			    'background-color': '#ffffff' 
			}); 	      		
		};
 	});    
	$('navLarge2').addEvent('mouseout', function(e) {	   
		e.stop();           
        eteindBoutons();
	});            
	


	$('navLarge3').addEvent('mouseover', function(e) { 
		e.stop();   
        eteindBoutons(); 
		if (!$('page').hasClass('action')) {
			FX_nav3.start({
			    'color': '#00a0e1', 
			    'background-color': '#ffffff' 
			}); 	      		
		};
 	});    
	$('navLarge3').addEvent('mouseout', function(e) {	   
		e.stop();        
        eteindBoutons();
	});                


 

	/**
	 * Bouton TÃ©lÃ©chargement des PDF
	**/                             
	$$('p.boutonPDF').each(function(bouton) {   
		
		if (bouton.getParent().getElement('h2')!==null) {  
			bouton.getParent().getElement('h2').setStyle('cursor', 'pointer');
			bouton.getParent().getElement('h2').addEvent('click', function(e) { 
				e.stop();
				var url = bouton.getElement('a').get('href');
				window.location = url;
			});     
		}; 		
		if (bouton.getParent().getElement('img')!==null) {  
			bouton.getParent().getElement('img').setStyle('cursor', 'pointer');
			bouton.getParent().getElement('img').addEvent('click', function(e) { 
				e.stop();
				var url = bouton.getElement('a').get('href');
				window.location = url;
			});     
		}; 
		
 		bouton.addEvent('click', function(e) {
			e.stop();
			var url = bouton.getElement('a').get('href');
			window.location = url;
		});
	});




       
	
	           
	
	$$('div.actualite').each(function(actu) {
		actu.addEvent('click', function(e) {
			var url = actu.getElement('a').get('href');
			window.location = url;
		});
	});
	
	



    if ( $('commune')!==null) {    

		$('commune').addEvent('focus', function(e) { 
			var commune = $('commune').set('value', '');
		});    
		$('commune').addEvent('blur', function(e) {   
			if ($('commune').get('value')=='') {
				$('commune').set('value', 'Saisissez votre commune ...');
			};
		});     
		$('commune').addEvent('keyup', function(e) { 
			
			var commune = $('commune').get('value');
			requeteListeCommune(commune);
		});                          
	};                           
	
	

	
	        
	window.addEvent('keydown', function(e) { 
		if (e.key == 'enter') e.stop();
	});            





	if ($('zoneCarte2')!==null) {                      
 		$('garonne').addEvent('mouseover', function(e) {   
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone1').setStyle('opacity', '1');
		}); 	    
		$('picardie').addEvent('mouseover', function(e) { 
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone2').setStyle('opacity', '1');     
		}); 
 		$('loire').addEvent('mouseover', function(e) {    
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone3').setStyle('opacity', '1');     
		});   
 		$('rhin').addEvent('mouseover', function(e) {   
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone4').setStyle('opacity', '1');     
		});   
 		$('seine').addEvent('mouseover', function(e) {  
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone6').setStyle('opacity', '1');     
		});   
 		$('rhone').addEvent('mouseover', function(e) {  
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone5').setStyle('opacity', '1');     
		});   
 		$('corse').addEvent('mouseover', function(e) {  
        	$$('li.zone').setStyle('opacity', '.5');
			$('zone7').setStyle('opacity', '1');     
		});     
		
 		$('garonne').addEvent('mouseout', function(e) {   
        	$$('li.zone').setStyle('opacity', '1');
 		}); 	    
		$('picardie').addEvent('mouseout', function(e) { 
        	$$('li.zone').setStyle('opacity', '1');
 		}); 
 		$('loire').addEvent('mouseout', function(e) {    
        	$$('li.zone').setStyle('opacity', '1');
 		});   
 		$('rhin').addEvent('mouseout', function(e) {   
        	$$('li.zone').setStyle('opacity', '1');
 		});   
 		$('seine').addEvent('mouseout', function(e) {  
        	$$('li.zone').setStyle('opacity', '1');
 		});   
 		$('rhone').addEvent('mouseout', function(e) {  
        	$$('li.zone').setStyle('opacity', '1');
 		});   
 		$('corse').addEvent('mouseout', function(e) {  
        	$$('li.zone').setStyle('opacity', '1');
 		});  


		
 		$('garonne').addEvent('click', function(e) {   
        	var url = $('zone1').getElement('a').get('href');
			window.open(url);
 		}); 	    
		$('picardie').addEvent('click', function(e) {  
        	var url = $('zone2').getElement('a').get('href');
			window.open(url);
 		}); 
 		$('loire').addEvent('click', function(e) {   
        	var url = $('zone3').getElement('a').get('href');
			window.open(url);
 		});   
 		$('rhin').addEvent('click', function(e) {   
        	var url = $('zone4').getElement('a').get('href');
			window.open(url);
 		});   
 		$('seine').addEvent('click', function(e) {  
        	var url = $('zone6').getElement('a').get('href');
			window.open(url);
 		});   
 		$('rhone').addEvent('click', function(e) {   
        	var url = $('zone5').getElement('a').get('href');
			window.open(url);
 		});   
 		$('corse').addEvent('click', function(e) {  
        	var url = $('zone7').getElement('a').get('href');
			window.open(url);
 		});  

     	
	}



	if ($('zoneCarte')!==null) {     

		$('garonne').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_0').setStyle('display', 'block');
		}) 	    
		$('picardie').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_1').setStyle('display', 'block');
		}) 
 		$('loire').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_2').setStyle('display', 'block');
		})   
 		$('rhin').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_3').setStyle('display', 'block');
		})   
 		$('seine').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_5').setStyle('display', 'block');
		})   
 		$('rhone').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_4').setStyle('display', 'block');
		})   
 		$('corse').addEvent('mouseover', function(e) {   
			$$('div.c_agence').each(function(bulle) {   
					bulle.setStyle('display', 'none');  
			});       
			$('c_agence_4').setStyle('display', 'block');
		})  
		                     
		    
	};







var zTables = new ZebraTables('#colonneDroite #menu-agences');


  

});

var ZebraTables = new Class({
  //initialization
  initialize: function(table_class) {

    //add table shading
    $$(table_class + ' li').each(function(el,i) {

      //do regular shading
      var _class = i % 2 ? 'even' : 'odd'; el.addClass(_class);

 

    });
  }
});
