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 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 BBGallery_swapItem(itemID) {

	jQuery("#BBGallery_list li").each( function(i) {
		jQuery(this).removeClass().css("position", "relative");
		(i==itemID) ? jQuery(this).addClass("BBTool_galMainImg").css("position", "absolute") : jQuery(this).addClass("BBTool_galImg");
	});

}

function BBTool_menu(menuID, action) {

	switch(action) {
		case "show":
			/*if(BBSettings.defaultEffect=="fade") jQuery("#"+menuID).BBFadeIn(BBSettings.defaultEffectSpeed).css("display","block");
			else jQuery("#"+menuID).show("normal").css("display","block");*/
			jQuery("#"+menuID).show();
			jQuery("#top_menu_btn_01").css("background-position","0 -42px");
			break;
		case "hide":
			/*if(BBSettings.defaultEffect=="fade") jQuery("#"+menuID).BBFadeOut(BBSettings.defaultEffectSpeed).css("display","none");
			else jQuery("#"+menuID).hide("normal").css("display","none");*/
			jQuery("#top_menu_btn_01").css("background-position","0 0");
			jQuery("#"+menuID).hide();
			break;
		case "init":
			break;
		default:
			break;
	
	}
	
}

function BBTool_flash() {
	jQuery(".flashLayer").each( function() {
		var flashID			 	= (jQuery(this).attr("flashID")==undefined) ? "flash" : jQuery(this).attr("flashID");
		var flashSrc			= (jQuery(this).attr("flashSrc")==undefined) ? false : jQuery(this).attr("flashSrc");
		var flashWMode			= (jQuery(this).attr("flashWMode")==undefined) ? "transparent" : jQuery(this).attr("flashWMode");
		var flashBG				= (jQuery(this).attr("flashBG")==undefined) ? "transparent" : jQuery(this).attr("flashBG");
		var flashScriptAccess	= (jQuery(this).attr("flashScriptAccess")==undefined) ? "always" : jQuery(this).attr("flashScriptAccess");
		var flashParams			= (jQuery(this).attr("flashParams")==undefined) ? "" : eval("({"+jQuery(this).attr("flashParams")+"})");
		var flashBase			= (jQuery(this).attr("flashParams")==undefined) ? "" : jQuery(this).attr("flashBase");
		if(jQuery(this).attr("flashWidth")==undefined) {
			var flashWidth = (jQuery(this).width()>0) ? jQuery(this).width() : "auto";
		} else var flashWidth = jQuery(this).attr("flashWidth");
		if(jQuery(this).attr("flashHeight")==undefined) {
			var flashHeight = (jQuery(this).height()>0) ? jQuery(this).height() : "auto";
		} else var flashHeight = jQuery(this).attr("flashHeight");
		
		if(flashSrc) 
			jQuery(this).flash({
				id:					flashID,
				src:				flashSrc,
				width:				flashWidth,
				height:				flashHeight,
				wmode:				flashWMode,
				allowScriptAccess:	flashScriptAccess,
				flashvars:			flashParams,
				base:				flashBase
			});
	});
}

function BBSendMail( action, objID ) {

	switch(action) {
		case "send":
			var data = "";
			if (BBVars.dataSendContentID != "") 
				data = jQuery("#"+BBVars.dataSendContentID).html();
			else if(jQuery(".dataSend:last").length == 1)
				data = jQuery(".dataSend:last").html();
			jQuery("#msgData").attr("value", data);
			BBTool_formPost(objID, true);
			break;
		case "msg":
			jQuery.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=msg",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "data":
			jQuery.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=data",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "url":
			jQuery.get(
				BBVars.pagesURL + "ajax/envoyer.cfm"
				+ "?formAction=prompt"
				+ "&msgDataType=url",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;
		case "prod":
			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);}
			);
			break;
		default:
			jQuery.get(
				BBVars.pagesURL + "ajax/envoyer.cfm?formAction=prompt",
				function(data) {BBTool_openMsgBox(data, true);}
			);
			break;		
	}
	

}

function viewDefil(videoSrc) {
	
	var dsp = (jQuery("#view_defil").css("display")=="none"||jQuery("#view_defil").css("display")==undefined) ? "block" : "none";
	jQuery("#view_defil").css("display",dsp);
	var dsp = (jQuery("#view_sil").css("display")=="none"||jQuery("#view_sil").css("display")==undefined) ? "block" : "none";
	jQuery("#view_sil").css("display", dsp);
		
	jQuery('#video').html("");
	jQuery('#video').flash({
		src: BBVars.pagesURL + 'ximg/flash/video.swf',
		width: 180,
		height: 320,
		wmode: 'transparent',
		allowScriptAccess: 'always',
		flashvars: {
			flvwidth: 180,
			flvheight: 320,
			flvname: videoSrc
		}
	});
}


(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);

