//------------------- ET JEZ INVENTA LE SOMMAIRE DE FICHIER JS ---------------------//
//--- [MAIN]		- Main init
//--- [HOMEPAGE]	- 
//--- [CONTENT]		- Contenu
//--- [FICHE]		- Fiche
//--- [SHIPPING]	- Livraison
//--- [FOOTER]		- Barre des langues et radio boutons
//----------------------------------------------------------------------------------// 

/*--------------------------------- [MAIN] ---------------------------------*/
jQuery(document).ready(function() {
	
	var BBTool_pageSizes 			= BBTool_getPageSize();
	var BBTool_pageScroll 			= BBTool_getPageScroll();
	
		BBVars.pageWidth 			= BBTool_pageSizes[0];
		BBVars.pageHeight 			= BBTool_pageSizes[1];
		BBVars.windowWidth 			= BBTool_pageSizes[2];
		BBVars.windowHeight 		= BBTool_pageSizes[3];
		BBVars.pageScrollX 			= BBTool_pageScroll[0];
		BBVars.pageScrollY 			= BBTool_pageScroll[1];
		
		BBVars.dataSendContentID	= ($(".dataSend").length>0) ? $(".dataSend").attr("id") : "";
		
	jQuery(window).bind("resize", function() {
	    BBTool_pageSizes 			= BBTool_getPageSize();
		BBVars.pageWidth 			= BBTool_pageSizes[0];
		BBVars.pageHeight 			= BBTool_pageSizes[1];
		BBVars.windowWidth 			= BBTool_pageSizes[2];
		BBVars.windowHeight 		= BBTool_pageSizes[3];
	}).bind("scroll", function() {
		BBTool_pageScroll 			= BBTool_getPageScroll();
		BBVars.pageScrollX 			= BBTool_pageScroll[0];
		BBVars.pageScrollY 			= BBTool_pageScroll[1];
	});
		
	//initDebug();
	initLangList();
	initBBSlider();
	initBBSelect();
	initBBCheckbox();
	initBBRadio();
	initContentMenu();
	initMainMenu();
	dspSignsImg();
	initNavBtn();
	initCatHome();
	dspnewAccountLayer();
	dspBasketDetail();
	getLastSeenProducts();
	fInitSymbols();
	keyLogin_callback();
	initBBSelect('#quickSearch_layer');
	initXitiClick();
	
	if(BBSettings.BBForms.checkFormMethod=="rt"||jQuery("form[check=rt]").length>0) BBTool_initRTForms();
	if(jQuery(".BBTTip").length>0) BBTool_toolTip();
	
	// ACTIVATION DE LA POPUP PROMO CKDO
	//if(BBVars.displayCKDO=="1") popup_CKDO();
	
	//if(BBVars.currentPageName!="paiement") {
		BBCart("check");
		initLoginBlock();
		BBAccount("check");
		BBTool_flash();
	//}
	
	if(BBVars.currentPageName=="index") {
		initHomepage();
	} else if(BBVars.currentPageName=="univers" || BBVars.currentPageName=="selection" || BBVars.currentPageName=="recherche") {
		initQuickBy();
	} else if(BBVars.currentPageName=="livraison") {
		initShippingPage();
	} else if(BBVars.currentPageName=="fiche") {
		updateLastSeenProducts(ref_produitid_lastseen,ref_color_lastseen);
		if(jQuery(".checkBox").length>1) {
		
			jQuery(".product_form").css("opacity", 1);
		
			jQuery(".checkBox").each( function(i,el) {
		
				jQuery(this).bind("click", function(evt) {
					
					evt.preventDefault();
					jQuery(this).toggleClass("checked");
					
					var sListNb = jQuery("ul.sizesList:visible").length;
					var selectedSListNb = 0;
					var totalPrice = jQuery("#InPrixTot").val();
					
					
					jQuery("ul.sizesList").each( function(j,elem) {
						if( !eval(jQuery("#check"+jQuery(this).attr("prodID")).hasClass("checked")) ) {
							totalPrice -= jQuery(this).attr("price") * eval(jQuery("#prodQty"+jQuery(this).attr("prodID")).html());
							sListNb--;
						} else if (jQuery("#product_form"+jQuery(this).attr("prodID")+" .selected").length==1) selectedSListNb++;
					});
					jQuery("#prixTot").html(BBVars.currentPriceFormat.replace("{price}", NumberFormat((Math.abs(totalPrice)).toFixed(2))));
					
					jQuery(this).parents(".product_form").stop().animate({ opacity: ( (jQuery(this).parents(".product_form").css("opacity")==1)?0.2:1 ) });
					
					if(sListNb==selectedSListNb) jQuery(".noAttribLayer").stop().animate({opacity: 0}, function() { jQuery(this).css("display","none")});
					else jQuery(".noAttribLayer").css("display", "block").stop().animate({opacity: 0.5});
					
					if(jQuery(".product_form .checked").length==0) {
						jQuery(".totalPriceLayer .pinkBtn").stop().animate({opacity: 0}, function() { jQuery(this).css("display", "none"); })
					} else {
						jQuery(".totalPriceLayer .pinkBtn").stop().css("display", "block").animate({opacity: 1})
					}
				});
				
			});
		}
	} else if(BBVars.currentPageName=="compte_suivi") {
		dspOrderDetails();
	} else if(BBVars.currentPageName=="compte_panier") {
		initDeleteList();
	} else if(BBVars.currentPageName=="silhouettes") {
		initSilhouette();
	} else if(BBVars.currentPageName=="collection") {
		if(jQuery("#collectionListLayer").length>0) initCollectionHome();
		if(jQuery("#tpListLayer").length>0) initScrollable();
	} else if(BBVars.currentPageName=="espace_fidelite") {
		if(jQuery("#fidToolbarLayer").length>0) {
			var btnLayer = jQuery("#fidToolbarLayer"),
				cancelBtn = jQuery("#cancelBtn"),
				modifyBtn = jQuery("#modifyBtn"),
				civLayer = jQuery("#civRadioLayer"),
				civLabel = jQuery("#civLabel"),
				form = jQuery("#fidelityArea_form"),
				astLabels = jQuery("span.astLabel", form),
				inputs = jQuery("input[id!=#numMembre]", form),
				list = jQuery("ul", form),
				mandatoryLabel = jQuery(".italic", list),
				cgvList =jQuery("#fidCGV");
			
			cancelBtn.bind("click", function(e) {
				e.preventDefault();
				list.addClass("disabled");
				inputs.attr("readonly", "true");
				btnLayer.stop().animate({opacity: 0}, function() {jQuery(this).css({visibility: "hidden"})});
				astLabels.stop().animate({opacity: 0}, function() {jQuery(this).css({visibility: "hidden"})});
				mandatoryLabel.stop().animate({opacity: 0}, function() {jQuery(this).css({visibility: "hidden"})});
				civLayer.stop().animate({opacity: 0}, function() {
					jQuery(this).css("display", "none");
					civLabel.css({display: "block", opacity: 0}).animate({opacity: 1});
				});
				btnLayer.stop().animate({opacity: 0}, function() {
					jQuery(this).css("display", "none");
					modifyBtn.css({display: "block", opacity: 0}).animate({opacity: 1});
				});
			});
			modifyBtn.bind("click", function(e) {
				e.preventDefault();
				inputs.removeAttr("readonly");
				list.removeClass();
				btnLayer.stop().css({opacity: 0, visibility: "visible"}).animate({opacity: 1});
				astLabels.stop().css({opacity: 0, visibility: "visible"}).animate({opacity: 1});
				mandatoryLabel.stop().css({opacity: 0, visibility: "visible"}).animate({opacity: 1});
				civLabel.stop().animate({opacity: 0}, function() {
					jQuery(this).css("display", "none");
					civLayer.css({display: "block", opacity: 0}).animate({opacity: 1});
				});
				modifyBtn.stop().animate({opacity: 0}, function() {
					jQuery(this).css("display", "none");
					btnLayer.css({display: "block", opacity: 0}).animate({opacity: 1});
				});
			});
			
			jQuery("dt", cgvList).bind("click", function(e) {
				jQuery("dd", cgvList).slideToggle();
			});
			
		}
	}
	
/*
	else if(BBVars.currentPageName=="index") {
	
		homepageInit();
		jeux_MPA();
		
	} else if(BBVars.currentPageName=="fiche") {
		
		InitPictoRea();
		initComment();
		jQuery("#gallery li.BBTool_galMainImg").bind("mouseenter", function() {
			jQuery("#zoom_label").stop().animate({opacity: 0}, 100, function() {jQuery(this).css("display", "none");});
		}).bind("mouseleave", function() {
			jQuery("#zoom_label").css("display", "block").stop().animate({opacity: 1});
		});

	} else if(BBVars.currentPageName=="panier") {
		
		hideDelivery();
		
	} else if(BBVars.currentPageName=="compte_perso") {
		var options = {
			header:			'strong', 
			autoheight:		false,
			active: 		false
		}
		$("#account_list").accordion(options);
		
	} else if(BBVars.currentPageName=="paiement") {
	
		jQuery("#cartLayer .checkoutOverlay")
			.css({
				opacity: 0.2,
				height: jQuery("#cartLayer").height()+"px"
			})
	
	}*/
	
});
/*------------------------------------------------------------------------------*/



