function delTR( lineID, lineHeight ) {

	jQuery(lineID).css({overflow: "hidden", height: lineHeight});
	jQuery(lineID+" td").css({height: lineHeight, overflow: "hidden"}).animate({opacity:0, height: 0}, function() {
		jQuery(this).remove();
		jQuery(lineID).animate({height: 0}, function() { jQuery(this).remove(); });
	});
				
}

function NumberFormat(nStr){
	nStr += '',
	x = nStr.split(','),
	x1 = x[0],
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	var r = x1 + "" + x2;
	return r.replace(".", ",");
}

// onload de plusieurs images
/* Pour les BBForms /^[a-zA-Z-' éèêïîëôûüàâöäèòìóñÑ]+$/ = /^[a-zA-Z-' \u00E0-\u00EF\u00F0-\u00F6\u00F9-\u00FC]+$/ */
(function($) {
$.fn.batchImageLoad = function(options) {
	var images = $(this);
	var originalTotalImagesCount = images.size();
	var totalImagesCount = originalTotalImagesCount;
	var elementsLoaded = 0;

	// Init
	$.fn.batchImageLoad.defaults = {
		loadingCompleteCallback: null, 
		imageLoadedCallback: null
	}
    var opts = $.extend({}, $.fn.batchImageLoad.defaults, options);
		
	// Start
	images.each(function() {
		// The image has already been loaded (cached)
		if ($(this)[0].complete) {
			totalImagesCount--;
			if (opts.imageLoadedCallback) opts.imageLoadedCallback(elementsLoaded, originalTotalImagesCount);
		// The image is loading, so attach the listener
		} else {
			$(this).load(function() {
				elementsLoaded++;
				
				if (opts.imageLoadedCallback) opts.imageLoadedCallback(elementsLoaded, originalTotalImagesCount);

				// An image has been loaded
				if (elementsLoaded >= totalImagesCount)
					if (opts.loadingCompleteCallback) opts.loadingCompleteCallback();
			});
			$(this).error(function() {
				elementsLoaded++;
				
				if (opts.imageLoadedCallback) opts.imageLoadedCallback(elementsLoaded, originalTotalImagesCount);
					
				// The image has errored
				if (elementsLoaded >= totalImagesCount)
					if (opts.loadingCompleteCallback) opts.loadingCompleteCallback();
			});
		}
	});

	// There are no unloaded images
	if (totalImagesCount <= 0)
		if (opts.loadingCompleteCallback) opts.loadingCompleteCallback();
};
})(jQuery);


// MouseWheel event
(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
    setup: function() {
        if ( this.addEventListener )
            for ( var i=types.length; i; )
                this.addEventListener( types[--i], handler, false );
        else
            this.onmousewheel = handler;
    },
    
    teardown: function() {
        if ( this.removeEventListener )
            for ( var i=types.length; i; )
                this.removeEventListener( types[--i], handler, false );
        else
            this.onmousewheel = null;
    }
};

$.fn.extend({
    mousewheel: function(fn) {
        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
    },
    
    unmousewheel: function(fn) {
        return this.unbind("mousewheel", fn);
    }
});


function handler(event) {
    var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
    
    event = $.event.fix(event || window.event);
    event.type = "mousewheel";
    
    if ( event.wheelDelta ) delta = event.wheelDelta/120;
    if ( event.detail     ) delta = -event.detail/3;
    
    // Add event and delta to the front of the arguments
    args.unshift(event, delta);

    return $.event.handle.apply(this, args);
}

})(jQuery);

function BBTool_getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		if(document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
		else  windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	if(xScroll < windowWidth) pageWidth = xScroll;		
	else pageWidth = windowWidth;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function BBTool_getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};

function BBTool_getMousePos(e) {
	var xPos, yPos;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) xPos = e.pageX, yPos = e.pageY;
	else if (e.clientX || e.clientY) {
		xPos = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		yPos = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	arrayMousePos = new Array(xPos,yPos);
	return arrayMousePos;
}

