function ChangeImage ()
{
	startLoading("foto_prodotto");
}

function ShowImage ()
{
	stopLoading("foto_prodotto");
}

function GetImage (productGroupId, specification, size)
{
	$.ajax({
	  type: "POST",
	  beforeSend: '',
	  url: "productGetInfo.php",
	  data: "infoType=image1&productGroupId="+productGroupId+"&specification="+specification+"&productId="+size,
	  success: function(data) {
		if (data != "")
		{
			//alert(data);
			data = data.split(",");
			$("#productFrontImage").attr({
				 src: "/productImages/"+data[1]
			});
			
			$("#productImageA").attr({
				 href: "#"
			});
			
			$(".lenteFronte").html("<a href=\"#\" onclick=\"ZoomView('productImage', 'productImageA', '"+data[2]+"', 'jqzoom');\"></a>");
		}
		
	  }
	});
}

function GetImage2 (productGroupId, specification, size)
{
	$.ajax({
	  type: "POST",
	  beforeSend: '',
	  url: "productGetInfo.php",
	  data: "infoType=image2&productGroupId="+productGroupId+"&specification="+specification+"&productId="+size,
	  success: function(data) {
		if (data != "")
		{
			//alert(data);
			data = data.split(",");
			$("#productRearImage").attr({
				 src: "/productImages/"+data[1]
			});
			
			$("#productRearA").attr({
				 href: "#"
			});

			$(".lenteRetro").html("<a href=\"#\" onclick=\"ZoomView('productImage', 'productRearA', '"+data[2]+"', 'jqzoom2');\"></a>");
			
		}
		
		
	  }
	});
}

function GetWebType (productGroupId, specification, size)
{
	$.ajax({
	  type: "POST",
	  beforeSend: '',
	  url: "productGetInfo.php",
	  data: "infoType=webType&productGroupId="+productGroupId+"&specification="+specification+"&productId="+size,
	  success: function(data) {
		if (data != "")
		{
			$("#button_news").removeClass("nobackground");
			$("#webType").removeClass("nobackground");
			$("#webType").html(data);
		}
		else
		{
			$("#button_news").addClass("nobackground");
			$("#webType").addClass("nobackground");
			$("#webType").html('');
		}
	  }
	});
}

function GetPrice (productGroupId, specification, size)
{
	$.ajax({
	  type: "POST",
	  beforeSend: '',
	  url: "productGetInfo.php",
	  data: "infoType=price&productGroupId="+productGroupId+"&specification="+specification+"&productId="+size,
	  success: function(data) {
		if (data != "")
		{
			$("#productPrice").html(data);
		}
		else
		{
			$("#productPrice").html('&nbsp;');
		}
	  }
	});
}

function UpdateProductId (productGroupId, specification, size)
{
	//alert(productGroupId + ' ' + specification + ' ' size);
	
	$("#productId").val($("#taglia").val());
	GetWebType (productGroupId, specification, size);
	GetPrice (productGroupId, specification, size);
}

function GetSize (productGroupId, specification)
{
	$.ajax({
	  type: "POST",
	  beforeSend: ChangeImage (),
	  url: "productGetSize.php",
	  data: "cmd=getSize&productGroupId="+productGroupId+"&specification="+specification,
	  success: function(data) {
		if (data != "")
		{
			$("#taglia").html(data);
			$("#productId").val($("#taglia").val());
			GetImage2 (productGroupId, specification, '');
			GetImage (productGroupId, specification, '');
			GetWebType (productGroupId, specification, '');
			GetPrice (productGroupId, specification, '');
		}
		$("#productFrontImage").load(function () {ShowImage ();});
	  }
	});
	
	$(".jqZoomWindow").remove();
    $(".jqZoomPup").remove();
    $(".preload").remove();
	$("#productImageA").removeClass("jqzoom");
	$("#productRearA").removeClass("jqzoom2");
	$("#productImageA").attr({style: " "});
	$("#productRearA").attr({style: " "});
	$("#productImageA").css("cursor", "default");
	$("#productRearA").css("cursor", "default");

}

function ZoomView (idProduct, idName, imageName, zoomClass)
{
	
	$("#"+idName).attr({
		 href: "/productImages/"+imageName
	});

	$("#"+idName).addClass(zoomClass);

	var optionsZoom2 =
	{
		zoomType: 'reverse',
	    zoomWidth: 391,
	    zoomHeight: 403,
	    title: false,
	    xOffset: 27,
	    yOffset: -1
	};
	var optionsZoom =
	{
		zoomWidth: 391,
		zoomHeight: 403,
		showEffect:'show',
		hideEffect:'fadeout',
		fadeoutSpeed: 'slow',
		xOffset: 27,
		yOffset: -1,
		title :false
	};

	  
	$("."+zoomClass).jqzoom(optionsZoom);
}

function DisplayRetro(idName, zoomClassToRemove)
{
	startLoading("foto_prodotto");
	
	var display = $("#productRear").css("display");

	if (display == "none")
	{
		$("#productImage").addClass("nodisplay");
		$("#productImageA").removeClass("jqzoom");
		$("#productRearA").removeClass("jqzoom2");
		$("#productImageA").attr({style: ""});
		$("#productRearA").attr({style: ""});
		$("#productImageA").css("cursor", "default");
		$("#productRearA").css("cursor", "default");
		$("#"+idName).attr({href: "#"});
		$("#productRear").removeClass("nodisplay");
	}
	else
	{
		$("#productRear").addClass("nodisplay");
		$("#productImage").removeClass("nodisplay");
		$("#productImageA").removeClass("jqzoom");
		$("#productRearA").removeClass("jqzoom2");
		$("#productImageA").attr({style: ""});
		$("#productRearA").attr({style: ""});
		$("#productImageA").css("cursor", "default");
		$("#productRearA").css("cursor", "default");
	}
	
	stopLoading("foto_prodotto")
	
}