/*----------------------------------- [FICHE] ----------------------------------*/
function initGallery( galID, picID ) {

	var zoom = eval(jQuery("#"+galID).attr("zoom"));

	jQuery("#"+galID+" li[class!='nav'] a").each( function(i) {
			
		if(i==0) {
			jQuery("img", this)
				.bind("load", function() {
					jQuery(this).animate({opacity:1});
				}).bind("click", function(e) {
					if(zoom) getGallery(jQuery(this).attr("currentPic"));
					e.preventDefault();
				})				
				.addClass("BBGallery_mainProdImg");
		} else {
			jQuery(this).bind("click", function(e) {
				var newImg = jQuery(this).attr("href");
				jQuery("#"+galID+" li a img.BBGallery_mainProdImg").animate({opacity: 0}, function() {
					jQuery(this).attr("src", newImg);
					jQuery(this).attr("currentPic", i);
				});
				e.preventDefault();
			});
		}
			
	});
	
	picID = (typeof(picID)=="undefined") ? 0 : picID;
	if(picID!=0) {
		jQuery("#"+galID+" li a img.BBGallery_mainProdImg")
				.css({opacity: 0, display: "block"})
				.attr("src", jQuery("#"+galID+" li[class!='nav'] a").eq(picID).attr("href"))
				//.attr("currentPic", picID);
	}

}


