
// FONCTION NAV
var sensenav = 0;
var oldBtn;

function menu(el,sensenav){
	ToTop();
	oldBtn = 0;
	
	// Nouvel élément
	$$('.panel-block').setStyle('display','none');
	newId = String(el.id).replace('btn-','');
	newLayer = 'panel-'+newId;
	newBtn = 'btn-'+newId;
	
	$(newLayer).setStyle('display','block');
	navWrapFx = new Fx.Tween('navWrap');
	navWrapFx.addEvent('complete', function() {
		if (sensenav == 1)	{
			sensenav = 0;
		} else {
			sensenav = 1;
		}
	});
	
	layerFxNew = new Fx.Tween(newLayer);
	layerSize = $(newLayer).getStyle('height');
	
	var checkBtns = $$('.btn');
	for(i=0; i<checkBtns.length; i++){
		if(checkBtns[i].hasClass('on')){
			
			// Elements précédents
			oldId = String(checkBtns[i].id).replace('btn-','');
			oldLayer = 'panel-'+oldId;
			oldBtn = 'btn-'+oldId;	
			layerFxOld = new Fx.Tween(oldLayer);
			$(oldBtn).removeClass('on');
		}
	} 
	
	// Si je clique sur le même bouton
	if(oldBtn == el.id){
		if(sensenav == 1){
			navWrapFx.cancel();
			navWrapFx.start('height',layerSize+'px');
			$(oldBtn).addClass('on');
			
		}else{
			navWrapFx.cancel();
			navWrapFx.start('height',0);
		}	
		
		// Si je clique sur un autre bouton
	}else{
		//alert('je switch le contenu');	
		if(sensenav == 1){
			navWrapFx.start('height',layerSize);
			layerFxNew.start('opacity',1);
			$(newLayer).setStyle('visibility','visible');

		}else{
			navWrapFx.start('height',layerSize);
			layerFxNew.start('opacity',1);
		}
		
		el.addClass('on');
	}
}	

// FAQ ONCHANGE SELECT
function Onchangeselectbox(id){		
	// Module FAQ
		
	var selectbox = $$('.selectbox');
	selectbox.each(function(el) {
							
		el.addEvent('click',function(){
			var value_selectbox = el.get('value');
			//alert(value_selectbox);
			
			var param = $$('.parameter');
			//alert(param);
			param.set('value', value_selectbox);

			// contenu dynamique
			var contentProduct = '<strong>&bull; Title 1</strong><br /> texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique texte dynamique<br /><br /><strong>&bull; Title</strong><br /> is simply dummy text of the printing and typesetting   industry. Lorem Ipsum has been the industrys standard dummy text ever since the   1500s, when an unknown printer took a galley of type and scrambled it to make a   type specimen book. It has survived not only five centuries, but also the leap   into electronic typesetting, remaining essentially unchanged. It was popularised   in the 1960s with the release of Letraset sheets containing Lorem Ipsum   passages, and more recently with desktop publishing software like Aldus   PageMaker including versions of Lorem Ipsum.';
			
			
			$$('#'+id+' p').set('html', contentProduct);
			$$('#'+id+' p').setStyle('display','block');

		});
	});
}

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

	// NAV
	$$('.btn').each(function(el){
		el.addEvent('click', function()
		{
			menu(this,sensenav);
		});
	});
									 
	// BTN fermer nav
	$$('.panelClose').addEvent('click', function(el){
		navWrapFx.start('height',0);
		$(newBtn).removeClass('on');
	});
	
	
	// Accordeon Drop Produits
	var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'ul.element', {
		opacity: false,
		display:0,
		onActive: function(toggler, element)
		{
			$$('ul.element')[0].setStyle('height', '45px');
			toggler.removeClass('accordOpen');
			toggler.addClass('accordClose');
			

			if(toggler == $$('h3.toggler')[3])
			{
				$('navWrap').setStyle('height','660px');
			}else if(toggler == $$('h3.toggler')[1]){
				$('navWrap').setStyle('height','260px');
			}else if(toggler == $$('h3.toggler')[2]){
				$('navWrap').setStyle('height','364px');
			}else if(toggler == $$('h3.toggler')[4]){
				$('navWrap').setStyle('height','240px');
			}
		},
		onBackground: function(toggler, element)
		{
			$$('ul.element')[0].setStyle('height', 0);
			toggler.removeClass('accordClose');
			toggler.addClass('accordOpen');
		}
	});
	
	// tooltips		
	$$('.linkbulle').addEvent('mouseover', function(event){
			var _mouseX = parseInt(event.client.x);
			var _mouseY = parseInt(event.client.y);
			$$('.infobulle').setStyles({'left':_mouseX, 'top':_mouseY, 'display':'block'});
	 });
            
	$$('.linkbulle').addEvent('mouseout', function(){
			$$('.infobulle').hide();
	});

								
});


//TICKER FOOTER

window.addEvent('domready',function(){
	var hs1 = new noobSlide({
		box: $('box'),
		items: [1,2,3,4],
		size: 450,
		autoPlay: true
	});
});

//noobSlide (rev.19-06-08)
var noobSlide = new Class({

	initialize: function(params){
		this.items = params.items;
		this.mode = params.mode || 'horizontal';
		this.modes = {horizontal:['left','width'], vertical:['top','height']};
		this.size = params.size || 240;
		this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
		this.button_event = params.button_event || 'click';
		this.handle_event = params.handle_event || 'click';
		this.onWalk = params.onWalk || null;
		this.currentIndex = null;
		this.previousIndex = null;
		this.nextIndex = null;
		this.interval = params.interval || 10000;
		this.autoPlay = params.autoPlay || false;
		this._play = null;
		this.handles = params.handles || null;
		if(this.handles){
			this.addHandleButtons(this.handles);
		}
		this.buttons = {
			previous: [],
			next: [],
			play: [],
			playback: [],
			stop: []
		};
		if(params.addButtons){
			for(var action in params.addButtons){
				this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
			}
		}
		this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:500,wait:false}),{property:this.modes[this.mode][0]}));
		this.walk((params.startItem||0),true,true);
	},

	addHandleButtons: function(handles){
		for(var i=0;i<handles.length;i++){
			handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
		}
	},

	addActionButtons: function(action,buttons){
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
				case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
				case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
				case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
				case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
			}
			this.buttons[action].push(buttons[i]);
		}
	},

	previous: function(manual){
		this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),manual);
	},

	next: function(manual){
		this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),manual);
	},

	play: function(interval,direction,wait){
		this.stop();
		if(!wait){
			this[direction](false);
		}
		this._play = this[direction].periodical(interval,this,[false]);
	},

	stop: function(){
		$clear(this._play);
	},

	walk: function(item,manual,noFx){
		if(item!=this.currentIndex){
			this.currentIndex=item;
			this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
			this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
			if(manual){
				this.stop();
			}
			if(noFx){
				this.fx.cancel().set((this.size*-this.currentIndex)+'px');
			}else{
				this.fx.start(this.size*-this.currentIndex);
			}
			if(manual && this.autoPlay){
				this.play(this.interval,'next',true);
			}
			if(this.onWalk){
				this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
			}
		}
	}
	
});