function BBGallery_swapItem(itemID) {

	$("#BBGallery_list li").each( function(i) {
		$(this).removeClass().css("position", "relative");
		(i==itemID) ? $(this).addClass("BBTool_galMainImg").css("position", "absolute") : $(this).addClass("BBTool_galImg");
	});

}

function BBTool_flash() {
	$(".flashLayer").each( function() {
		var flashID			 	= ($(this).attr("flashID")==undefined) ? "flash" : $(this).attr("flashID");
		var flashSrc			= ($(this).attr("flashSrc")==undefined) ? false : $(this).attr("flashSrc");
		var flashWMode			= ($(this).attr("flashWMode")==undefined) ? "transparent" : $(this).attr("flashWMode");
		var flashBG				= ($(this).attr("flashBG")==undefined) ? "transparent" : $(this).attr("flashBG");
		var flashScriptAccess	= ($(this).attr("flashScriptAccess")==undefined) ? "always" : $(this).attr("flashScriptAccess");
		var flashParams			= ($(this).attr("flashParams")==undefined) ? "" : eval("({"+$(this).attr("flashParams")+"})");
		if($(this).attr("flashWidth")==undefined) {
			var flashWidth = ($(this).width()>0) ? $(this).width() : "auto";
		} else var flashWidth = $(this).attr("flashWidth");
		if($(this).attr("flashHeight")==undefined) {
			var flashHeight = ($(this).height()>0) ? $(this).height() : "auto";
		} else var flashHeight = $(this).attr("flashHeight");
		
		if(flashSrc) 
			$(this).flash({
				id:					flashID,
				src:				flashSrc,
				width:				flashWidth,
				height:				flashHeight,
				wmode:				flashWMode,
				allowScriptAccess:	flashScriptAccess,
				salign:				'tl',
				align:				'top',
				flashvars:			flashParams
			});
	});
}

function BBSendMail( action, objID ) {

	switch(action) {
		case "send":
			var data = "";
			if (BBVars.dataSendContentID != "") 
				data = $("#"+BBVars.dataSendContentID).html();
			else if($(".dataSend:last").length == 1)
				data = $(".dataSend:last").html();
			$("#msgData").attr("value", data);
			BBTool_formPost(objID);
			break;
		case "msg":
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=msg",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "data":
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=data",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "url":
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=url",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "prod":
			BBSettings.BBPopup.elementsSettings.width = "570px";
			jQuery.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=prod"
				+ "&msgShowData=true"
				+ "&msgDataProdID=" + BBVars.currentProdID
				+ "&msgDataColorID=" + BBVars.currentColorID,
				function(data) {
					BBTool_openMsgBox(data, true);
					BBSettings.BBPopup.elementsSettings.width = "610px";
				}
			);
			break;
		default:
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm?formAction=prompt",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;		
	}
	

}

