﻿var array_galleria;
var n_galleria = 0;

function click_cambia(){
  n_galleria = n_galleria + 1 ;

  if(array_galleria.length == n_galleria)
    n_galleria = 0;
    
  var next_galleria = 0;
  if(array_galleria.length - 1 > n_galleria)
    next_galleria = n_galleria + 1;

  $('#div_quartolivello div.div_cambiavista a.a_cambiavista img.primopiano').attr("src", "/ShowImageMin.ashx?file=" + array_galleria[next_galleria] + "&on=true");
  $('#immagine_prodotto').remove();
  $('#div_immagine_prodotto').addClass('loading');
 
  var img = new Image();
  img.id = 'immagine_prodotto';
  $(img).load(function () {
      //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
      $(img).hide();
      $('#div_immagine_prodotto').removeClass('loading').append(img);
      $(img).show();
      fixPNG(img, 650, 650);
  }).error(function () {
    alert('errore');
      // notify the user that the image could not be loaded
  }).attr('src', '/ShowImage.ashx?file=' + array_galleria[n_galleria]);
                    
  //$('.ImageProdotto').attr("src", "/ShowImage.ashx?file=" + array_galleria[n_galleria]);
 
}