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, productId)
{
	$.ajax({
	  type: "POST",
	  beforeSend: '',
	  url: "productGetInfo.php",
	  data: "infoType=price&productGroupId="+productGroupId+"&productId="+productId,
	  success: function(data) {
		if (data != "")
		{
			$("#productPrice").html(data);
		}
		else
		{
			$("#productPrice").html('&nbsp;');
		}
	  }
	});
}

function UpdateProductId (productGroupId, productId)
{
	//alert(productGroupId + ' ' + specification + ' ' size);
	
	//$("#productId").val(productId);
	//GetWebType (productGroupId, specification, size);
	//GetPrice (productGroupId, productId);
	
    $.ajax({
        type: "POST",
        beforeSend: '',
        url: "/ws/productChange.php",
        data: "cmd=change&productId="+productId,
        success: function(data) {
        	data = data.split("|");
        	$("#productId").val(data[0]);
        	$("#productImage").fadeOut();
  			$("#productImage").attr({src: "/productImages/"+data[1]});
        	$("#productImage").fadeIn();
      		$("#color").css("background-color", data[3]);
			$("#productPrice").html(data[2]);
			$("#sizePrice > h4").html(data[4]);
			$("#sizePrice > h3").html(data[2]);
			Cufon.refresh();
          }
      });
	
}

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")
	
}



function SelectSpecification (productGroupId, comboName)
{
	
	$('#specificationCombo').html('');
	
	$.ajax({
	  type: "POST",
	  beforeSend: ChangeImage (),
	  url: "/ws/productSpecificationCombo.php",
	  data: "productGroupId="+productGroupId+"&comboName="+comboName,
	  success: function(data) {
		if (data != "")
		{
			$('#specificationCombo').html(data);
		}
	  }
	});
}

function ChangeSpecification (productId) {
	
	if (productId.length > 0)
	{
		$.ajax({
			  type: "POST",
			  beforeSend: ChangeImage (),
			  url: "/ws/productColor.php",
			  data: "productId="+productId,
			  success: function(data) {
				if (data != "")
				{
					$('#kiicolorSel').css("background-color", data);
					$('#kiicolorSel').show();
				}
			  }
		});
		$("#addC").show();
	}
}