// Rajoute de la fonction tooltip a lobjet jQuery afin de pouvoir l utiliser sur n importe quel selecteur jQuery
(function(jQuery) {

	// fn: Objet jQuery
	//		Collection d objet jQuery a laquelle appliquer le tooltip
	// options:	Objet contenant les parametres du tooltip a afficher
	//		xOffset: 		Int
	//						decallage horizontal en pixel du tooltip par rapport a sa position initiale (negatif a gauche/positif a droite)
	//		yOffset: 		Int
	//						decallage vertical en pixel du tooltip par rapport a sa position initiale (negatif en haut/positif en bas)
	//		tooltipID: 		String
	//						ID HTML du div cree pour afficher le tooltip
	//		tTipHeight:		Int/String
	//						"auto" la hauteur du tooltip s adaptera a la hauteur de son contenu
	//						Hauteur du tooltip en pixel
	//		tTipWidth:		Int/String
	//						"auto" la largeur du tooltip s adaptera a la largeur de son contenu
	//						Largeur du tooltip en pixel
	//		tTipDspPos:		String
	//						Position du tooltip par rapport a l objet
	//						"free" le tooltip se positionne en fonction de la position du pointeur de la souris sur l objet
	//						"vtc" le tooltip s affichera en dessous(au dessus s il l espace d affichage n est pas suffisant) de l objet et suivra le pointeur de la souris
	//						"hrzt" le tooltip s affichera a droite(a gauche s il l espace d affichage n est pas suffisant) de l objet et suivra le pointeur de la souris
	//						"auto" la position d affichage du pointeur sera determine par les dimensions de l objet
	//							Un objet plus large que haut sera affiche avec le positionnement "vtc" (voir ci dessus)
	//							Un objet plus haut que large sera affiche avec le positionnement "hrzt" (voir ci dessus)
	//						"top" le tooltip s affiche au dessus de l objet
	//						"right" le tooltip s affiche a droite de l objet
	//						"bottom" le tooltip s affiche en dessous de l objet
	//						"left" le tooltip s affiche a gauche de l objet
	//		pointer:		Bool
	//						Determine si le pointeur du tooltip doit etre affiche
	//////////////////////////////////////// EN DEV ////////////////////////////////////////////////////////////////////////////////
	//		pointerPos:		String 
	//						"auto" le pointeur du tooltip suit l objet
	//						"fixed" le pointeur du tooltip reste fige a sa position intiale
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//		pointerOffset:	Objet
	//							x:	Int
	//								decallage horizontal en pixel du pointeur du tooltip par rapport a sa position initiale (negatif a gauche/positif a droite)
	//							y:	Int
	//								decallage vertical en pixel du pointeur du tooltip par rapport a sa position initiale (negatif en haut/positif en bas)
	//		classN:			String
	//						Class CSS qui sera rajoute au div contenant le tooltip
	//		events:			Objet
	//							init:	String
	//									Liste des evenements(separes par un espace) declenchant l initialisation du tooltip
	//							show:	String
	//									Liste des evenements(separes par un espace) declenchant l affichage du tooltip
	//							hide:	String
	//									Liste des evenements(separes par un espace) declenchant le masquage du tooltip
	//


    jQuery.fn.tooltip = function( content, options) {

		// On recupere les options si on en a passe a la fonction 
		// Sinon on cree une structure vide
        options = options || {};

        var defaults = {
            xOffset: 		0,
            yOffset: 		0,
            tooltipID: 		'BBTTip',
			tTipHeight:		"auto",
			tTipWidth:		"auto",
			tTipDspPos:		"free",
			pointer:		true,
			pointerPos:		"auto",
			pointerOffset:	{x:0, y:0},
			classN:			"",
			events:			{
								init:	"mouseenter",
								show:	"mousemove",
								hide:	"mouseleave"
							}
        };
		
		// Genere les "tooltip" pour la collection d'objet passee en parametre
        return this.each(function() {
            tooltip(jQuery(this), content, jQuery.extend(defaults, options));
        });
    }
})(jQuery);

