function redimPictos () {
	//On redimensionne les pictos du produit 
	$(".productPicto").each (function () {
		//alert ($(this).width());
		//alert ($(this).height());
		if ($(this).width() == "NaN" || $(this).height() == "NaN") {
			return;
		}
		if ($(this).width() > 50 || $(this).height() > 50) {
			if ($(this).width() > $(this).height()) {$(this).attr("width", 50);}
			else {$(this).attr("height", 50);}
		}		
		if ($(this).width() <= 50 && $(this).height() <= 50){
			$(this).css("visibility", "visible");		
		}		
	});
	$(".one_picto").css("visibility", "visible");	
}

var lotDetailsHtmlContent = null;
var currentStepRequest = null;

function bindProductionChainStep () {
	$(".productionChainStepLink").bind ("click", function () {

		if ($(this).hasClass("activeStep") == true) {
			return;
		}else {
			$(".activeStep").removeClass("activeStep");
			$(this).addClass("activeStep");
			if (currentStepRequest != null) {
				currentStepRequest.abort();
			}
		}
	
		if (lotDetailsHtmlContent == null) {
			lotDetailsHtmlContent = $("#lotDetailsContent").html();
		}
		
		//On change la couleur de fond de l'élément cliqué
		$(".productionChainStepLink").css("background-color","#DAE8F2");
		$(this).css("background-color","#FFF9F7");
		
		var stepId = $(this).attr("id");

		//On affiche un loader ajax dana la zone de chargement
		$("#lotDetailsContent").html("<div style=\"position:absolute;top:170px;left:580px;\" ><img src=\"/img/ajax_loader_long.gif\"/></div>");
		
		var paramName = "lotProductionChainStepFactoryId";
		if ($(this).hasClass("factoryChainStepEmpty")) {
			paramName = "productionChainStepId";
		}
		
		currentStepRequest = $.ajax({
		    type : 'post',
			url:"/Lot_ajax_productionChainStepFactoryDetails.action",
			data: paramName+"="+stepId,
			success:function(html) {
				$("#lotDetailsContent").html(html);

				//Bindage des csrDomains
				bindImagePreviews();
				
				//Bindage pour les thickbox des csr domains
				$('.thickbox').each(function(i) {
		            $(this).unbind('click');
		        });
				tb_init('a.thickbox, area.thickbox, input.thickbox');
				
				tooltip();
				
				//Bindage des onglets de la description de l'étape
				$("#navtd3 li").unbind();
				$("#navtd3 li").bind ('click', function () {
				    clicked_tab = this;

				    //On teste si l'onglet cliqué n'est pas déjà l'onglet actif
				    if ($(clicked_tab).hasClass("actif") == false) {
					    //On applique le style à l'onglet sélectionné
					    $(clicked_tab).addClass("actif");

				    	$("#navtd3 li").each ( function () {
							if (this != clicked_tab) {							
								$(this).removeClass("actif");
								//On masque les autres contenus
								$("#tab_"+$(this).children("a").attr("id")).hide();				
							}
				    	});

				    	//On affiche le contenu de l'onglet cliqué
						$("#tab_"+$(clicked_tab).children("a").attr("id")).show();
				    }
			    });
				
				if (($("#lotProductionChainStepLatitude").attr('value') == undefined || $("#lotProductionChainStepLatitude").attr('value').length == 0) 
						&& ($("#lotProductionChainStepLongitude").attr('value') == undefined  || $("#lotProductionChainStepLongitude").attr('value').length == 0)) {
					$("#lotProductionChainStepFactoryMap").html("No localization defined for this factory.");
				}
				else {
			        //On récupère les coordonnées de l'usine et on affiche la carte
					var map = new google.maps.Map2(document.getElementById("lotProductionChainStepFactoryMap"));
	
					var factoryPoint = new google.maps.LatLng($("#lotProductionChainStepLatitude").attr('value'), $("#lotProductionChainStepLongitude").attr('value'));
	
			        if (factoryPoint) {
			     	    map.setMapType(G_SATELLITE_MAP);
			 	        map.setCenter(factoryPoint, 4);
			 	        var marker = new google.maps.Marker(factoryPoint);
			 	        map.addOverlay(marker);
			 	        map.addControl(new google.maps.SmallMapControl()); 
			 	        map.addControl(new google.maps.MapTypeControl()); 
			 	    }
				}
				
//				
//				$('ul.gallery').galleria({
//					insert    : '#main_image',
//					onImage   : function (image,caption,thumb) {
//						if (image.width() > 350 || image.height() > 280) {			
//							var ratioWidth = image.width() / 350;
//							var ratioHeight = image.height() / 280;
//							
//							var ratio = 1;
//							if (ratioWidth > ratioHeight) {
//								ratio = ratioWidth;
//								
//							}
//							else {
//								ratio = ratioHeight;				
//							}				
//							var height = image.height() / ratio;
//							var width = image.width() / ratio;
//							image.attr("width",width);
//							image.attr("height",height);
//						}
//						//image.css ("max-width", "350");
//						//image.css ("max-height", "280");
//						image.css ("border", "1px solid #b5c3cd");
//										
//						// fade in the image & caption
//						if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
//							image.css('display','none').fadeIn(200);
//						}
//						else {
//							image.css('display','none').show();
//						}
//						caption.css('display','none');
//						$("#caption_image").html(caption.html());
//						$("#caption_image").css('display','none').fadeIn (200);
//						
//						// fetch the thumbnail container
//						var _li = thumb.parents('li');
//						
//						// fade out inactive thumbnail
//						_li.siblings().children('img.selected').fadeTo(200,0.5);
//						
//						// fade in active thumbnail
//						thumb.fadeTo('fast',1).addClass('selected');
//						
//						// add a title for the clickable image
//						image.attr('title','Next image >>');
//						
//					},
//					onThumb : function(thumb) { // thumbnail effects goes here   				
//						// fetch the thumbnail container
//						var _li = thumb.parents('li');
//						
//						// if thumbnail is active, fade all the way.
//						var _fadeTo = _li.is('.active') ? '1' : '0.5';
//						
//						// fade in the thumbnail when finnished loading
//						thumb.css({display:'none',opacity:_fadeTo}).fadeIn(500);
//						
//						// hover effects
//						thumb.hover(
//							function() { thumb.fadeTo('fast',1); },
//							function() { _li.not('.active').children('img').fadeTo('fast',0.5); } // don't fade out if the parent is active
//						)
//						thumb.parents('li').css ("border", "1px solid #b5c3cd");				
//					}
//				});
				
				//On simule un clic sur l'onglet description de l'étape
				$("#factory_production_step_menu2").click();
			}
		});			
	});	
}

