jQuery(document).ready(function(){
	jQuery('.productFotoGalItem').click(function(){
		if(jQuery(this).hasClass('active')) return false;
		
		updateBigImage(jQuery(this));
		return false;
	});
});

function updateImage(index)
{
	thumb = jQuery('.thumb'+index);
	if (thumb.size() > 0){
		updateBigImage(thumb);
	}
	else{
		thumb = jQuery('.thumb0');
		updateBigImage(thumb);
	}
	return false;
}

function updateBigImage(thumb){
	desc = $$('.bigImage')[0].descendants();
	for(i = 0; i < desc.length; i++) {
		desc[i].stopObserving();
	}
	product_zoom.draggable.destroy();
	delete(product_zoom);
	jQuery('.zoomimage').remove();
	rand = Math.round(Math.random()*10000);
	jQuery('.product-image-zoom').append('<img class="zoomimage" id="zoomimage'+rand+'" src="'+thumb.attr('ref')+'" title="'+thumb.children('img').attr('title')+'" alt="'+thumb.children('img').attr('alt')+'" />');
	
	product_zoom = new Atalan.Product.Zoom(jQuery('#zoomimage'+rand).get()[0], 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
	
	thumb.siblings().toggleClass('active', false);
	thumb.toggleClass('active', true);
}
