/*Cufon.replace('h5.cuf,#paccbio,.blocsanteacc h4,.blocformeacc h4,.blocformeacc2 h4,.blocdecouverteacc h4,h2,h3, a.todo,#drop_down_menu li a.todo,#prelaisside h4,#prelaisside ul li a, a.bouton,ul.listeProduits li a span.nomArticle,#nouscontacter a, #plusdecontact,#h5bdpacc, a.acheter, .description h4, h5.choixreg,#fichepanier th, #footer h4');
*/


var Bibi = {

	doSelectPR : function() { //fct qui affiche le select des pr d une ville
		if ($('elpr_ville')) {
			var val = $('elpr_ville').value;
			if (val!=0) {
				$$('.selpr').each(function(el){el.setStyle('display','none');});
				if ($('elpr_nom_'+val)) {$('elpr_nom_'+val).setStyle('display','');}
			}
		}
	},
	checkNav : function() {
		//Biobox de gauche maj href
		var TableMenu=$$("ul.tofont li ul li a");
		
		//Menu princ - idem + comportement
		var list = $$("#drop_down_menu li.menu ul.links"); 	
		$$('#drop_down_menu li.menu').each( function( elem, i ){
			//if (i==0) { var un = elem.getElements('a'); un[0].set('href','./'); }
			var un = elem.getElements('ul.links li a');
			var non=0;
			
			un.each(function(elel,b){
				if (elel.hasClass('actif')){non=1;}
				if (i==2 && b==3) {elel.set('href','dossier.php?id_dossier=6');}
			});
			if (i==0 && elem.hasClass('active')) {non=1;}
			if (non==0) {	
				list[i].setStyle('display','none');		
				elem.addEvents({ 
					'mouseenter' : function(){ list[i].setStyle('display','')},
					'mouseleave' : function(){ list[i].setStyle('display','none')}
				});	

			}	
		});
		//recherche si on a un ss menu actif
		$$('#drop_down_menu ul.links li a.actif').each( function( elem ){
			elem.getParent().getParent().show();
		});
		//if ($$('#drop_down_menu li.princ1').hasClass('active')) {$$('#drop_down_menu li.princ1 ul').show();}	
		//if ($('moteurEtCatalogue'))Ê{
		//hauteur contenu
		//var taille = $('moteurEtCatalogue').getCoordinates();
		//var taille2 = $('contenu').getCoordinates();
		//alert(taille.bottom);
		//alert(taille2.bottom);
		//var total = taille.bottom - taille2.bottom;
		/*if (total>taille2.height) {
		$('contenu').setStyle('height',taille2.height+total);}
		if ($('leblocdossier')) {
			$('leblocdossier').setStyle('height',total-20);
			
		}*/
		//}
		
		if ($$('a.amarkcmd')) {
			var latable=$$('a.amarkcmd');
			latable.setStyle('opacity',.5);
			$$('a.amarkcmd').each(function(el,i) {
			
				el.addEvents({
				'click':function(event){
						if (event) {event.stop();}
						toto=el.get('rel');
						$$('.selpr').each(function(el){el.setStyle('display','none'); el.set('disabled','disabled'); el.removeClass('actif');});
						if ($('elpr_nom_'+toto)) {
							$('elpr_nom_'+toto).setStyle('display','');
							el.setStyle('opacity',1);
							$('elpr_nom_'+toto).set('disabled','');
							$('elpr_nom_'+toto).addEvent('change',function(){
								$('resume_pr').set('html',$('elpr_nom_'+toto).value);
								if ($('c_pr')) {$('c_pr').value=$('elpr_nom_'+toto).value;}
							});
	
							el.addClass('actif');
							latable.each(function(ele,k) {if (ele.get('id')!=el.get('id')) {ele.setStyle('opacity',.5);} })
						}
					},
					'mouseenter' : function(){ if (!el.hasClass('actif')){el.set('morph',{'duration':'short'}); el.morph({'opacity':1});} },
			'mouseleave' : function(){ if (!el.hasClass('actif')){el.set('morph',{'duration':'short'}); el.morph({'opacity':.5});} }
					});
			
			});
		}
		
	},
	calculeTotal:function() {
	var total = 0;
	var tututext = "";
	$$('#formpane input.marquemoi').each(function(el,i) {
		var ta= 'td_prix-'+el.get('id');
		var to = $(ta).get('text').toInt() * el.value.toInt();
		total = total + to;
		var tutu= 'titre-'+el.get('id');
		if (el.value.toInt()>0) {tututext=tututext + el.value.toInt()+' X '+$(tutu).get('text')+' ('+$(ta).get('text').toInt()+' &euro;)<br>';}
		
	});
	$('td_paniertotal').set('text',total);
	if (total>0) {$('anextto2').fade('in');} else {$('anextto2').fade('out');}
	$('resume_total').set('text',total);
	$('resume_text').set('html',tututext);
	
	if ($('c_box')) {$('c_box').value=tututext;}
	if ($('c_total')) {$('c_total').value=total;}
	
	},
	doPane:function() {
	
	$$('#formpane input.marquemoi').each(function(el,i) {
	
	var upButton = new Element('div',{
			text: '+',
			'class': 'button',
			events: {
				click: function() {
					el.value = el.value.toInt() + 1;
					var ti= 'td_total-'+el.get('id');
					var ta= 'td_prix-'+el.get('id');
					var to = $(ta).get('text').toInt() * el.value.toInt();
					$(ti).set('text',to);
					Bibi.calculeTotal();
				}
			}
		}).inject(el.getParent());
	
	
	var downButton = new Element('div',{
			text: '-',
			'class': 'button dec',
			events: {
				click:function() {
					var val = el.value.toInt();
					if(val != 0) {
						el.value = val - 1;
						var ti= 'td_total-'+el.get('id');
					var ta= 'td_prix-'+el.get('id');
					var to = $(ta).get('text').toInt() * el.value.toInt();
					var toto = $('td_paniertotal').get('text').toInt() - $(ta).get('text').toInt();
					$(ti).set('text',to);
					Bibi.calculeTotal();
					}
				}
			}
		}).inject(el.getParent());
		
	});	
	
	},
	SlideMonActu : function() {
		if ($('divactubionews')) {
	var layers=$$('#divactubionews a');
	layers.setStyle('position','absolute');
	layers.each(function(el,i){
		if(i>0) {el.setStyles({'opacity':'0','visibility':'hidden'});}});
	var delay = 5000;
   	var i=0;
   	setInterval(function(){ layers[i].fade('out');  i = (i == layers.length-1)? 0 : i+1; layers[i].fade('in');},delay);
}
	},
	doPageCmd : function() {
	//COMMANDE
	
	Cufon.replace('#fichepanier th');
	
		new Fx.Reveal($('holdformcmd')).dissolve();
		if ($('mystep2')) {new Fx.Reveal($('mystep2')).dissolve();}
		if ($('mystep3')) {new Fx.Reveal($('mystep3')).dissolve();}
	
		if ($('h3step2')) {
	$('h3step2').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step2').addEvent('click',function(event) {
	if (event) {event.stop();}
	if ($('resume_total').get('text')!="0") {
	new Fx.Reveal($('mystep1')).dissolve();
	new Fx.Reveal($('mystep2')).reveal();
	new Fx.Reveal($('mystep3')).dissolve();
	$('h3step2').setStyles({'cursor':'pointer','opacity':1});
	$('h3step1').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step3').setStyles({'cursor':'pointer','opacity':.5});
	$('anextto2').fade('out'); 
	
	} else {
	alert('Votre panier est vide !\nMerci de choisir une biobox d\'abord.');
	}
	});
}
if ($('anextto2')) {
	//$('h3step2').setStyles({'cursor':'pointer','opacity':.5});
	$('anextto2').addEvent('click',function(event) {
	if (event) {event.stop();}
	if ($('resume_total').get('text')!="0") {
	new Fx.Reveal($('mystep1')).dissolve();
	new Fx.Reveal($('mystep2')).reveal();
	new Fx.Reveal($('mystep3')).dissolve();
	$('h3step2').setStyles({'cursor':'pointer','opacity':1});
	$('h3step1').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step3').setStyles({'cursor':'pointer','opacity':.5});
	$('anextto2').fade('out');
	} else {
	alert('Votre panier est vide !\nMerci de choisir une biobox d\'abord.');
	}
	});
}