// Fonction de generation des tooltips
function tooltip(el, TTContent, options) {

	// Si le DIV associe a l ID passe en parametre servant de contener au tooltip n existe pas on le cree
	if(jQuery("#"+options.tooltipID).length==0) {
	
		// Le tooltip contient deux DIVs, un(.pointer) pour afficher le pointeur et l autre(.content) pour afficher le contenu
		// On fixe la position et le zIndex au cas ou on l aurait oublie dans la css
		jQuery('body').append(
			jQuery('<div id="' + options.tooltipID + '"><div class="pointer">&nbsp;</div><div class="content"></div></div>')
				.css({ zIndex: 10000, position: "absolute" })
		);
	}
	var obj = jQuery(el),
		objDim = {width: 0, height: 0},
		objPos = {top: 0, left: 0},
		tTip = jQuery("#"+options.tooltipID),
		tTipDim = {width: 0, height: 0},
		tTipPos = {top: 0, left: 0},
		pointer = jQuery(" .pointer", tTip),
		pointerPos = {top: 0, left: 0},
		pointerDim = {},
		content = jQuery(" .content", tTip);
	/*pointer.css({
		display: 	((options.pointer)?"block":"none"),
		position:	"absolute"
	});*/
	
	obj.bind( options.events.init , function (e) {
		tTip.removeAttr("class").addClass(options.classN).css({width: "", height: ""});
		content.html( ((typeof(TTContent)=="function")?TTContent(this):TTContent) );
		tTipDim = {width: (options.tTipWidth=="auto") ? tTip.width() : options.tTipWidth, height: (options.tTipHeight=="auto") ? tTip.height() : options.tTipHeight},
		objPos = {left: obj.offset().left, top: obj.offset().top},
		objDim = {width: obj.width(), height: obj.height()},
		pointerDim = {width: eval(pointer.css("width").replace("px","")), height: eval(pointer.css("height").replace("px",""))};
		tTip.stop().css(jQuery.extend({opacity: 0, display: "block"}, tTipDim)).animate({opacity: 1},"200");
		if(options.pointer&&options.pointerPos!="auto"/*&&options.tTipPos!="hrzt"&&options.tTipPos!="vtc"*/) {
			switch(options.pointerPos) {
				case "top":
					classN = "pointer bottom",
					pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
					pointerPos.top = -pointerDim.height + options.pointerOffset.y + "px";
					break;
				case "right":
					classN = "pointer left",
					pointerPos.left = tTipDim.width + options.pointerOffset.x + "px",
					pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
					break;
				case "bottom":
					classN = "pointer top",
					pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
					pointerPos.top = tTipDim.height + options.pointerOffset.y + "px";
					break;
				case "left":
					classN = "pointer right",
					pointerPos.left = -pointerDim.width + options.pointerOffset.x + "px",
					pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
					break;
				case "bottom,right":
					classN = "pointer top",
					pointerPos.left = tTipDim.width + options.pointerOffset.x + "px",
					pointerPos.top = tTipDim.height + options.pointerOffset.y + "px";
					break;
			}
			pointer.addClass(classN).css(pointerPos);
		} else if (!options.pointer) pointer.css("display", "none");
		
	}).bind( options.events.hide , function (e) {
		tTip.stop().animate({opacity: 0}, "200", function() { jQuery(this).css("display","none") });
	}).bind( options.events.show , function (e) {
		dspPos = options.tTipDspPos;
		if(dspPos=="auto") 
			dspPos = (e.pageX - objPos.left < e.pageY - objPos.top) ? "hrzt" : "vtc" ;
			// Suit le curseur de la souris et se positionne autour de l objet en fonction de sa taille
		else if(dspPos=="free") {
			hWidth = objDim.width/2,
			hHeight = objDim.height/2,
			origin = {X: hWidth + objPos.left, Y: hHeight + objPos.top},
			points = {
					tr: {X: hWidth, Y: hHeight},
					br: {X: hWidth, Y: -hHeight},
					bl: {X: -hWidth, Y: -hHeight},
					tl: {X: -hWidth, Y: hHeight},
					evt: {X: e.pageX - origin.X, Y: e.pageY - origin.Y}
			}, angles = {
					tr: 180 * (Math.acos( points.tr.X / Math.sqrt( Math.pow(points.tr.X,2) + Math.pow(points.tr.Y,2) ) )) / Math.PI,
					br: 360 - (180 * (Math.acos( points.br.X / Math.sqrt( Math.pow(points.br.X,2) + Math.pow(points.br.Y,2) ) )) / Math.PI),
					bl: 360 - (180 * (Math.acos( points.bl.X / Math.sqrt( Math.pow(points.bl.X,2) + Math.pow(points.bl.Y,2) ) )) / Math.PI),
					tl: 180 * (Math.acos( points.tl.X / Math.sqrt( Math.pow(points.tl.X,2) + Math.pow(points.tl.Y,2) ) )) / Math.PI,
					evt: 180 * (Math.acos( points.evt.X / Math.sqrt( Math.pow(points.evt.X,2) + Math.pow(points.evt.Y,2) ) )) / Math.PI
			};
			if ( points.evt.Y > 0 ) angles.evt = 360 - angles.evt;
			if ( angles.tr<angles.evt && angles.evt<angles.tl ) dspPos = "top";
			else if ( angles.tl<angles.evt && angles.evt<angles.bl ) dspPos = "left";
			else if ( angles.bl<angles.evt && angles.evt<angles.br ) dspPos = "bottom";
			else dspPos = "right";
		}
		switch(dspPos) {
			// Fixe au dessus
			case "top":
				tTipPos.left = (options.xOffset + objDim.width/2 + objPos.left - tTipDim.width/2) + "px",
				tTipPos.top = (options.yOffset + objPos.top - tTipDim.height - ((options.pointer)?pointerDim.height:0)) + "px";
				if(options.pointer&&options.pointerPos=="auto") {
					classN = "pointer top",
					pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
					pointerPos.top = tTipDim.height + options.pointerOffset.y + "px";
					pointer.addClass(classN).css(pointerPos);
				}
				break;
			// Fixe a droite
			case "right":
				tTipPos.left = (options.xOffset + objDim.width + objPos.left + ((options.pointer)?pointerDim.width:0)) + "px",
				tTipPos.top = (options.yOffset + objPos.top + objDim.height/2 - tTipDim.height/2) + "px";
				/*if(options.pointer&&options.pointerPos=="auto") {
					classN = "pointer right",
					pointerPos.left = -pointerDim.width + options.pointerOffset.x + "px",
					pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
					pointer.attr("class", classN).css(pointerPos);
				}*/
				break;
			// Fixe en dessous
			case "bottom":
				tTipPos.left = (options.xOffset + objDim.width/2 + objPos.left - tTipDim.width/2) + "px",
				tTipPos.top = (options.yOffset + objPos.top + objDim.height + ((options.pointer)?pointerDim.height:0)) + "px";
				/*if(options.pointer&&options.pointerPos=="auto") {
					classN = "pointer bottom",
					pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
					pointerPos.top = -pointerDim.height + options.pointerOffset.y + "px";
					pointer.attr("class", classN).css(pointerPos);
				}*/
				break;
			// Fixe a gauche
			case "left":
				tTipPos.left = (options.xOffset + objPos.left - tTipDim.width - ((options.pointer)?pointerDim.width:0)) + "px",
				tTipPos.top = (options.yOffset + objPos.top + objDim.height/2 - tTipDim.height/2) + "px";
				/*if(options.pointer&&options.pointerPos=="auto") {
					classN = "pointer left",
					pointerPos.left = tTipDim.width + options.pointerOffset.x + "px",
					pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
					pointer.attr("class", classN).css(pointerPos);
				}*/
				break;
			// Suit le curseur de la souris et se positionne sur au dessus ou en dessous de l objet
			case "vtc":
			
				if( objPos.top - BBVars.pageScrollY >= tTipDim.height - options.yOffset - ((options.pointer)?pointerDim.height:0)) {
					tTipPos.top = objPos.top - (options.yOffset + tTipDim.height + ((options.pointer)?pointerDim.height:0));
					if(options.pointer) {
						classN = "pointer top";
						pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
						pointerPos.top = tTipDim.height + options.pointerOffset.y + "px";
						pointer.addClass(classN).css(pointerPos);
					}
				} else {
					tTipPos.top = objPos.top + objDim.height + options.yOffset + ((options.pointer)?pointerDim.height:0);
					if(options.pointer&&options.pointerPos=="auto") {
						classN = "pointer bottom";
						pointerPos.left = tTipDim.width/2 - pointerDim.width/2 + options.pointerOffset.x + "px",
						pointerPos.top = -pointerDim.height + options.pointerOffset.y + "px";
						pointer.addClass(classN).css(pointerPos);
					}
				}
				tTipPos.left = e.pageX - tTipDim.width/2;
				break;
			// Suit le curseur de la souris et se positionne sur a droite ou a gauche de l objet
			case "hrzt":
				if( e.pageX + tTipDim.width + options.xOffset + ((options.pointer)?pointerDim.width:0) < BBVars.windowWidth + BBVars.pageScrollX ) {
					tTipPos.left = e.pageX + options.xOffset + ((options.pointer)?pointerDim.width:0);
					if(options.pointer) {
						classN = "pointer right";
						pointerPos.left = -pointerDim.width + options.pointerOffset.x + "px",
						pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
						pointer.addClass(classN).css(pointerPos);
					}
				} else {
					tTipPos.left = e.pageX - options.xOffset - tTipDim.width - ((options.pointer)?pointerDim.width:0);
					if(options.pointer) {
						classN = "pointer left";
						pointerPos.left = tTipDim.width + options.pointerOffset.x + "px",
						pointerPos.top = (tTipDim.height/2 - pointerDim.height/2) + options.pointerOffset.y + "px";
						pointer.addClass(classN).css(pointerPos);
					}
				}
				vHeight = BBVars.dspAreaHeight - ( e.pageY - BBVars.pageScrollY + tTipDim.height/2 + options.yOffset );
				tTipPos.top = e.pageY - tTipDim.height/2 + options.yOffset + ((vHeight>0)?0:vHeight);
				break;
		}
			
		tTip.css(tTipPos);
		
	});
}

