$(document).ready(function(){
	
	var galleryPath = '/gallery/';
	var roundCorner = true;
	
	var myGalleryPH = $("img.2DGallerySystem");
	if (myGalleryPH.length > 0){
		myGalleryPH.wrap('<div class="2DGallery"></div>');
		var myGallery = $("div.2DGallery");
		myGallery.attr('style', myGalleryPH.attr('style'));
		myGallery.css('background', '#fff url('+galleryPath+'images/azioni/loadGallery.gif) no-repeat center center');
		myGallery.css('overflow', 'hidden');
		myGallery.css('margin', '10px');
		myGallery.css('position', 'relative');
		if (roundCorner)
		myGallery.css('border-radius', '5px').css('-moz-border-radius', '5px');
		var myGalleryId = myGalleryPH.attr('id').split('_')[1];
		myGalleryPH.remove();
		/*
		TODO Ajax per recuperare dimensioni corrette galleria
		*/
		
		$.ajax({
		  url: galleryPath+'manageGallery.php?getGallery='+myGalleryId,
		  success: function(data) {
		    myGallery.html(data);
		    var myMaxW = myGallery.find('input[name='+myGalleryId+'_maxW]').val();
		    var myMaxH = myGallery.find('input[name='+myGalleryId+'_maxH]').val();
		    myGallery.find('input[name='+myGalleryId+'_maxW]').remove();
		    myGallery.find('input[name='+myGalleryId+'_maxH]').remove();
		    myGallery.css('width', myMaxW+'px').css('height', myMaxH+'px');
		    myGallery.find("img.2DGalleryImage").css('top', '0px').css('left', '0px').css('margin', '0px').css('padding', '0px');
		    if (roundCorner)
		    myGallery.find("img.2DGalleryImage").css('border-radius', '5px').css('-moz-border-radius', '5px');
		    /*
		    $('img.2DGalleryImage').captify({
					speedOver: 'fast',
					speedOut: 'normal',
					hideDelay: 500,
					animation: 'slide',
					prefix: '',
					opacity: '0.7',
					className: 'caption-bottom',
					position: 'bottom',
					spanWidth: '100%'
				});
				*/
				myGallery.cycle({
			    fx:    'fade',
			    speed:  1500
				});
				myGallery.css('background', 'transparent');
		  }
		});
	}
});
