function BBTool_flash( layerID ) {

	var flashLayers = (typeof(layerID)!="undefined") ? jQuery("#"+layerID) : jQuery(".flashLayer");

	flashLayers.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,
				flashvars:			flashParams
			});
	});
}

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 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, true);
			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":
			//alert(objID+" "+objID.split(",")[0]);
			var prodID	= (typeof(objID)=="undefined")? BBVars.currentProdID : objID.split(",")[0];
			var colorID	= (typeof(objID)=="undefined")? BBVars.currentColorID : objID.split(",")[1];
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=prod"
				+ "&msgShowData=true"
				+ "&msgDataProdID=" + prodID
				+ "&msgDataColorID=" + colorID,
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "select":
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=select"
				+ "&msgShowData=true"
				+ "&msgDataProdID=" + objID,
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		default:
			$.get(
				BBVars.pagesURL + "ajax/envoyer.cfm?formAction=prompt",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;		
	}
	

}

function BBTool_pause( duration ) {
	
	var startDate = new Date();
	var currentDate = null;

	do { currentDate = new Date(); }
	while(currentDate-startDate < duration);	

}

function BBTool_trace( value ) {

	if(value) {
		try {
			if(window.jQuery && jQuery.fn && /^1\.[3-9]/.test(jQuery.fn.jquery)) {
				if(jQuery("#traceLayer").length==0) {
					jQuery("body").append(
						jQuery("<div id='traceLayer'><a href='javascript: jQuery(\"#traceLayer p:first\").remove(); void(0); '>Remove first</a><a href='javascript: jQuery(\"#traceLayer p\").remove(); void(0); '>Clear</a><div style='overflow: hidden;'></div></div>")
							.css({
								"position": 	"absolute",
								"z-index":	 	1000,
								"top": 			0,
								"left": 		0,
								"overflow":		"hidden",
								"width": 		"10px",
								"height": 		"10px",
								"background": 	"black",
								"color": 		"white",
								"text-align":	"left"
							})
							.bind( "mouseenter", function(e) {
								jQuery(this).stop().animate({
									height:		jQuery("div", this).height() + 100,
									width:		jQuery("div", this).width()
								});
							})
							.bind( "mouseleave", function(e) {
								jQuery(this).stop().animate({
									height:		10,
									width:		10
								}, "fast");
							})
						);
				}
				jQuery("#traceLayer div").append("<p>"+value+"</p>");
			} else {
				if(document.getElementById("#traceLayer")=="undefined") {
					document
					var traceLayer = document.createElement("div");
					var contentDiv = document.createElement("div");
						contentDiv.append("<p>"+value+"</p>");
						traceLayer.append(contentDiv);
						traceLayer.style.position = "absolute";
						traceLayer.style.zIndex = 10000;
						traceLayer.style.top = 0;
						traceLayer.style.left = 0;
						traceLayer.style.overflow = "hidden";
						traceLayer.style.width = "10px";
						traceLayer.style.height = "10px";
						traceLayer.style.background = "black";
						traceLayer.style.color = "white";
						traceLayer.style.textAlign = "left";
						traceLayer.onmouseover = function(e) {
							this.style.width = this.getElementsByTagName("div")[0].innerWidth+"px";
							this.style.height = this.getElementsByTagName("div")[0].innerHeight+"px";
						};
						traceLayer.onmouseout = function(e) {
							this.style.width = "10px";
							this.style.height = "10px";
						};

				}
			}
		} catch(err) {
			alert(err+"\n"+value);
		}
	}

}


// Permet de faire varier la taille d un conteneur en fonction de la taille de son contenu
function BBTool_resize( HTMLTarget, callback ) {

	var objWidth	= jQuery(HTMLTarget).width()+"px";
	var objHeight	= jQuery(HTMLTarget).height()+"px";

	// On resize le conteneur avec les nouvelles dimensions
	//jQuery(objID).animate({ width: newWidth, height: newHeight});
	
	jQuery(HTMLTarget).css({
		height:		objHeight,
		width:		objWidth,
		overflow: 	"hidden"
		
	// On cache le contenu de la cible
	}).animate({
		height: 	objHeight,
		width:		objWidth
	}, function() {

		// On met a jour le contenu de la cible
		jQuery("div.content", HTMLTarget).animate({opacity: 1}, function() {

			jQuery(HTMLTarget).animate({
				width: jQuery("div.content", HTMLTarget).outerWidth()+"px",
				height: jQuery("div.content", HTMLTarget).outerHeight()+"px"
			});
		
		});
		
	})

}

function BBTool_resizeCallback(HTMLTarget) {

	jQuery(HTMLTarget).animate({
		width: jQuery("div.content", HTMLTarget).outerWidth()+"px",
		height: jQuery("div.content", HTMLTarget).outerHeight()+"px"
	}, function() {
		jQuery("div.content",HTMLTarget).animate({opacity: 1});
	});
	
}