function bindNavigationTabs () {
	$("#navtd2 li").bind ('click', function () {
	    clicked_tab = this;

	    //On teste si l'onglet cliqué n'est pas déjà l'onglet actif
	    if ($(clicked_tab).hasClass("actif") == false) {
		    //On applique le style à l'onglet sélectionné
		    $(clicked_tab).addClass("actif");

	    	$("#navtd2 li").each ( function () {
				if (this != clicked_tab) {
					$(this).removeClass("actif");
					//On masque les autres contenus
					$($(this).children("span").attr("id")).hide();
				}
	    	});
	    	$("#navtdAcc li").each ( function () {
				if (this != clicked_tab) {
					$(this).removeClass("actif");
					//On masque les autres contenus
					$($(this).children("span").attr("id")).hide();
				}
	    	});

	    	//On affiche le contenu de l'onglet cliqué
			$($(clicked_tab).children("span").attr("id")).show();
			
	    	//Si on clique sur la page de détail du lot alors il faut aussi charger le panel de gauche
	    	if ($(clicked_tab).attr("id") == "info_product_menu1" && lotDetailsHtmlContent != null) {
				//$("#lotDetailsContent").html(lotDetailsHtmlContent);
				$("#lotDetailsContent").html("<div id=\"supplyChainMap\"></div>");
				actionAfterLoadLotDetails ();
	    	}
	    }
    });
}

function bindAccessoriesNavigationTabs () {
	$("#navtdAcc li").bind ('click', function () {
	    clicked_tab = this;

	    //On teste si l'onglet cliquÃ© n'est pas dÃ©jÃ  l'onglet actif
	    if ($(clicked_tab).hasClass("actif") == false) {
		    //On applique le style Ã  l'onglet sÃ©lectionnÃ©
		    $(clicked_tab).addClass("actif");

	    	$("#navtdAcc li").each ( function () {
				if (this != clicked_tab) {
					$(this).removeClass("actif");
					//On masque les autres contenus
					$($(this).children("span").attr("id")).hide();				
				}
	    	});
		    
		  	$("#navtd2 li").each ( function () {
				if (this != clicked_tab) {
					$(this).removeClass("actif");
					//On masque les autres contenus
					$($(this).children("span").attr("id")).hide();
				}
	    	});
		  	


	    	//On affiche le contenu de l'onglet cliquÃ©
			$($(clicked_tab).children("span").attr("id")).show();
	    }
    });
}