if ($('h3step3')) {
	$('h3step3').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step3').addEvent('click',function(event) {
	if (event) {event.stop();}
	if ($('resume_total').get('text')!="0") {
	if ($('resume_pr').get('text')!="-") {
	new Fx.Reveal($('mystep1')).dissolve();
	new Fx.Reveal($('mystep3')).reveal();
	new Fx.Reveal($('mystep2')).dissolve();
	$('h3step2').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step1').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step3').setStyles({'cursor':'pointer','opacity':1});

	} else {
	alert('Merci de choisir d\'abord votre point relais !');
	new Fx.Reveal($('mystep1')).dissolve();
	new Fx.Reveal($('mystep2')).reveal();
	new Fx.Reveal($('mystep3')).dissolve();
	$('h3step2').setStyles({'cursor':'pointer','opacity':1});
	$('h3step1').setStyles({'cursor':'pointer','opacity':.5});
	$('h3step3').setStyles({'cursor':'pointer','opacity':.5});
	}
	
	} else {
	alert('Votre panier est vide !\nMerci de choisir une biobox d\'abord.');
	
	}
	});

}


if ($('anextto3')) {
$('anextto3').addEvent('click',function(event) {
if (event) {event.stop();}
$('h3step3').fireEvent('click');
});
}


if ($('h3step1')) {
//$('h3step1').setStyle('cursor','pointer');
$('h3step1').addEvent('click',function(event) {
if (event) {event.stop();}
new Fx.Reveal($('mystep1')).reveal();
new Fx.Reveal($('mystep2')).dissolve();
new Fx.Reveal($('mystep3')).dissolve();
$('h3step2').setStyles({'cursor':'pointer','opacity':.5});
$('h3step3').setStyles({'cursor':'pointer','opacity':.5});
$('h3step1').setStyles({'cursor':'pointer','opacity':1});
if ($('resume_total').get('text')!="0") {$('anextto2').fade('in');} else {$('anextto2').fade('out');}



});

}
	if ($('amodmypr')) {
$('amodmypr').addEvent('click',function(event) {
if (event) {event.stop();}
$('h3step2').fireEvent('click');
});
}
	if ($('amodmybio')) {
$('amodmybio').addEvent('click',function(event) {
if (event) {event.stop();}
$('h3step1').fireEvent('click');
});
}
	
	
	