function BBTool_toolTip() {


	jQuery("a."+BBSettings.defaultTTipClassName).each(function(i,el) {
		if(jQuery(this).hasClass("BBTTip_img")) {
			jQuery("a."+BBSettings.defaultTTipClassName).tooltip(function (el) {
				return "<img width='360' height='360' src='"+ el.rel +"' alt='"+ el.title +"' />";
				}, {'tooltipID': BBSettings.defaultTTipName, 'tTipDspPos': "hrzt", 'pointer': false, 'xOffset': 20
			});
		
		} else if (jQuery(this).hasClass("BBTTip_Kdo")) {
			jQuery("a."+BBSettings.defaultTTipClassName).tooltip(function (el) {
				var c = (el.anchor_title != "") ? "<div>" + el.anchor_title + "</div>" : "";
				return c ;
				}, {'tooltipID': BBSettings.defaultTTipName, 'xOffset': 5, 'yOffset' : -130
			});
		
		} else if (jQuery(this).hasClass("BBTTip_txt")) {
			jQuery("a."+BBSettings.defaultTTipClassName).tooltip(function (el) {
				var c = (el.anchor_title != "") ? "<p>" + el.anchor_title + "</p>" : "";
				return c ;
				}, {'tooltipID': BBSettings.defaultTTipName, 'xOffset': 5, 'yOffset' : -25
			});
		}
	});
	
	if(BBVars.currentPageName=="livraison") {
		jQuery("span.BBTTip").tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("id") + "Layer").html(); },
				{pointer: true, classN: "shipInfo", tTipDspPos: "bottom", tTipWidth: 200, events: {init: "click", show: "click", hide: "mouseleave"}}
			);
		jQuery("a.moreInfoLink").each( function() {
			jQuery(this).tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: -20, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", tTipWidth: 400, events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
		});
		jQuery("a.ReaLink").each( function() {
			jQuery(this).tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: 5, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
		});
		
	} else if (BBVars.currentPageName=="paiement") {
		jQuery("a.moreInfoLink").each( function() {
			jQuery(this).tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: -20, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", tTipWidth: 500, tTipHeight: 190, events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
		});
		
		jQuery("a.NControl_info").tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: -5, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", tTipWidth: 300, tTipHeight: 195, events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
			
		jQuery("a.ReaLink").each( function() {
			jQuery(this).tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: 5, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
		});
			
	} else if (BBVars.currentPageName=="panier") {
	
		jQuery("a.ReaLink").each( function() {
			jQuery(this).tooltip(
				function(el) { return jQuery("#" + jQuery(el).attr("rel")).html(); },
				{yOffset: 5, classN: jQuery(this).attr("rev"), pointer: true, tTipDspPos: "vtc", events: {init: "mouseenter", show: "mousemove", hide: "mouseleave"}}
			);
		});
	}
	
}