/*------------------------------------------------------------------------------*/


/*--------------------------------- [SHIPPING] ---------------------------------*/
function initShippingPage() {
		
	jQuery("#shippingModeList li").bind("click", function() {
		
		jQuery("#erreur_liv").html("");
		jQuery("input", this).attr("checked","checked");
		
		shippingCountryTest();	
		
		if(jQuery("input:checked", this).attr("value") == 1) {
			if(jQuery("#mapLayer").height() > 0) jQuery("#mapLayer,#shopAdrList,#shopAdrListKiala").stop().animate({opacity: 0, height: 0}, function() {jQuery(this).css("display", "none")});
			jQuery("#shipInfosLayer").stop().animate({opacity: 1, height: "300px"});
			jQuery("#shipInfosLayer").css("display", "block");
			
			 var pays_livrable = false;
        
	        jQuery("#frmFacturation #pays_coli option").each( function(i,el){
	        	if (jQuery("option",this).val() == jQuery("#account_form #pays_fact").val())
	        		{pays_livrable = true;}
	        });
	        
	        if (pays_livrable){
	        	jQuery('#selectAdr').val(-1);
	        	charge_adresse();
	        }
		}
		else if(jQuery("input:checked", this).attr("value") == 5) {
			jQuery("#shopAdrListKiala").css("display", "block").animate({opacity: 1, height: "561px"});
			jQuery("#mapLayer").css("display", "block").animate({opacity: 1,height :"300px"});
			jQuery("#shipInfosLayer,#shopAdrList").stop().animate({opacity: 0, height: 0}, function() {jQuery(this).css("display", "none")});
			// Initialisation de le googlemap pour Kiala 			
		  	initialize_kiala(1);
		}
		else if(jQuery("input:checked", this).attr("value") == 2) {
			jQuery("#shopAdrList").css("display", "block").animate({opacity: 1, height: "627px"});
			jQuery("#mapLayer,").css("display", "block").animate({opacity: 1,height :"300px"});
			jQuery("#shipInfosLayer,#shopAdrListKiala").stop().animate({opacity: 0, height: 0}, function() {jQuery(this).css("display", "none")});
			
			// Initialisation de le googlemap pour les magasins
			initMarkers_magasin(1);
		}	
	});
	

	if (jQuery("#shippingModeList li input[id=mode_livraison_select2]").attr("checked")) {
		initMarkers_magasin(1);
		jQuery("#shippingModeList li").eq(jQuery("#shippingModeList li input[name=mode_livraison_select]").index(jQuery("#shippingModeList li input[id=mode_livraison_select2]"))).trigger("click");
	} else if (jQuery("#shippingModeList li input[id=mode_livraison_select5]").attr("checked")) {
		initialize_kiala(1);
		jQuery("#shippingModeList li").eq(jQuery("#shippingModeList li input[name=mode_livraison_select]").index(jQuery("#shippingModeList li input[id=mode_livraison_select5]"))).trigger("click");
	} else if (jQuery("#shippingModeList li input[id=mode_livraison_select1]").attr("checked"))
		jQuery("#shippingModeList li").eq(jQuery("#shippingModeList li input[name=mode_livraison_select]").index(jQuery("#shippingModeList li input[id=mode_livraison_select1]"))).trigger("click");
	
	
	jQuery("#factAdrModBtn").bind("click", function(e) {
		e.preventDefault();	
		jQuery(this).stop().animate({opacity: 0}, function() { jQuery(this).css("display", "none"); });
		jQuery("a#factAdrCancelBtn, a#factAdrValidateBtn, form#account_form :input").css("display", "block").stop().animate({opacity: 1});
	});
	
	jQuery("a#factAdrCancelBtn").bind("click", function(e) {
		e.preventDefault();
		jQuery("#factAdrModBtn").css("display", "block").stop().animate({opacity: 1});
		jQuery("a#factAdrCancelBtn, a#factAdrValidateBtn, form#account_form :input").stop().animate({opacity: 0}, function() { jQuery(this).css("display", "none"); });
	});
	
	jQuery("a#search_kiala").bind("click", function(e) {
		e.preventDefault();
		BBKiala(jQuery('#code_postal_search_kiala').val(), jQuery('#pays_kiala').val());
	});
	
	jQuery("a#search_mag").bind("click", function(e) {
		e.preventDefault();
		BBMagasin(jQuery('#shopAdrList #pays_mag').val(), jQuery('#shopAdrList #departement').val(), '');
		
	});
	
	jQuery(".country").bind("change", function() {
		var selectValue = jQuery(this).val();
		jQuery(".zipCode").attr("maxlength", (selectValue=='FR') ? 5 : 4 );
	});
               
	shippingCountryTest();
}

