gallery = function() {
		//$('#content').prepend('<div id="gallery"></div>');
		//$.each(galleryData,function(i,k){
			//$('#gallery').append('<div><p><a href="img/sculture/'+k.image+'" rel="'+i+'"><span class="title">'+k.title+'</span><span class="detail">'+k.detail+'</span><span class="year">'+k.year+'</span></a></p><img src="img/sculture/thumb/'+k.image+'" /></div>');
		//});
		Cufon.replace('#gallery span', { fontFamily: 'Proxima Nova Th'});
		$('#gallery div').hover (
			function() {$(this).find('p').show();},
			function() {$(this).find('p').hide();}
		);
		$('#gallery div').click(function(ev) {lightBox(Number($(this).find('a').attr('rel')));});
		$('#gallery a').click(function(ev) {ev.preventDefault();});
	}
	
	lightBox = function(id) {
		if($('#lightBox').length==0) {
			$('body').css('overflow','hidden');
			//$('html').css('overflow','hidden');
			var stageWidth  = $(window).width();
			var stageHeight = $(window).height();
			var $lightBox = $('<div id="lightBox"></div>').css('width',stageWidth).css('height',stageHeight);
			$lightBox.append('<div id="lightBoxInner"><div id="lightBoxHeader"><div class="logo">Roberto Ciroli</div></div><div id="lightBoxContent" style="height:'+(stageHeight-180)+'px"><div id="lightBoxLoading"><img src="img/loading.gif" /></div><div id="lightBoxImage"></div></div><div id="lightBoxFooter"><div id="lightBoxNav"><span class="nav prev"></span><span class="nav next"></span></div><p></p></div></div>');
			$('body').append($lightBox);
			Cufon.refresh('.logo');
			$('#lightBoxNav .prev').click(function(){lightBox(Number($(this).attr('rel')));});
			$('#lightBoxNav .next').click(function(){lightBox(Number($(this).attr('rel')));});
		}
		
		$('#lightBoxImage img').remove();
		$('#lightBoxLoading').show();
		$('#lightBoxNav .prev').attr('rel',(id==0) ? galleryData.length-1 : id-1);
		$('#lightBoxNav .next').attr('rel',(id==galleryData.length-1) ? 0 : id+1);
		
		
		var detail = (galleryData[id].detail!='') ? ' (Dettaglio)' : '';
		$('#lightBoxFooter p').remove();
		$('#lightBoxFooter').append('<p><span class="title">'+galleryData[id].title+'</span>'+detail+'<br />'+galleryData[id].size+'<br />'+galleryData[id].material+'<br />'+galleryData[id].year+'</p>');
		Cufon.replace('#lightBoxFooter .title', { fontFamily: 'Proxima Nova Th'});
		
		var imgURL = 'img/sculture/'+galleryData[id].image;
		$.cacheImage(imgURL, {
			load : function (e) {
				$('#lightBoxLoading').hide();
				$('#lightBoxImage img').remove();
				$('#lightBoxImage').append('<img alt="Chiudi" src="'+imgURL+'" />');
				var img = $('#lightBoxImage img');
				img.hide();
				img.click(function() {lightBoxClose();});
				lightBoxImageWidth = img.width();
				lightBoxImageHeight = img.height();
				resizeLightBox();
				img.fadeIn();
				$('#lightBoxNav').fadeIn('slow');
				$('#lightBoxFooter').hover(
					function() {$('#lightBoxNav').fadeIn('slow')},
					function() {$('#lightBoxNav').fadeOut()}
				);
				
			},
			error: function (e) { },
			abort: function (e) { },
			complete : function(e) {}
		});
		
		_gaq.push(['_trackEvent', "Sculture", galleryData[id].title]);
	}
	
	lightBoxClose = function() {
		$('#lightBox').remove();
		$('body').css('overflow','auto');
		//$('html').css('overflow','');
	}
	
	
	resizeLightBox = function() {
		if($('#lightBox').length>0) {
			var w,h,imgW,imgH,imgT;
			w  = $(window).width();
			h = $(window).height();
			$('#lightBox').css('width',w).css('height',h);
			$('#lightBoxContent').css('height',h-180);
			imgT = 0;
			imgH = h-220;
			imgW = Math.round(lightBoxImageWidth / lightBoxImageHeight * imgH);
			if(imgW>w-40) {
				imgW = w-40;
				imgH = 	Math.round(lightBoxImageHeight / lightBoxImageWidth * imgW);
				imgT = Math.round((h-180-imgH)/2-20);
			}
			$('#lightBoxImage img').css('height',imgH+'px').css('width',imgW+'px').css('top',imgT+'px');
			
		}
	}