function BBTrace( string ) {

	jQuery("#debugLayer").html( jQuery("#debugLayer").html() + string );

}

function initBBSelect( target ) {

	jQuery(target + " .BBSelect").each( function(i,el) {
	
		var currentSelect = jQuery(this),
			layer = null,
			currentSelectID = currentSelect.attr("id"),
			selectedIndex = 0,
			currentLabel = "",
			currentValue = "",
			currentTarget = null,
			contentLayer = null,
			linkedInput = ( typeof(jQuery(this).attr("name"))!="undefined" && jQuery(this).attr("name")!=null ) ? jQuery(this).attr("name") : false;
		
		if(this.nodeName.toLowerCase()=="select") {
			selectHTML = "<div id='"+ ( (currentSelectID) ? currentSelectID : "BBSelect" + i ) + "' class='"+((typeof(currentSelect.attr("class"))!="undefined")? "BBSelect " + currentSelect.removeClass("BBSelect").attr("class") : "BBSelect")+"'></div>",
			tmpHTML = "",
			options = jQuery("option", currentSelect);
			
			options.each( function(i, el) {
				option = jQuery(this);
				optionClass = 'BBoption';
				if(i+1==options.length) optionClass += " last";
				if(option.attr("selected")) optionClass += " selected";
				tmpHTML += '<li class="'+optionClass+'" data-BBParams="{value:\'' + option.attr("value") + '\'}"><span>' + option.html() + '</span></li>';
			})
			
			currentSelect.replaceWith( selectHTML );
			currentSelect = jQuery("#"+( (currentSelectID) ? currentSelectID : "BBSelect" + i ));
			layer = jQuery("#"+( (currentSelectID) ? currentSelectID : "BBSelect" + i ));
			currentSelect
				.html( "<div class='selectedItem'></div><div class='content'><div class='scroller'></div><ul name='"+linkedInput+"'>" + tmpHTML + "</ul></div>")
				.closest("form").append("<input type='hidden' name='"+linkedInput+"' value=''>");
			currentTarget = jQuery(".selectedItem", currentSelect);
			currentSelect = jQuery("ul", currentSelect);
			contentLayer = jQuery("div.content", layer);
		}
		
		var contenerPos = contentLayer.offset(),
			maxHeight = 200,
			contenerHeight = ((currentSelect.outerHeight()<maxHeight) ? currentSelect.outerHeight() : maxHeight),
			contentHeight = currentSelect.outerHeight() - contenerHeight,
			step = contentHeight/contenerHeight,
			scroller = jQuery(".scroller",contentLayer),
			scrollerHeight = scroller.height(),
			scrollBarHeight = contenerHeight - scrollerHeight;

		layer.bind("mouseup", function(e) {
			e.preventDefault();
			
			if(contentLayer.height()==0) {
				jQuery(this).trigger("open");
				jQuery("body").bind("mousedown", function(evt) {
					var minX = contenerPos.left,
						minY = contenerPos.top,
						maxX = contenerPos.left + contentLayer.width(),
						maxY = contenerPos.top + contentLayer.height();
					if( minX > evt.pageX || evt.pageX > maxX || minY > evt.pageY || evt.pageY > maxY) {
						jQuery(this).trigger("close");
					}
				});
			} else {
				var minX = contenerPos.left,
					minY = contenerPos.top,
					maxX = contenerPos.left + contentLayer.width(),
					maxY = contenerPos.top + contentLayer.height();
				if( minX > e.pageX || e.pageX > maxX || minY > e.pageY || e.pageY > maxY) {
					jQuery(this).trigger("close");
				}
			}
		}).bind("open", function() {
			contentLayer.animate({height: contenerHeight}).addClass("open");
		}).bind("close", function() {
			contentLayer.animate({height: 0}, function() { jQuery(this).removeClass("open") });
			jQuery(this).unbind("mousedown");
		});
		
		if(contenerHeight>=maxHeight) {
			layer.addClass("scrollable").bind("mousewheel", function(e, d) {
			
				e.preventDefault();
				var currentPos = eval(currentSelect.css("top").replace("px","")),
					newPos = currentPos + d * 20,
					scrollerStep = contentHeight/(contenerHeight - scrollerHeight);
				
				if(newPos>=0) newPos = 0;
				else if (newPos<=-contentHeight) newPos = -contentHeight;
				
				currentSelect.css("top", newPos + "px");
				scroller.css("top", -newPos/scrollerStep + "px");
				
			});
			
			scroller.bind("mousedown", function(e) {
				e.stopPropagation();
				e.preventDefault();
				var eventPos = e.pageY - contenerPos.top - eval(scroller.css("top").replace("px",""));
				jQuery("body").bind("mousemove", function(evt) {
					relPos = eval(scroller.css("top").replace("px",""));
					if( relPos+eventPos >= 0 && relPos-eventPos < scrollBarHeight && evt.pageY - eventPos >= contenerPos.top && evt.pageY + scrollerHeight - eventPos < contenerPos.top + contenerHeight) {
						newPos = evt.pageY - contenerPos.top - eventPos;
						if(newPos<0) newPos = 0;
						if(newPos>=scrollBarHeight) newPos = scrollBarHeight;
						scroller.css("top", newPos);
						cNewPos = -(newPos)*(contentHeight/(contenerHeight - scrollerHeight));
						currentSelect.css("top", cNewPos );
					}
				}).bind("mouseup", function(evt) {
					jQuery("body").unbind("mousemove");
				});
			})
		} else scroller.css("display","none");
		
		jQuery("li", currentSelect).each( function(i, el) {
			var item = jQuery(this),
				defaults = { value: "", target: ".selectedItem", action: "setVal", data: ""},
				params = jQuery.extend({}, defaults, eval( "(" + item.attr("data-BBParams") + ")") ),
				label = item.html();
			item.removeAttr("data-BBParams");
			if(eval(item.hasClass("selected")))
				selectedIndex = i,
				currentLabel = label,
				currentValue = params.value;
				
			item.bind("click", function(e) {
				e.preventDefault();
				item.trigger( params.action, true );
				currentSelect.removeClass("open");
				
				jQuery(this).trigger("close");
				//BBTrace(params.action+"-");
				//if( item.data("events." + params.action ) ) item.trigger( params.action+"("+params.data+")");
			}).bind("setVal", function(e, checkTrigger) {
				input = jQuery("input[name="+linkedInput+"]"),
				currentTarget.html( label );
				if(linkedInput) input.val( params.value );
				if(BBSettings.BBForms.checkFormMethod=="rt"&&checkTrigger) {
					currentForm = item.closest("form");
					BBTool_checkForm( currentForm.attr("id"), jQuery("[type=hidden][data-BBParams]") );
				}
			});
		});
		
		jQuery("li", currentSelect).eq(selectedIndex).trigger("setVal", ((selectedIndex==0) ? false : true) );
		//jQuery("li", currentSelect).eq(selectedIndex).trigger("setVal");
		/* jQuery(".selectedItem", layer).html( currentLabel );
		if(linkedInput) jQuery("input[name="+linkedInput+"]").val( currentValue );*/
		
	});
	
}


function initDebug() {

	var debugLayer = jQuery("#debugLayer")/*,
		layerHeight = BBVars.windowHeight-2,
		layerWidth = BBVars.windowWidth-2,
		CFBtn = jQuery(".CFIcon", debugLayer),
		SQLBtn = jQuery(".SQLIcon", debugLayer),
		JSBtn = jQuery(".JSIcon", debugLayer),
		ajaxBtn = jQuery(".ajaxIcon", debugLayer),
		errorLayer = jQuery("#CFErrorLayer");

	jQuery("#stateLayer a").bind("click", function() {
		opened = (debugLayer.height()==40) ? false : true;
		if(opened) 
			debugLayer.css({width: 145, height: 40, overflow: "hidden" });
		else
			debugLayer.css({width: layerWidth, height: layerHeight, overflow: "auto" });
			
	});
	
	debugLayer.bind("error", function() {
		debugLayer.addClass("error");
		debugLayer.addClass("CFError");
	});
	
	if(errorLayer.length>0) {
		jQuery("#cfdebug_errorsLayer",debugLayer).append(errorLayer.clone());
		errorLayer.remove();
		debugLayer.trigger("error");
	}*/
	
	debugLayer.html("");

}