// TOOLTIPS
(function(jQuery) {
    function tooltip(el, fn, options) {
        el.hover(function (e) {
		
		    this.anchor_title = this.title;
            this.title = '';
			
           	jQuery('#' + options.tooltipID).html(fn(this)+"&nbsp");
	
			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")
                .css("left", xPos + "px")
                .fadeIn("fast");
	                
	         
        }, function () {
            this.title = this.anchor_title;
            jQuery('#' + options.tooltipID).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
        };
        
		jQuery('body').append('<div id="' + options.tooltipID + '">' + fn(this) + '&nbsp;</div>');
		jQuery('#' + options.tooltipID)
				.css("z-index", 10000)
				.css("position", "absolute");
		
        return this.each(function() {
            tooltip(jQuery(this), fn, jQuery.extend(defaults, options));
        });
    }
    
})(jQuery);

function BBTool_toolTip() {
	
	jQuery("a."+BBSettings.defaultTTipClassName).tooltip(function (el) {
			var c = (el.anchor_title != "") ? "<p>" + el.anchor_title + "</p>" : "";
			return c ;
		}, {
			'tooltipID': BBSettings.defaultTTipName,
			'tTipHeight': 60,
			'tTipWidth': 60
	});
	
}


function initScrollable( target ) {
	
	scrollable = (typeof(target)!="undefined") ? jQuery( target ) : jQuery(".scrollable");

	scrollable.each( function(i,el) {
	
		var currentLayer = jQuery(this),
			currentList	= jQuery("ul", currentLayer),
			currentListItems = jQuery("li", currentList),
			dspAreaWidth = currentList.parent().innerWidth(),
			itemWidth = 0,
			nbItem = currentListItems.length,
			nextBtn = jQuery(".next", currentLayer),
			prevBtn = jQuery(".prev", currentLayer),
			defaults = {
							index: 0,
							fx: false,
							callback: "",
							loop: true,
							menu: false,
							menuThumb: []
						},
			params = jQuery.extend({}, defaults, eval( "(" + currentList.attr("data-BBParams") + ")") );
		
		currentListItems.each( function() {
			itemWidth = (jQuery(this).outerWidth()>itemWidth) ? jQuery(this).outerWidth() : itemWidth;
		});
		currentListItems.css("width", itemWidth);
		
		var nbItemDsp = Math.floor(dspAreaWidth/itemWidth),
			listWidth = nbItem*itemWidth,
			scrollable = (listWidth>currentList.parent().innerWidth()) ? true : false,
			init = currentLayer.data("init");
		
		currentList.css("width", listWidth + "px");
		
		if( scrollable && !init ) {
			
			currentLayer.data("init", true);
			
			if(params.menu) {
				currentLayer.append("<ul class='menuBar'>");
				var menuBar = jQuery(".menuBar", currentLayer),
					menuItemWidth = Math.floor(dspAreaWidth/nbItem),
					totalItemWidth = menuItemWidth*currentListItems.length,
					menuBarWidth = menuBar.width();
					
				currentListItems.each( function(i,el) {
					currentItem = ( typeof(params.menuThumb[i]) != "undefined" ) ? "<img src='"+params.menuThumb[i]+"' alt='"+eval(i+1)+"'>" : "<span>"+eval(i+1)+"</span>";
					menuBar.append(
						jQuery("<li"+((i==params.index)?" class='selected'":"")+"><a href='##'>"+currentItem+"</a></li>")
							.css("width", menuItemWidth)
							.bind("click", function(e) {
								e.preventDefault();
								index = jQuery("li", menuBar).index(jQuery("li.selected", menuBar));
								step = i - index;
								jQuery("li", menuBar).removeClass("selected");
								jQuery(this).addClass("selected");
								if( step > 0 ) nextBtn.trigger("click", [step]);
								else if( step < 0) prevBtn.trigger("click", [Math.abs(step)]);
							})
					);
				});
				
				if(totalItemWidth<menuBar.width()) {
					marginWidth = menuBarWidth - totalItemWidth;
					menuBar.css({ width: menuBarWidth - marginWidth, paddingLeft: marginWidth/2, paddingRight: marginWidth/2});
				}
				
			}
			
			if(params.index!=0){
				start = currentListItems.slice(0,params.index),
				end = currentListItems.slice(params.index);
				currentList.empty().append(end).append(start);
			}
			
			nextBtn.bind("click", function( e, step ) {
				e.preventDefault();
				var clicked = false;
				if(typeof(step)=="undefined") {
					clicked = true;
					step = 1;
				}
				if(jQuery(":animated", currentLayer).length==0) {
					var allItems = jQuery("li", currentList),
						newElem = jQuery("li:lt("+step+")", currentList),
						lastItem = allItems.eq(allItems.length-1);
					newElem.clone(true).insertAfter(lastItem);
					if(params.fx) motionBlur();
					currentList.css({ position: "relative", width: listWidth + itemWidth*step }).animate({left: "-"+itemWidth*step }, 350*step/step*2, function() {
						newElem.remove();
						jQuery(this).css({left: 0, width: listWidth});
						if(jQuery.isFunction(params.callback)) {
							(params.callback).call();
						}
						if(params.menu&&clicked) {
							nextMenuItem = jQuery("li", menuBar).eq( jQuery("li", menuBar).index(jQuery("li.selected", menuBar)) + 1 );
							jQuery("li", menuBar).removeClass("selected");
							nextMenuItem.addClass("selected");
						}
					});
				}
			}).css("display", "block");
			
			prevBtn.bind("click", function( e, step ) {
				e.preventDefault();
				var clicked = false;
				if(typeof(step)=="undefined") {
					step = 1;
					clicked = true;
				}
				if(jQuery(":animated", currentLayer).length==0) {
					var allItems = jQuery("li", currentList),
						newElem = jQuery("li:gt("+eval(allItems.length-1-step)+")", currentList),
						firstItem = allItems.eq(0);
						
					currentList.css({ position: "relative", width: listWidth + itemWidth*step, left: -itemWidth*step })
					newElem.clone(true).insertBefore(firstItem);
					if(params.fx) motionBlur();
					currentList.animate({left: "+=" + itemWidth*step }, 350*step/step*2, function() {
						newElem.remove();
						if(jQuery.isFunction(params.callback)) {
							(params.callback).call();
						}
						if(params.menu&&clicked) {
							prevMenuItem = jQuery("li", menuBar).eq( jQuery("li", menuBar).index(jQuery("li.selected", menuBar)) - 1 );
							jQuery("li", menuBar).removeClass("selected");
							prevMenuItem.addClass("selected");
						}
					});
				
				}
			}).css("display", "block");
			
		} else {
			nextBtn.css("display", "none");
			prevBtn.css("display", "none");
		}

	});
	
}


function motionBlur() {

	jQuery(".scrollable img").each( function() {
		currentImg = jQuery(this),
		currentImgURL = currentImg.attr("src"),
		tmpHTML = "";
		for(i=0;i<7;i++) {
			tmpHTML += '<img class="blur-clone" src="'+currentImgURL+'" style="position: absolute; top: 0; left:'+(Math.floor(Math.random()*-30)-7)+'px;"/>';
		}
		currentImg.parent().append(tmpHTML);
	});
	jQuery(".scrollable .blur-clone").animate({opacity: 0.15}, 250, function() {
		jQuery(this).animate({opacity: 0}, 250, function() { jQuery(this).remove(); });	
	});

}

function initBBRadio( target ) {

	jQuery("form").each( function( i ) {
	
		var currentForm = jQuery(this);
	
		jQuery(".BBRadio", this).each( function( j ) {
		
			var inputName = jQuery(this).attr("name"),
				inputValue = jQuery(this).attr("value"),
				inputTrim = jQuery(this).attr("checked"),
				inputOnClick = jQuery(this).attr("onClick");
			
			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='"+((inputTrim)?"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);
					if(jQuery.isFunction(eval(inputOnClick))) inputOnClick.call();
				})
			)
			
			if(jQuery(".BBRadio[group="+inputName+"]",currentForm).hasClass("checked")) jQuery(".BBRadio[group="+inputName+"]",currentForm).trigger("click");
		});
		
	
	});

}