function shippingCountryTest() {
	var countryList = "FR,BE,LU,MC,"; 

	if( countryList.indexOf(jQuery("#account_form #pays_fact").val())==-1 && jQuery("#shippingModeList input:checked").val()==1) {
		jQuery("#frmFacturation input").val("");
		jQuery("#msgLayerCountry").html(BBLabels.label_wrongShippingCountry);
	} else jQuery("#msgLayerCountry").html("");
}

/*------------------------------------------------------------------------------*/

/*--------------------------------- [HOMEPAGE] ---------------------------------*/

function initHomepage() {

	jQuery("#homepageLayer .select").each( function(i,el) {
	
		jQuery("img.selectImg", this).bind("load", function() {jQuery(this).stop().animate({opacity: 1})});
	
		jQuery(".selectList li a", this).bind("mouseenter", function(e) {
		
			var params = jQuery(this).attr("rev").split(';');
			var currentID = jQuery(this).attr("rel");
			
			jQuery("#infos" + currentID).stop().animate({opacity: 0}, function() {
				jQuery(".selectLabel strong", this).html( params[1] );
				jQuery(".selectPrice strong", this).html( params[2] );
				jQuery(".buyBtn", this).attr("href", BBVars.pagesURL + params[0]);
			});
			jQuery("#img" + currentID).stop().animate({opacity: 0}, function() {
				jQuery(this).attr("src", params[3]);
				jQuery("#infos" + currentID).stop().animate({opacity: 1});
			});
			
		
		}).bind("click", function(e) {e.preventDefault(); });
	
	});

}

/*------------------------------------------------------------------------------*/

/*----------------------------- [HOMEPAGE UNIVERS] -----------------------------*/
function initCatHome() {

	jQuery("div.sliderLayer").each( function(i,el) {
	
		var scrollable = (jQuery("li", this).length>3) ? true : false;
		if(scrollable) {
		
			var currentList = jQuery("ul", this);
			
			jQuery(".nextBtn", this).bind("click", function( e ) {
			
				e.preventDefault();
				var allItems = jQuery("li", currentList);
				var newElem = allItems.eq(0);
				var lastItem = allItems.eq(allItems.length-1);
				newElem.clone(true).insertAfter(lastItem);
				newElem.animate({ marginLeft: "-=115" }, function() {
					jQuery(this).remove();
				});
			});
			
			jQuery(".prevBtn", this).bind("click", function( e ) {
			
				e.preventDefault();
				var allItems = jQuery("li", currentList);
				var newElem = allItems.eq(allItems.length-1);
				var firstItem = allItems.eq(0);
				newElem.clone(true).insertBefore(firstItem).css({marginLeft: "-115px"})
						.animate({ marginLeft: "+=115" }, function() { allItems.eq(allItems.length-1).remove(); });
			
			
			});
		
		}
	
	});

}

/*------------------------------------------------------------------------------*/

