var Nom = navigator.appName;
var Version = navigator.appVersion;
var ie6 = (Nom == 'Microsoft Internet Explorer' && Version.indexOf('MSIE 6.0') > 0) ? 1 : 0;
var zoomPopActif = 0;

//if (!ie6) {
    $(document).ready(function() {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ManagejQZoom);
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(StopjQZoom);
		
        ManagejQZoom();

    });
//}

function ManagejQZoom() {

	var imageColoris = $(".imgZoomColoris");	
	var srcImageColoris = imageColoris.attr("src");
	 var testImageColoris = new Image();
            $(testImageColoris).load(function () {
	$(".linkButtonClassVisuColoris").click(function(event){
		
		
		var spanProduit = $(".ProduitImage");
		var spanColoris = $(".spanZoomColoris");
		//var srcImageColoris = imageColoris.attr("src");
		
		imageColoris.attr("jqimg", srcImageColoris);
		if(typeof(FancyZoomActif)!='undefined')
		{ 
			if (ie6) {
				var divSelectBox = $("#ProduitSelectionZone").get(0);  
				if(divSelectBox != null)
				{
					divSelectBox.style.visibility = "hidden";
				}	
				zoomPopActif = 1;
				
				zoomPreload(spanProduit);
				
				return zoomClickIe6(spanProduit, spanColoris, event, divSelectBox);
			}
			else{		
				return zoomClick(spanProduit, spanColoris, event);
			}
		}
	});
	}).attr("src", srcImageColoris);
	
    $(".ProduitImage > img").each(function() {
        if (this.id.indexOf("VisuProduit_imgProduit") > 0 ) {
            var myImage = $(this);
			
			var urlVisuelPourZoom = visuelProduitUrlZoom;
		   
            var testImage = new Image();
            $(testImage).load(function () {
                //ne s'execute que si l'image existe
                myImage.attr("jqimg", urlVisuelPourZoom);

                //myImage.wrap("<div class='jqzoom' style='border-style:none;'></div>");

                var myParent = myImage.parent();

                if (!myParent.hasClass("jqzoom")) {
                    myParent.addClass("jqzoom");
                }
				
				if(typeof(myParent.jqueryzoom)!='undefined')
				{ 
					myParent.jqueryzoom({
						xzoom:320, //zooming div default width(default width value is 200)
						yzoom: 400, //zooming div default width(default height value is 200)
						offset: 10, //zooming div default offset(default offset value is 10)
						position: "left", //zooming div position(default position value is "right")
						preload: 1,
						lens: 1
					});
				}
                //FancyZoom
				if(typeof(FancyZoomActif)!='undefined')
				{ 
					myParent.click(function(event) {
						if (ie6) {
							var divSelectBox = this.document.getElementById("ProduitSelectionZone");
							
							if(divSelectBox != null)
							{
								divSelectBox.style.visibility = "hidden";
							}
							zoomPopActif = 1;
							return zoomClickIe6(this, this, event, divSelectBox);
						}
						else {
							return zoomClick(this, this, event);
						}
					});
				
					var linkZoomProduitButton = $(".linkButtonClassZoom");
					
					linkZoomProduitButton.click(function(event) {
						if (ie6) {
							var divSelectBox = this.document.getElementById("ProduitSelectionZone");
							
							if(divSelectBox != null)
							{
								divSelectBox.style.visibility = "hidden";
							}
							
							zoomPopActif = 1;
							return zoomClickIe6(myParent, myParent, event, divSelectBox);
						}
						else {
							return zoomClick(myParent, myParent, event);
						}
					});
					
					myParent.mouseover(function() {
					
						if (ie6) {
							var divSelectBox = this.document.getElementById("ProduitSelectionZone");
							
							if(divSelectBox != null)
							{
								divSelectBox.style.visibility = "hidden";
							}
						}
						zoomPreload(this);
					});
					
					if (ie6) {
						myParent.mouseout(function() {
							var divSelectBox = this.document.getElementById("ProduitSelectionZone");
							
							if(divSelectBox != null)
							{
								if(zoomPopActif == 0 && !isZoomActive())
								{
									divSelectBox.style.visibility = "visible";
								}
								else
								{
									divSelectBox.style.visibility = "hidden";
								}
							}
							if(!isZoomActive())
							{
								zoomPopActif = 0;
							}
					   });
					}
				
				}
            }).attr("src", urlVisuelPourZoom);
        }
    });
    //URL de la CSS pour trouver les images
    $("link").each(function() {
        if (this.href.indexOf("jqzoom.css") > 0) {
            //alert(this.href.substring(0, this.href.lastIndexOf("/") + 1));
            zoomImagesURI = this.href.substring(0, this.href.lastIndexOf("/") + 1);
        }
    });
    zoomImagesURI = zoomImagesURI + "images/"; 
    if(typeof(FancyZoomActif)!='undefined')
	{ 
		insertZoomHTML();
		
		zoomdiv = document.getElementById(zoomID);
		zoomimg = document.getElementById(theID);
	}

    limitToWindowSize = true; //false;
}

function StopjQZoom() {
    $(".jqzoom").unbind("mouseenter");
    $(".jqzoom").unbind("mouseleave");
}