function initBBCheckbox( target ) {

	contener = (typeof(target)!="undefined") ? jQuery( target ) : jQuery("form");

	contener.each( function( i ) {
	
		var currentContener = jQuery(this),
			nodeType = this.nodeName.toLowerCase();
	
		jQuery(".BBCheckbox", currentContener).each( function( j ) {
		
			var inputName = jQuery(this).attr("name"),
				inputValue = jQuery(this).attr("value");
				checked = jQuery(this).attr("checked");
			
			if(j==0) {
				if(nodeType=="form")
					jQuery("fieldset", currentContener).append("<input type='hidden' name='"+inputName+"' id='"+inputName+"' value=''>");
				else currentContener.append("<input type='hidden' name='"+inputName+"' id='"+inputName+"' value=''>");
			}
				
			jQuery(this).replaceWith(
				jQuery("<div class='BBCheckbox' group='"+inputName+"'>&nbsp;</div>").bind("click", function(e) {
					if(jQuery(this).hasClass("checked")) {
						jQuery(this).removeClass("checked");
						var currentValue = jQuery("#"+inputName).val(),
							newValue = currentValue.replace(","+inputValue,"");
						jQuery("#"+inputName).val( newValue );
					} else {
						jQuery(this).addClass("checked");
						var currentValue = jQuery("#"+inputName).val(),
							newValue = currentValue + "," + inputValue;
						jQuery("#"+inputName).val( newValue );
					}
				})
			)
			if(checked=="checked") jQuery(".BBCheckbox[group="+inputName+"]").eq(j).trigger("click");
		});
	
	});
		
}


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")
							.removeClass("selected")
							.next()
							.stop()
							.slideToggle();
						jQuery("dt", currentSlider)
							.eq(j)
							.attr("selected", "true")
							.addClass("selected")
							.next()
							.stop()
							.slideToggle();
					}
				});
			});
		
		}
		
		jQuery("dt", currentSlider).not(jQuery("dl dt", currentSlider)).each( function(j) {
			if (jQuery(this).attr("class") == "selected") {
				jQuery(this).attr("selected", "true");
			} 
			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();
	
	});

}


// 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);