/*---------------------------------- [UNIVERS] ----------------------------------*/

function initQuickBy() {
	
	jQuery(".quickBuy").css({display: "none"});
	
	jQuery("#products_list li").each( function() {
	
		jQuery(".productImg_layer", this).bind("mouseenter", function(e) {
			jQuery(".quickBuy", this).css({display: "block", opacity: 0}).stop().animate({opacity: 1}, function() {
					if(BBVars.isMsIE)
						this.style.removeAttribute("filter");
				});

		}).bind("mouseleave", function(e) {
			jQuery(".quickBuy", this).stop().animate({opacity: 0}, function(){jQuery(this).css("display", "none")});
		});
	
	});

}


/*------------------------------------------------------------------------------*/

function initCollectionHome() {

	jQuery("#collectionLayer a.banner").each( function(i,el) {
	
		var collectionLabel	= jQuery(this).attr("title");
		var collectionDesc	= jQuery(this).attr("rel");
		var collectionURL	= jQuery(this).attr("href");
		var collectionImg	= jQuery("img", this);
		var layerWidth		= collectionImg.width();
		var layerHeight		= collectionImg.height();
		
		jQuery(this)
			.append(
				jQuery("<div><strong>" + collectionLabel + "</strong><p>" + collectionDesc + "</p><a href='" + collectionURL + "'>" + BBLabels.label_discoverCollect + "</a></div>")
					.css({
						display:	"none",
						opacity:	0,
						width:		layerWidth+"px",
						height:		layerHeight+"px"
					})
			).bind("mouseenter", function(e) {jQuery("div", this).css("display", "block").stop().animate({opacity: 1}, function() {}) })
			.bind("mouseleave", function(e) {jQuery("div", this).stop().animate({opacity: 0}, function() {jQuery(this).css("display", "none"); }) });
			
	});

}

/*---------------------------------- [GLOBAL] ----------------------------------*/

function initXitiClick() {

	var nbProdCombo = jQuery("select[name=nb_produits]"),
		pagesList = jQuery("#pages_layer, #pages_layer_bottom"),
		filterCombo = jQuery("select.axestat1, select.axestat2"),
		newsletterSubmitLink = jQuery("#mailingBlockForm a"),
		form = jQuery("#product_form");

	/*if( nbProdCombo.length > 0 ) {
		nbProdCombo.each( function() {
			jQuery(this).bind("change", function() {
				xt_click(this,'C','2','nb_produits_' + jQuery(this).val(), 'N');
				jQuery("#maxrows").val(jQuery(this).val());
				setTimeout("jQuery('#product_form').submit();", 500) ;
				//form.submit();
			});
		});
	}*/
	
	if( filterCombo.length > 0 ) {
		filterCombo.each( function() {
			jQuery(this).bind("change", function() {
				xt_click(this,'C','2', jQuery(this).attr("name") + '-' + jQuery(this).val(), 'N');
				setTimeout("jQuery('#product_form').submit();", 500) ;
				//form.submit();
			});
		});
	}
	
	/*if( pagesList.length > 0 ) {
		jQuery("li a", pagesList).bind("click", function(e) {
			//e.preventDefault();
			xt_click(this,'C','2','page_' + jQuery(this).attr("rel"), 'N')
		});
	}*/
	
	if( newsletterSubmitLink.length > 0 ) {
		newsletterSubmitLink.bind("click", function(e) {
			e.preventDefault();
			xt_click(this,'F','2','inscription_newsletter::' + jQuery("#gender").val().replace(",","-").replace("1","femme").replace("2","homme") );
		});
	}

}

