var Site = {
		
	start: function(){
		
		$$('.external').addEvent('click', function(ev){
				window.open(this.href); 
				new Event(ev).stop(); 
				return; 
		});
		
		if($('choixProduits'))	Site.change();
		if($('rightcolumn')) Site.opacity();
		if($('input_search')) Site.rechercher();

		if($('accordion')) Site.accordion();
		if($('contactprecisions')) Site.visibility($('select'), $('contactprecisions'));
		if($('s_type')) Site.visibility($('s_type'), $('s_precisions'));		
		if($('slideshow'))	new BarackSlideshow('menu', 'pictures', 'loading', {transition: 'fade', auto:true, autostart: true});
		if($$('.newsticker')) new viewer($$('.newsticker'),{mode: 'alpha',interval: 5000}).play(true);
		if ($('voeux')) { Site.show(); }
		
	},
	
	visibility: function(select, input){		
		
		input.slide('hide');
		
		select.addEvent('change', function(){	
			
			input.slide('out');
			select.setStyle('margin-bottom', '0');
			
			if(this.value=='Autres') 
				input.slide('in');
				select.setStyle('margin-bottom', '8px');
		});
		
		
	},
	
	accordion : function(){
		
		$$('h5.togglers').setStyle('cursor', 'pointer');
		
		var myAccordion = new Fx.Accordion($$('.togglers'), $$('.elements'), {
		    display: -1,
		    alwaysHide: false,
		    onActive: function(toggler, element){
			},
			onBackground: function(toggler, element){
			}
		});
		
		var href=window.location.href.toString().split('#');	
		var accId=href[1];
	
		var counter=0;
		$$('.togglers').each(function(el,i){
		
			if(el.get('id')==accId)
			{
				counter=i;
			}
		});

		myAccordion.display(counter);
		
	},

	rechercher : function(){
		
		$('input_search').addEvents({
			
			'focus': function() {
				if(this.value=='Rechercher') 
					this.value='';			
			},	
			
			'blur': function() {
				if(this.value=='') 
					this.value = 'Rechercher';			
			}
				
		});	
		
	},	
	
	change : function(){
		
		var familles = $('choixProduits').getElements('option[]');
	
		$('choixProduits').addEvent('change', function(){
			url = $('formProduits').action + this.value + '/';			
			location.href = url;	
	    });
	
		familles.each(function(element){
		
			if(element.value!=-1){
				
				element.addEvent('mouseover', function(){
					this.addClass('active');
			    });
				
				element.addEvent('mouseout', function(){
					this.removeClass('active');
			    });
				
			}
			
		});	
	},
	
	opacity : function(){
		
		var labels = $('rightcolumn').getElements('a[]');
	
		labels.each(function(element){
			
			if(element.get('class')=='external selected'){
			
				element.set('opacity','.' + 50);
			
			}else{
			
				element.addEvent('mouseover', function(){
					element.set('opacity','.' + 50);
			    });
				
				element.addEvent('mouseout', function(){
					element.set('opacity',1);
			    });

			}
			
		});	
	},
	
	link : function(){

		$$('.more').setStyle('display','none');
		
		$('blocActus').setStyle('cursor','pointer');
		a = $$('.more').href;
		
		$('blocActus').addEvent('click', function(){
			window.open(this.href); 
			document.location = a; 
		});	
	
	},
	
	show: function() {
		
		$(document.body).setStyle('position', 'relative');
		$('voeux').setStyle('display', 'block');
		
		var effect = new Fx.Morph('voeux', {duration: 2000, transition: Fx.Transitions.Sine.easeOut});
 
		effect.start({
		    'right': [-350, 0]
		});
			
		$('voeux').addEvents({
			'click': function(ev){
				new Event(ev).stop(); 
				new Fx.Morph('voeux', {duration: 2000, transition: Fx.Transitions.Sine.easeOut,  onComplete: function(){ $('voeux').setStyle('display','none') } }).start({'right': [0, -350]});
			},
			'mouseover': function(){
				
				var right = this.getStyle('right').toInt();

				if( right==-350) {
					effect.start({
					    'right': [-350, 0]
					});
				}
			}
		});
		
	}
		
	
}



window.addEvent('domready', function(){
	Site.start();
});