if ($('parmel')) {
		$('parmel').addEvent('click',function(event) {
			if (event) {event.stop();}
			if ($('resume_text').get('html')!="-" && $('resume_pr').get('html')!="-" && $('resume_total').get('html')!="0") {
			new Fx.Reveal($('holdformcmd')).reveal();
			} else {alert('Attention : merci de choisir d\'abord votre biobox et votre point relais. Merci !')}
		});
			
	}
	if ($('clichere')) {
$('clichere').addEvent('click',function(event) {
if (event) {event.stop();}
$('parmel').fireEvent('click');
});
}	
	
	
	
	//END COMMANDE
	},
	doOnReady : function() {
		
	
	Cufon.replace('ul.tofont li ul li a', {
	hover: true,
	fontSize: '18px'

});
Cufon.replace('#drop_down_menu li a.todo', {
	
	fontSize: '20px'

});


	
		if ($$('#prelaisside h4 a.acc')) {
			Cufon.replace('#prelaisside h4 a.acc', {hover: true});
			}
			 
		Cufon.replace('#paccbio,h2,h3,#prelaisside h4,#footer h4');
		if ($$('h5.cuf')) {Cufon.replace('h5.cuf');}
		Bibi.checkNav();
		if ($('formpane')) {Bibi.doPane();}
		if ($('holdformcmd')) {Bibi.doPageCmd();}
		
		//ADD ACTION onchange SELECT DES VILLES PR
		if ($('elpr_ville')) { 
			$('elpr_ville').addEvent('change',function(){Bibi.doSelectPR()});}
		
		
	var mySmoothScroll = new Fx.SmoothScroll({
    links: '.smoothAnchors',
    wheelStops: false
});

	
	
	
	if ($$('.opener')) {
		var myAccordion = new Fx.Accordion($$('.opener'), $$('.elements'), {
    display: -1,
    alwaysHide: false
    
});

	}
	
	if ($$('.openeur a')) {
		var myAccordion = new Fx.Accordion($$('.openeur a'), $$('.ouvre'), {
    display: 0,
    alwaysHide: false,
    onBackground:function(tog,ele) {
    		tog.removeClass('onit'); 
    		Cufon.replace('h5.openeur a', {hover: true});
    		},
    		onActive:function(tog,ele) {
    			$$('.openeur a').removeClass('onit'); tog.addClass('onit');
    		}
});

	
		}
	}

}


window.addEvent('domready', function(){ Bibi.doOnReady(); });	
window.addEvent('load', function(){ 

Bibi.SlideMonActu();







if ($('formular')) { 
   		if ($('formular').hasClass('pop')) {var laposi='left';} else {var laposi='left';}
   		
   		new FormCheck('formular', {
   			trimValue : true,
            display : {
                scrollToFirst : true,
                tipsPosition : laposi
            }});
            
   }

 });