function initScrollable() {

	jQuery(".scrollable").each( function(i,el) {
	
		var currentList		= jQuery("ul", this);
		var itemWidth		= jQuery("li",this).eq(0).outerWidth() + eval( (jQuery("li",this).eq(0).css("marginLeft").replace("px","") + "+" + jQuery("li",this).eq(0).css("marginRight")).replace("px",""));
		var nbItem			= jQuery("li",this).length;
		var listWidth		= nbItem*itemWidth;
		var scrollable 		= (listWidth>currentList.parent().innerWidth()) ? true : false;
		var init			= (eval(jQuery(this).attr("init"))) ? true : false;
		var linked			= false;
		if(typeof(jQuery(this).attr("linked"))!="undefined") {
			linked = true;
			var linkedLayer			= jQuery("#"+jQuery(this).attr("linked"));
			var linkedList			= jQuery("ul", linkedLayer);
			var linkedItemWidth		= jQuery("li", linkedLayer).eq(0).outerWidth();	
		}
		
		currentList.css("width", listWidth + "px");

		if( scrollable && !init ) {
			
			jQuery(this).attr("init", "true");
			
			jQuery(".next", this).bind("click", function( e ) {
				
				e.preventDefault();
				var allItems = jQuery("li", currentList);
				var newElem = allItems.eq(0);
				var lastItem = allItems.eq(allItems.length-1);
				newElem.clone(true).insertAfter(lastItem);
				newElem.animate({ marginLeft: "-="+itemWidth }, function() {
					jQuery(this).remove();
				});
				
				if(linked) {
				
					var allItems = jQuery("li", linkedList);
					var newElem = allItems.eq(0);
					var lastItem = allItems.eq(allItems.length-1);
					newElem.clone(true).insertAfter(lastItem);
					newElem.animate({ marginLeft: "-="+linkedItemWidth }, function() {
						jQuery(this).remove();
					});
				
				}
				
			});
			
			jQuery(".prev", this).bind("click", function( e ) {
			
				e.preventDefault();
				var allItems = jQuery("li", currentList);
				var newElem = allItems.eq(allItems.length-1);
				var firstItem = allItems.eq(0);
				newElem.clone(true).insertBefore(firstItem).css({marginLeft: "-"+itemWidth+"px"})
						.animate({ marginLeft: "+="+itemWidth }, function() { allItems.eq(allItems.length-1).remove(); });
			
				if(linked) {
					var allItems = jQuery("li", linkedList);
					var newElem = allItems.eq(allItems.length-1);
					var firstItem = allItems.eq(0);
					newElem.clone(true).insertBefore(firstItem).css({marginLeft: "-"+linkedItemWidth+"px"})
							.animate({ marginLeft: "+="+linkedItemWidth }, function() { allItems.eq(allItems.length-1).remove(); });
				}
			
			});
			
			jQuery(".prev,.next", this).css("display", "block");
		
		}
	
	});

}

function initMainMenu() {

	jQuery(".mainCatLayer").css({opacity: 0});
	jQuery(".mainCat").each( function( index ) {
		jQuery(this).bind("mouseenter", function( event ) {
			jQuery(".mainCatLayer", this).css("display", "block").stop().animate({opacity: 1});
		}).bind("mouseleave", function( event ) {
			jQuery(".mainCatLayer", this).stop().animate({opacity: 0}, function() {jQuery(this).css("display", "none");});
		});
		jQuery(".sCat", this).each( function() {
			if(jQuery(".tpList li", this).length==1)
				jQuery(".tpList", this).remove();
		});
	});
	

}

function initNavBtn() {

	jQuery(".navBtn").bind("click", function( e ) {
	
		e.preventDefault();
		
		jQuery('html,body').stop().animate({scrollTop: jQuery("#"+jQuery(this).attr("target")).offset().top-35}, "slow");
	
	});

}

function initBBSlider() {

	jQuery("dl.BBSlider").each( function(i) {
	
		var currentSlider	= jQuery(this);
		var selectedIndex	= (typeof(jQuery(this).attr("sIndex"))!="undefined") ? jQuery(this).attr("sIndex") : 0;
		var callback		= (typeof(jQuery(this).attr("callBack"))!="undefined"||jQuery(this).attr("callBack")!=null) ? jQuery(this).attr("callBack") : false;
		var linkedMenu		= (typeof(jQuery(this).attr("link"))!="undefined"||jQuery(this).attr("link")!=null) ? jQuery("#"+jQuery(this).attr("link")) : false;
	
	if(linkedMenu) {
		
			jQuery("li", linkedMenu).each( function(j) {
				jQuery(this).attr("class", ((j==selectedIndex)?"sSelected":""));
				
				jQuery(this).bind("click", function(e) {
					e.preventDefault();
					if(jQuery(this).attr("class")=="") {
					
						jQuery("li", linkedMenu).attr("class", "");
						jQuery(this).attr("class", "sSelected");
					
						jQuery("dt[selected=true]", currentSlider)
							.attr("selected", "false")
							.toggleClass("selected")
							.next()
							.stop()
							.slideToggle();
						jQuery("dt", currentSlider)
							.eq(j)
							.attr("selected", "true")
							.toggleClass("selected")
							.next()
							.stop()
							.slideToggle();
					}
				});
			});
		
		}
		
		jQuery("dt", currentSlider).not(jQuery("dl dt", currentSlider)).each( function(j) {
			jQuery(this).attr("selected", ((j==selectedIndex)?"true":"false"));
			jQuery(this).bind("click", function(e) {
					jQuery("dt[selected=true]", currentSlider).not(jQuery("dl dt", currentSlider))
						.attr("selected", "false")
						.removeClass("selected")
						.next()
						.stop()
						.slideUp();
					jQuery(this)
						.attr("selected", "true")
						.addClass("selected")
						.next()
						.stop()
						.slideDown();
					if(jQuery.isFunction(eval(callback))) eval(callback+"(j)");
			});
		});
		
		jQuery("dt[selected=true]", currentSlider).not(jQuery("dl dt", currentSlider))
			.eq(0)
			.toggleClass("selected")
			.next()
			.slideDown();
	
	});

}