function initMenu() {

	jQuery("#mainMenu_list li.cat").each( function(i) {
		if(jQuery("ul",this).attr("style")) {
			jQuery("ul",this).slideUp();
			jQuery("a:first", this)
				.bind("click", function( event ) {
					if(jQuery(this).hasClass("selected")) {
						jQuery(this).removeClass("selected");
						jQuery(this).next().slideUp();
					} else {
						jQuery(this).addClass("selected");
						jQuery(this).next().slideDown();
					}
					//event.preventDefault();
				})
		}
	});

}

function delTR( lineID, lineHeight ) {

	jQuery(lineID).css({overflow: "hidden", height: lineHeight});
	jQuery(lineID+" td").css({height: lineHeight, overflow: "hidden"});
	jQuery(lineID+" td")
			.animate(
				{opacity:0},
				function() {
					jQuery(this)
						.css("height", 0)
						.remove();
					jQuery(lineID).animate({height: 0}, function() { jQuery(this).remove(); });
				});
				
}

(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(jQuery) {
    function tooltip(el, fn, options) {
        el.hover(function (e) {
		
		    this.anchor_title = this.title;
            this.title = '';
			
           	jQuery('#' + options.tooltipID).html(fn(this));
	
			var scrollPos = BBTool_getPageScroll();
			
			if(options.tTipWidth==0) options.tTipWidth = jQuery("#"+options.tooltipID).width();
			if(options.tTipHeight==0) options.tTipHeight = jQuery("#"+options.tooltipID).height();
			
			var xPos 	= (options.tTipWidth+e.pageX+options.xOffset<BBVars.windowWidth+scrollPos[0])
						? e.pageX + options.xOffset
						: e.pageX - options.xOffset - options.tTipWidth;
						
			var yPos 	= (options.tTipHeight+e.pageY+options.yOffset<BBVars.windowHeight+scrollPos[1])
						? e.pageY + options.yOffset
						: BBVars.windowHeight + scrollPos[1] - options.tTipHeight;

            jQuery('#' + options.tooltipID)
                .css({
                	top:		yPos + "px",
                	left:		xPos + "px",
                	display:	"block"
                }).stop().animate({opacity: 1});
	                
	         
        }, function () {
            this.title = this.anchor_title;
            jQuery('#' + options.tooltipID).stop().animate({opacity: 0}, function() { jQuery(this).css("display","none");});
        });
        
        el.mousemove(function (e) {
		
			var scrollPos = BBTool_getPageScroll();
			
			var xPos 	= (options.tTipWidth+e.pageX+options.xOffset<BBVars.windowWidth+scrollPos[0])
						? e.pageX + options.xOffset
						: e.pageX - options.xOffset - options.tTipWidth;
						
			var yPos 	= (options.tTipHeight+e.pageY+options.yOffset<BBVars.windowHeight+scrollPos[1])
						? e.pageY + options.yOffset
						: BBVars.windowHeight + scrollPos[1] - options.tTipHeight;
						
			jQuery('#' + options.tooltipID)
				.css("top", yPos + "px")
				.css("left", xPos + "px");
			
		});
    }

    jQuery.fn.tooltip = function(fn, options) {
        options = options || {};
        var defaults = {
            xOffset: 		20,
            yOffset: 		-10,
            tooltipID: 		'BBTTip',
			tTipHeight:		0,
			tTipWidth:		0
        };
        
		if(jQuery("#"+options.tooltipID).length==0) {
			jQuery('body').append('<div id="' + options.tooltipID + '">' + fn(this) + '</div>');
			jQuery('#' + options.tooltipID)
				.css({
					zIndex:	10000,
					position:	"absolute",
					opacity:	0
				});
		}
		
        return this.each(function() {
            tooltip(jQuery(this), fn, jQuery.extend(defaults, options));
        });
    }
    
})(jQuery);

function BBTool_toolTip() {
	
	jQuery("."+BBSettings.defaultTTipClassName).tooltip(function (el) {
			var c = (el.anchor_title != "") ? "<p>" + el.anchor_title + "</p>" : "";
			//var c = jQuery("div",el).html();
			var i = (el.rel!="") ? "<img src='"+ el.rel +"' alt='"+ el.title +"' />" : "";
			return c;
		}, {
			'tooltipID': BBSettings.defaultTTipName,
			'tTipHeight': 60,
			'tTipWidth': 60
	});
	
	jQuery("a.apercu").tooltip(function (el) {
			var c = (el.anchor_title != "") ? "<p>" + el.anchor_title + "</p>" : "";
			//var c = jQuery("div",el).html();
			var i = (el.rel!="") ? "<img src='"+ el.rel +"' align='absmiddle' alt='"+ el.anchor_title +"' />" : "";
			return i;
		}, {
			'tooltipID': BBSettings.defaultTTipName,
			'tTipHeight': 60,
			'tTipWidth': 60
	});
	
	
	
}

// onload de plusieurs images

(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);

(function($) {
	$.fn.BBFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.BBFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.BBFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

function BBTool_rollFade( initObj, target) {

	jQuery(target).css({opacity: 0});
	jQuery(initObj).bind("mouseenter", function() {
		jQuery(target).css("display", "block")
			.stop()
			.animate({opacity: 1});
	}).bind("mouseleave", function() {
		jQuery(target).stop()
			.animate({opacity: 0}, function() {
				jQuery(this).css("display", "none");
			});
	});

}