function initBBSelect( target ) {
	var selectedIndex = 0;
	/*if(typeof(index)!="undefined")
		selectedIndex = index;*/
	
	jQuery(target + " .BBSelect").each( function(i,el) {
		var currentSelect = jQuery(this);
		var linkedInput = ( typeof(jQuery(this).attr("name"))!="undefined" && jQuery(this).attr("name")!=null  ) ? jQuery(this).attr("name") : false ;
		var selectedIndex = 0;
		var currentLabel = "";
		var currentValue = "";
		jQuery("li", currentSelect).each( function(i, el) {
			if(i==0) {
				jQuery(this).bind("click", function(e) {
					e.preventDefault();
					if(currentSelect.height()==20) {
						currentSelect.animate({height: jQuery("li",currentSelect).length*30+2 + "px"});
						jQuery("body").bind("mousedown", function(evt) {
							evt.preventDefault;
							currentSelect.animate({height: "20px"});
							jQuery(this).unbind("mousedown");
						});
					} else {
						currentSelect.animate({height: "20px"});
						jQuery("body").unbind("mousedown");
					}
				})
			} else {
				var link = jQuery("a",this);
				var action = (link.attr("href")!="" && link.attr("href")!="#") ? link.attr("href") : "";
				var label = link.html();
				var value = ( typeof(link.attr("rel"))!="undefined" && link.attr("rel")!=null  ) ? link.attr("rel") : "" ;
				if(link.attr("rev")=="true") {
					selectedIndex = i;
					currentLabel = label;
					currentValue = value;
				}
				jQuery(this).bind("click", function(e) {
					jQuery(".selectedItem", currentSelect).html( label );
					if(linkedInput) jQuery("input[name="+linkedInput+"]").val( value );
					currentSelect.animate({height: "20px"});
					jQuery("body").unbind("mousedown");
					eval(decodeURI(action));
					
				});
				link.replaceWith(label);
				
			}
		});
		if(selectedIndex!=0) {
			jQuery(".selectedItem", currentSelect).html( currentLabel );
			if(linkedInput) jQuery("input[name="+linkedInput+"]").val( currentValue );
		}
	});
}

function initBBRadio() {

	jQuery("form").each( function( i ) {
	
		var currentForm = jQuery(this);
	
		jQuery(".BBRadio", this).each( function( j ) {
		
			var inputName = jQuery(this).attr("name");
			var inputValue = jQuery(this).attr("value");
			
			if(jQuery("fieldset input[name='"+jQuery(this).attr("name")+"']", currentForm).length==0)
				jQuery("fieldset", currentForm).append("<input type='hidden' name='"+inputName+"' id='"+inputName+"' value='"+inputValue+"'>");
				
			jQuery(this).replaceWith(
				jQuery("<div class='"+((j==0)?"BBRadio checked":"BBRadio")+"' group='"+inputName+"'>&nbsp;</div>").bind("click", function(e) {
					jQuery(".BBRadio[group="+inputName+"]",currentForm).removeClass("checked");
					jQuery(this).addClass("checked");
					jQuery("#"+inputName).val(inputValue);
				})
			)
			
		});
		
	
	});

}

function initBBCheckbox() {

	jQuery("form").each( function( i ) {
	
		var currentForm = jQuery(this),
			inputs = jQuery("input.BBCheckbox", currentForm);
	
		inputs.each( function( j ) {
		
			var input = jQuery(this),
				inputName = input.attr("name"),
				inputValue = input.attr("value");
			
			if(jQuery("fieldset input[name='"+inputName+"']", currentForm).length==0)
				jQuery("fieldset", currentForm).append("<input type='hidden' name='"+inputName+"' id='"+inputName+"' value=''>");
				
			input.replaceWith(
				jQuery("<div class='BBCheckbox' group='"+inputName+"'>&nbsp;</div>").bind("click", function(e) {
					var item = jQuery(this),
						currentValue = jQuery("#"+inputName).val();
						
					if(item.hasClass("checked")) {
						item.removeClass("checked");
						var newValue = currentValue.replace(","+inputValue,"");
					} else {
						item.addClass("checked");
						var newValue = currentValue + "," + inputValue;
					}
					
					jQuery("#"+inputName).val( newValue );
				})
			)
			
		});
	
	});

}

/*------------------------------------------------------------------------------*/

/*---------------------------------- [CONTENT] ---------------------------------*/

function initContentMenu() {

	if(jQuery(".contentLayer").length>0 && typeof(jQuery(".contentLayer").attr("link"))!="undefined" && jQuery(".contentLayer").attr("link")) {
		var currentPos = jQuery(".contentLayer").attr("link").split(",");
		var noSMenu = (jQuery("#"+currentPos[0]).attr("className")=="noSMenu") ? true : false;
		if(noSMenu) {
			jQuery("#"+currentPos[0]).addClass("selected");
		} else {
			jQuery.each( currentPos, function(i,el) {
				if(jQuery("#"+el).attr("className")=="noSMenu") 
					jQuery("#"+el).addClass("selected");
				else {
					jQuery("#"+el).slideToggle();
					if(i==currentPos.length-1) {
						jQuery("#"+el).prev().addClass("selected");
						jQuery("#"+el+" a[target!='']").each( function(j) {
							if(j==0) jQuery(this).addClass("sSelected");
							jQuery(this).bind("click", function(e) {
								e.preventDefault();
								jQuery("#"+el+" a[target!='']").removeClass("sSelected");
								jQuery(this).addClass("sSelected");
								jQuery('html,body').stop().animate({scrollTop: jQuery("#"+jQuery(this).attr("target")).offset().top-35}, "slow");
							});
						});
					}
				}
			});
		}
	}
	
	jQuery("#infosMagasin").css({opacity: 0, visibility: "visible"});
	
	if(jQuery("#contact_subject").val()==2) jQuery("#infosMagasin").animate({opacity: 1});
	
	jQuery("#contact_subject").bind("change", function( e ) {
		if(jQuery(this).val()==2) {
			jQuery("#dpt").css("display", "block");
			jQuery("#infosMagasin").stop().animate({opacity: 1});
			jQuery("#dpt").attr("mandatory", "true");
			jQuery("#dpt").attr("check", "true");
		} else {
			jQuery("#infosMagasin").stop().animate({opacity: 0}, function() {
				jQuery("#dpt").css("display", "none");
				jQuery("#dpt").removeAttr("mandatory");
				jQuery("#dpt").removeAttr("check");
			});
		}
	});
	
	if(BBVars.currentPageName=="cgv") {
	
		var selectedIndex = jQuery("#CGV_Page").attr("sIndex");
		if(selectedIndex>0) jQuery('html,body').stop().animate({scrollTop: jQuery("#article_"+selectedIndex).offset().top-35}, "slow");
	
	}

}

function dspSignsImg() {
	
	jQuery(".display_layer").bind("mouseenter", function() {
		var div_id = jQuery(this).attr('id');
		jQuery(".right_col img").stop().css({display: "none", opacity: 0});
		jQuery(".left_col a").stop().css({display: "none", opacity: 0});
		jQuery(".right_col #" + div_id + "_img").stop().css({display: "block", opacity: 0}).animate({opacity: 1});
		jQuery(".left_col #" + div_id + "_link").stop().css({display: "block", opacity: 0}).animate({opacity: 1});
	});
}

/*------------------------------------------------------------------------------*/

/*--------------------------------- [FOOTER] ---------------------------------*/

function initLangList() {

	jQuery("#langList").each( function( i ) {
	
		jQuery("li a:gt(0)", this).bind("click", function( e ) {
		
			e.preventDefault();
			var newURL = "";
			var currentCountry = jQuery("#langList li.selected a").attr("class");
			var newCountry = jQuery(this).attr("class");
			
			if(window.location.search=="") {
				newURL = window.location.href + "?payssite=" + newCountry;
			} else {
				if(window.location.search.search("payssite")!=-1)
					newURL = window.location.href.replace("="+currentCountry,"="+newCountry);
				else
					newURL = window.location.href + "&payssite=" + newCountry;
			}
			
			window.location.href = newURL;
		
		});
	
		jQuery(this).bind("click", function( e ) {
		
			e.preventDefault();
			if(jQuery(this).innerHeight()==19) {
				jQuery(this).stop().animate({height: eval(jQuery("li", this).length)*19+"px"});
			} else {
				jQuery(this).stop().animate({height: "19px"});
			}
		
		});
		
	});

}

/*--------------------------------------------------------------------*/
