/* 
Lightbox in jQuery
*/



Array.prototype.contains = function(obj, field){
	// specifica per la struttura del json
	var found = -1;
	for (i = 0; i < this.length; i++){
		if(this[i][field] == obj) {
			found = i;
			break;
		}
	}
	return found;
};

function anno_uscite(){
	this.anno = 0;
	this.uscite = new Array();
}

lightbox = {
	options : {
		json: 'http://www.nova100.ilsole24ore.com/static/copertine/json/copertine_2.json',
		jsonName: 'copertine_2.json', 
		speed : 'slow', 
		animationSpeed : 800,
		isAnimated: true,
		overlay_opacity: '0.65',
		loadingImage: '/img2008/lightbox/loading.gif',
		delay: 5000,
		paginationModule: 7, 
		iframeSpotUrl: '',
		counterIntro: "Copertina del ",
		website: "http://www.novaonline.ilsole24ore.com",
		hasPadding: {
			top: 0,
			bottom: 0,
			left: 0,
			right: 0
		}, 
		templateUrl: 'http://www.nova100.ilsole24ore.com/static/copertine/lightbox.html', 
		sitecensus: {
			url: '//secure-it.imrworldwide.com/cgi-bin/m?ci=ilsole-it&cg=0&si=',
			completeurl: '', 
			lboxparam: 'lb=1'
		},
		contentType: 0 
	},
	
	dimensions: {
		img_box_h: 594, 
		img_box_w: 466,
		cnt_box_h: 792, 
		cnt_box_w: 1000
	},
	
	_custom: {
		theList: new Array(),
		select_anno: "",
		select_mesegiorno: "",
		indexField: "data",
		json: "http://novareview.ilsole24ore.com/static/copertine/json/copertine.json", 
		approfondimenti: true,
		fromHP: false,
		max_review: 3 
	},
	
	flags : {
		pageLoaded: false,
		activeSlideshow: false,
		active: false,
		hideimage: false,
		hasCustomBoxes: true,
		hasFixedDimImages: true
	},
	
	keyboard: { 
		left_arrow: 37,
		right_arrow: 39,
		esc_key: 27
	},
	
	browser: {
		msie6: $.browser.msie && ($.browser.version == "6.0"),
		msie7: $.browser.msie && ($.browser.version == "7.0"),
		ffox: $.browser.mozilla,
		safari: $.browser.safari,
		opera: $.browser.opera
	},
	
	debug : function(logger){
		if (navigator.userAgent.indexOf('Firefox') != -1)
			console.log(logger);
		else window.alert(logger);
	},

	windowload : function(){
		lightbox.flags.pageLoaded = true;
	},
	
	initialize : function(json, caller){
		if (lightbox.flags.pageLoaded && !lightbox.flags.active) {
			lightbox.flags.active = true;
			lightbox.options.iframeSpotUrl = "http://www.nova100.ilsole24ore.com/static/copertine/spot_include.html";
			lightbox.caller = caller;
			lightbox.loadSuccess = false;
			if(!lightbox._custom.fromHP)
				if(json != "") lightbox.getData(json);
				else lightbox.getData(lightbox.options.json);
			else {
				lightbox.loadSuccess = true;
				lightbox.launch();
			}
		}
	},
	
	getData : function(url){
		$.ajaxSetup({
			error: function(XMLHttpRequest, textStatus, errorThrown){
				if(url.indexOf('copertine') > -1){ // e' una get delle lightbox
					if(url.indexOf('copertine.json') < 0)
						lightbox.getData(lightbox._custom.json);
					else {
						lightbox.loadSuccess = false;
						lightbox.launchFailure();
					}
				}
			 }
		});
		
		$.getJSON(url, function(json){
			lightbox.galleryItems = json;
			lightbox.loadSuccess = true;
			if(url.indexOf(lightbox.options.jsonName) < 0) lightbox._custom.approfondimenti = false;
			lightbox.launch();
		});
	},

	checkStartIndex: function(i){
		myIndex = 0;
		if(i >= lightbox.galleryItems.copertine.length)
			myIndex = lightbox.galleryItems.copertine.length - 1;
		else myIndex = i;
		return myIndex;
	},
	
	launch: function(){
		lightbox.flags.activeSlideshow = false;
		if (($(lightbox.caller).attr("rel") != undefined) && $(lightbox.caller).attr("rel") != ""){
			index = lightbox.galleryItems.copertine.contains($(lightbox.caller).attr("rel"), lightbox._custom.indexField);
			lightbox.startIndex = index;
			lightbox.currentIndex = index;
		} else {
			lightbox.currentIndex = 0;
			lightbox.startIndex = 0;
		}
		lightbox.hideFlash();
		//if(lightbox.browser.msie7 || lightbox.options.msie6) $('html').css("overflow-x", "hidden"); // ie
		$('body')
			//.css("overflow-x", "hidden")
			.append('<div id="overlay" style="display:none"> </div>');
		$('#overlay')
			.height($(document).height())
			.width($(document).width())
			.css('opacity', lightbox.options.overlay_opacity)
			.bind('click',function(){
				lightbox.close();
				return false;
			});
		lightbox.launchSuccess();
		
		$(window).bind('resize', function(){
			lightbox.alignCenter($('#cnt_lbox').outerWidth(), $('#cnt_lbox').outerHeight(), false); // init = false
			$('#overlay')
				.height($(document).height())
				.width($(document).width())
		});
	},

	launchFailure: function(){
		$('#overlay').show();
		window.alert("ERROR getting Items");
		lightbox.close();
	},
	
	launchSuccess: function(){
		lightbox.options.paginationModule = (lightbox.galleryItems.copertine.length < lightbox.options.paginationModule ? lightbox.galleryItems.copertine.length : lightbox.options.paginationModule);
		padding = lightbox.getContentPadding();
		if (lightbox.options.isAnimated)
			$('#overlay').fadeIn(lightbox.options.speed, function(){
				$('body').append('<div id="lightbox"><div id="cnt_lbox" class="clearfix"> </div></div>');
				
				lightbox.resizeLightbox(true);
			});
		else {
			$('#overlay').show();

			lightbox.resizeLightbox(true);
		}
		lightbox.setupSitecensus();
	},

	activateOverflow: function(){
		win_w = parseInt($(window).width());
		if (lightbox.browser.msie6 || lightbox.browser.msie7) win_w = win_w - 20; // tolgo la dimensione delle scrollbar
		if( win_w < lightbox.dimensions.cnt_box_w){
			//if (lightbox.browser.msie6 || lightbox.browser.msie7) $('body').css("overflow-x", "auto");
			//$('html').css("overflow-x", "auto");
		} else {
			//if (lightbox.browser.msie6 || lightbox.browser.msie7) $('body').css("overflow-x", "hidden");
			//$('html').css("overflow-x", "hidden");
		}
	},
	
	getBoxDimensions: function(){
		if(!lightbox.flags.hasFixedDimImages){
			if(lightbox.options.contentType == 0) {
				lightbox.dimensions.img_box_h = lightbox.galleryItems.images[lightbox.currentIndex].height;
				lightbox.dimensions.img_box_w = lightbox.galleryItems.images[lightbox.currentIndex].width;
				overhead = 130;
			} else {
				lightbox.dimensions.img_box_h = lightbox.galleryItems.video[0].height;
				lightbox.dimensions.img_box_w = lightbox.galleryItems.video[0].width;
				overhead = 84;
			}
			lightbox.dimensions.cnt_box_h = lightbox.dimensions.img_box_h + overhead;
			lightbox.dimensions.cnt_box_w = 850;
		}
	},
	
	getContentPadding: function(){
		var padding = {vert: 0, horiz: 0}
		if(lightbox.options.hasPadding != null){
			padding.vert = lightbox.options.hasPadding.top + lightbox.options.hasPadding.bottom;
			padding.horiz = lightbox.options.hasPadding.left + lightbox.options.hasPadding.right;
		}
		return padding;
	},
	
	setupSitecensus: function(){
		loc = escape(document.location.href);
		if(lightbox.options.sitecensus.lboxparam == "")
			lightbox.options.sitecensus.completeurl = lightbox.options.sitecensus.url + loc;
		else {
			if(document.location.href.indexOf("?") > 0) 
				lightbox.options.sitecensus.completeurl = lightbox.options.sitecensus.url + loc + escape("&" + lightbox.options.sitecensus.lboxparam);
			else 
				lightbox.options.sitecensus.completeurl = lightbox.options.sitecensus.url + loc + escape("?" + lightbox.options.sitecensus.lboxparam);
		}
	},
	
	alignCenter : function(width, height, init){
		var leftval = ($(window).width() / 2 ) - (width / 2);
		var topval = ($(window).height() / 2) - (height / 2) + $(document).scrollTop();
		if (leftval < 0) leftval = 0;
		if (topval < 0) topval = 0;
		if(!lightbox.options.isAnimated || init)
			$('#lightbox')
				.css({
					'left': leftval,
					'top': topval
				});
		else $('#lightbox').animate({"top": topval, "left": leftval}, lightbox.options.animationSpeed);
		lightbox.activateOverflow();
	},
	
	resizeLightbox : function(init) {
			if(lightbox.options.isAnimated){
				if(init)
					padding = lightbox.getContentPadding();
					lightbox.alignCenter(lightbox.dimensions.cnt_box_w + padding.horiz, lightbox.dimensions.cnt_box_h + padding.vert, init);
					$('#cnt_lbox')
						.css({
							"padding": "0px",
							"width": "1px",
							"height": "1px"
						})
						.animate({
							"width": lightbox.dimensions.cnt_box_w
							}, lightbox.options.animationSpeed, function(){
								if(lightbox.options.hasPadding != null){
									$('#cnt_lbox').css({
										"padding-top": lightbox.options.hasPadding.top,
										"padding-bottom": lightbox.options.hasPadding.bottom,
										"padding-left": lightbox.options.hasPadding.left,
										"padding-right": lightbox.options.hasPadding.right
									});
								}
							$('#cnt_lbox').animate({"height": lightbox.dimensions.cnt_box_h}, lightbox.options.animationSpeed, function(){
								lightbox.showLightbox(init);
								$('#current_image').show();
							});
						});
			} else {
				$('#cnt_lbox').height(lightbox.dimensions.cnt_box_h);
				lightbox.showLightbox(init);
				$('#current_image').show();
			}
	},
	
	showLightbox: function(init){
		if (init) lightbox.createLightbox();
		lightbox.alignCenter($('#cnt_lbox').outerWidth(), $('#cnt_lbox').outerHeight(), init); 
	},
	
	resizeImageBox : function() {
		if(!lightbox.flags.hasFixedDimImages){
			lightbox.getBoxDimensions();
			padding = lightbox.getContentPadding();
			if(lightbox.options.isAnimated){
				$('#current_image').css("visibility", "hidden"); // cosi' mantiene gli ingombri
				$('#current_image').height(lightbox.dimensions.img_box_h);
				$('#bannerLB').hide();
				$('#current_image img')
					.css({
						"width": lightbox.galleryItems.images[lightbox.currentIndex].width,
						"height": lightbox.galleryItems.images[lightbox.currentIndex].height
					});
				$('#cnt_lbox').animate({"height": lightbox.dimensions.cnt_box_h}, lightbox.options.animationSpeed, function(){
					$('#bannerLB').show();
					$('#current_image').css("visibility", "visible");
					$('#current_image img').fadeIn(lightbox.options.speed);
				});
			} else {
				$('#current_image').height(lightbox.dimensions.img_box_h);
				$('#cnt_lbox').height(lightbox.dimensions.cnt_box_h);
			}
			lightbox.alignCenter(lightbox.dimensions.cnt_box_w + padding.horiz, lightbox.dimensions.cnt_box_h + padding.vert, false);
		}	},
	
	createLightbox : function() {
		if (!lightbox.options.isAnimated){
			$('body').append('<div id="lightbox"><div id="cnt_lbox"  style="display:none;" class="clearfix"> </div></div>');
			$('#cnt_lbox').show();
		}
		$('#cnt_lbox').css('opacity', '1');
		$('#cnt_lbox').append(lightbox.injectGalleryHtml());
		$('#spot').append('<iframe id="bannerLB" scrolling="no" frameborder="0" allowtransparency="true" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" src="" ></iframe>');
		$('a#close_lbox').bind('click', function(){
			lightbox.close();
			return false;
		});
		$('#firstLink').bind('click', function(){
			lightbox.showImage(0, true, true);
			return false;
		});
		$('#prevLink').click(function(){
			lightbox.showImage(-1, false, true);
			return false;
		});
		$('#nextLink').click(function(e){
			lightbox.showImage(1, false, true);
			return false;
		});
		$('#lastLink').bind('click', function(){
			lightbox.showImage(lightbox.galleryItems.copertine.length - 1, true, true);
			return false;
		});
		$('#startSlider').bind('click', lightbox.startSlideshow);
		if(lightbox.flags.hasCustomBoxes) {
			lightbox._setupSpecialBox(); 
			lightbox._injectSpecialBox();
		}
		$(document).keydown(lightbox.keyboard_navigation);
		lightbox.showImage(lightbox.startIndex, true, false);
	},

	keyboard_navigation: function(e){
		switch(e.keyCode){
			case lightbox.keyboard.left_arrow:
				lightbox.showImage(-1, false, false);
				break;
			case lightbox.keyboard.right_arrow:
				lightbox.showImage(1, false, false);
				break;
			case lightbox.keyboard.esc_key:
				lightbox.close();
				break;
		}
	},
	
	injectGalleryHtml : function(){
		var html = $.ajax({
			url: lightbox.options.templateUrl,
			type: 'GET',
			datatype: 'html', 
			async: false,
			error: function(){
				window.alert("Errore caricamento template");
				lightbox.close();
			}
		}).responseText;
		return html;
	},
	
	refreshSitecensus: function(){
		if(lightbox.options.sitecensus.completeurl == "") lightbox.setupSitecensus();
		$('img#sitecensus').attr('src', lightbox.options.sitecensus.completeurl + "&rnd=" + new Date().getTime());
	},
	
	loading: function(){ 
	},
	
	startSlideshow : function(){
		if(!lightbox.flags.activeSlideshow){
			lightbox.flags.activeSlideshow = true;
			$('#current_image img').unbind();
			$(document).unbind('keydown');
			$('#startSlider').unbind('click', lightbox.startSlideshow);
			$('#startSlider').hide();
			$('#stopSlider').show();
			$('#stopSlider').bind('click', lightbox.stopSlideshow);
			lightbox.timerControl('start');
		}
		return false;
	},

	stopSlideshow : function(){
		if(lightbox.flags.activeSlideshow){
			lightbox.timerControl('stop');
			$('#stopSlider').unbind('click', lightbox.stopSlideshow);
			$('#stopSlider').hide();
			$('#startSlider').show();
			$('#startSlider').bind('click', lightbox.startSlideshow);
			$('#current_image img').click(function(){
					lightbox.showImage(1, false, false);
				})
				.hover(function(){
					$(this).css("cursor", "pointer");
				}, function(){
					$(this).css("cursor", "default");
				});
			$(document).keydown(lightbox.keyboard_navigation);
			lightbox.flags.activeSlideshow = false;
		}
		return false;
	},
	
	timerControl : function(action) {
		if (action == 'start') {
			lightbox.timer = self.setInterval("lightbox.showImage(1, false, false)", lightbox.options.delay)
		} else {
			lightbox.timer = clearInterval(lightbox.timer);
			lightbox.timer = null;
		}
	},

	setPagination : function(){
		var rangeMax, rangeMin;
		var paginationString = '';
		var resto = lightbox.currentIndex % lightbox.options.paginationModule;
		
		if (lightbox.currentIndex != 0)
			rangeMin = lightbox.currentIndex - Math.floor(lightbox.options.paginationModule / 2) ;
		else rangeMin = 0;
		rangeMax = rangeMin + lightbox.options.paginationModule - 1;
		if (rangeMax >= lightbox.galleryItems.copertine.length) {
			rangeMax = lightbox.galleryItems.copertine.length - 1;
			rangeMin = lightbox.galleryItems.copertine.length - lightbox.options.paginationModule;
		}
		if (rangeMin < 0){
			rangeMin = 0;
			rangeMax = lightbox.options.paginationModule - 1;
		}
		$('#gallery_pagination').empty();
		for (var i = rangeMin; i <= rangeMax; i++){
			var tag = 'img' + i;
			paginationString ='\n<li id="' + tag + '" rel="' + i + '"><a href="javascript:void(0)" ';
			if (i == lightbox.currentIndex)
				paginationString +='class="selected"';
			paginationString +='>' + (i + 1);
			paginationString +='</a></li>';
			$('#gallery_pagination').append(paginationString);
			$('#' + tag).bind('click', function(){
				lightbox.showImage($('#' + this.id).attr("rel"), true, true); // true = arriva dal click della paginazione
			});
		}
	},

	showImage : function(value, absolute, fromPagination){
		if (fromPagination) lightbox.stopSlideshow();
		if (!absolute) index = parseInt(lightbox.currentIndex) + parseInt(value);
		else index = value;
		index = lightbox.checkIndex(index);
		prevIndex = lightbox.currentIndex;
		lightbox.currentIndex = index;
		$('#current_image img').replaceWith('<img src="' + lightbox.options.website + lightbox.galleryItems.copertine[index].src + '" width="466" height="594" alt="' + lightbox.galleryItems.copertine[index].data + '" />');
		if(!lightbox.flags.activeSlideshow)
			$('#current_image img').click(function(){
				lightbox.showImage(1, false, false);
			}).hover(function(){
				$(this).css("cursor", "pointer");
			}, function(){
				$(this).css("cursor", "default");
			});
		lightbox.setPagination();
		if(lightbox.galleryItems.copertine[index].pdf == "") 
			$('#image_caption').hide();
		else {
			$('#image_caption').show();
		$('#image_caption a').attr("href", lightbox.options.website + lightbox.galleryItems.copertine[index].pdf);
		}
		lightbox.setCounter(index);
		if(lightbox._custom.approfondimenti == true) lightbox._setupApprofondimenti()
		if(lightbox.browser.msie6){
			$('#bannerLB').attr('src',lightbox.options.iframeSpotUrl).load(function(){
				$('#cnt_lbox').focus(function(){
					$(document).focus();
				}).focus();
			});
		} else $('#bannerLB').attr('src',lightbox.options.iframeSpotUrl);
		lightbox.refreshSitecensus();
	},

	preloadcopertine : function (index){
		
	},
	
	checkIndex : function(index){
		if (index < 0) index = lightbox.galleryItems.copertine.length - 1;
		if (index >= lightbox.galleryItems.copertine.length) index = 0;
		return index;
	},
	
	setCounter : function(index) {
		index = parseInt(index);
		$('#counter').empty();
		$('#counter').append(lightbox.options.counterIntro + lightbox.galleryItems.copertine[index].giorno + " " + lightbox.galleryItems.copertine[index].mese + " " + lightbox.galleryItems.copertine[index].anno);
	},

	hideFlash: function(){
		$('iframe').css('visibility', 'hidden');
		$('object').css('visibility', 'hidden');
		$('embed').css('visibility', 'hidden');
		if(lightbox.browser.msie6) $('select.nova09_select').css('visibility', 'hidden');
	},

	showFlash: function(){
		$('iframe').css('visibility', 'visible');
		$('object').css('visibility', 'visible');
		$('embed').css('visibility', 'visible');
		if(lightbox.browser.msie6) $('select.nova09_select').css('visibility', 'visible');
	},

	close: function(){
		if (!lightbox.loadSuccess)
			$('#overlay').empty().remove();
		else {
			if (lightbox.timer != null)
				lightbox.stopSlideshow();
			lightbox._custom.theList = null;
			lightbox._custom.select_anno = "";
			lightbox._custom.select_mesegiorno = "";
			$(window).unbind('resize');
			$(document).unbind('keydown');
			if (lightbox.options.isAnimated){
			$('#cnt_lbox')
				.empty()
				.animate({'height': '1px','opacity': '1'}, lightbox.options.animationSpeed)
				.css({"padding": "0px"})
				.animate({'width' : '1px'}, lightbox.options.animationSpeed, function(){
					$('#lightbox').empty().remove();
					$('#overlay').fadeOut(lightbox.options.speed, function(){
						$('#overlay').remove();
						lightbox.showFlash();
						//if(lightbox.browser.msie6 || lightbox.browser.msie7) $('html').css("overflow", "auto");
						//$('body').css("overflow", "auto");
					});
				});
			} else {
				$('#lightbox').empty().remove();
				$('#overlay').remove();
				lightbox.showFlash();
				//if(lightbox.browser.msie6 || lightbox.browser.msie7) $('html').css("overflow", "auto");
				//$('body').css("overflow", "auto");
			}
		}
		lightbox.flags.active = false;
	},
	
	_initializeSpecialBox: function(){
		lightbox._custom.select_anno = "";
		lightbox._custom.select_mesegiorno = "";
		for(x = 0; x < lightbox._custom.theList.length; x++) 
			lightbox._custom.select_anno = lightbox._custom.select_anno + "<option value=\"" + lightbox._custom.theList[x].anno  + "\">" + lightbox._custom.theList[x].anno + "</option>";
		for(x = 0; x < lightbox._custom.theList[0].uscite.length; x++) 
			lightbox._custom.select_mesegiorno = lightbox._custom.select_mesegiorno + "<option value=\"" + lightbox._custom.theList[0].uscite[x] + "\">" + lightbox._custom.theList[0].uscite[x] + "</option>";
	},
	
	_setupSpecialBox: function(){
		var year_counter = 0, index_found = -1;
		var theList = new Array();
		var llength = 0;
		for (i = -1; i < lightbox.galleryItems.copertine.length; i++) {
			if(theList.length > 0){
				index_found = -1;
				for (y = 0; y < theList.length; y++){
					if( theList[y].anno == lightbox.galleryItems.copertine[i].anno) {
						index_found = y;
					}
				}
				if(index_found == -1){
					theList[llength] = new anno_uscite;
					theList[llength].anno = lightbox.galleryItems.copertine[i].anno;
					theList[llength].uscite[0] = lightbox.galleryItems.copertine[i].giorno + " " + lightbox.galleryItems.copertine[i].mese;
					llength ++;
				} else {
					theList[index_found].uscite[theList[index_found].uscite.length] = lightbox.galleryItems.copertine[i].giorno + " " + lightbox.galleryItems.copertine[i].mese;
				}
			} else {
				theList[llength] = new anno_uscite;
				theList[llength].anno = "Anno";
				theList[llength].uscite[0] = "Mese e Giorno";
				llength ++;
			}
		}
		lightbox._custom.theList = null;
		lightbox._custom.theList = theList;
		lightbox._initializeSpecialBox();
	},
	
	_injectSpecialBox: function(){
		$('#cnt_lbox select.form-anno')
			.empty()
			.append(lightbox._custom.select_anno)
			.change(lightbox._changeSpecialBox);
		$('#cnt_lbox select.form-mese')
			.empty()
			.append(lightbox._custom.select_mesegiorno);
		$('#cnt_lbox a#cercaform')
			.click(lightbox._actionSpecialBox)
//			.hover(function(){
//				$(this).css("cursor", "pointer");
//			}, function(){
//				$(this).css("cursor", "normal");
//			})
			;
		
	},
	
	_changeSpecialBox: function(){
		if($('#cnt_lbox select.form-anno option:selected').attr("value") != "Anno"){
			lightbox._custom.select_mesegiorno = "";
			for(x = 0; x < lightbox._custom.theList.length; x++) {
				if(lightbox._custom.theList[x].anno == $('#cnt_lbox select.form-anno option:selected').attr("value")){
					for(y = 0; y < lightbox._custom.theList[x].uscite.length; y++) lightbox._custom.select_mesegiorno = lightbox._custom.select_mesegiorno + "<option value=\"" + lightbox._custom.theList[x].uscite[y] + "\">" + lightbox._custom.theList[x].uscite[y] + "</option>";
				}
			}
		} else {
			lightbox._custom.select_mesegiorno = "<option value=\"Mese e Giorno\">Mese e Giorno</option>";
		}
		$('#cnt_lbox select.form-mese')
			.empty()
			.append(lightbox._custom.select_mesegiorno);
	},
	
	_actionSpecialBox: function(){
		if (($('#cnt_lbox select.form-mese').attr("value") != "Mese e Giorno") && ($('#cnt_lbox select.form-anno').attr("value") != "Anno")) {
			var data = $('#cnt_lbox select.form-mese').attr("value") + " " + $('#cnt_lbox select.form-anno').attr("value");
			lightbox.showImage(lightbox.galleryItems.copertine.contains(data, "data"), true, true);
			lightbox._initializeSpecialBox();
			lightbox._injectSpecialBox();
		}
	},
	
	_setupApprofondimenti: function(){
		$('#approfondimenti').show().find('div').remove();
		var length = 0;
		var review = lightbox.galleryItems.copertine[lightbox.currentIndex].approfondimenti;
		if(typeof(review) != 'undefined'){
			type = typeof(review.length);
			//if(type == 'undefined') review.length = 1; // quando e' lung 1 non e' un array
			if (review.length > 0){
				if(lightbox._custom.max_review > review.length) length = review.length;
				else length = lightbox._custom.max_review;
				for(i = 0; i < length; i++)
					/*if (length == 1) $('#approfondimenti').append("<div class=\"nova09_copertina_dx_review_riga\"><a target=\"blank\" href=\"" + review.link +"\" title=\"" + review.valore + "\">" + review.valore + " &gt;&gt;</a></div>");
					else*/ $('#approfondimenti').append("<div class=\"nova09_copertina_dx_review_riga\"><a target=\"blank\" href=\"" + review[i].link +"\" title=\"" + review[i].valore + "\">" + review[i].valore + "</a></div>");
						
				$('#approfondimenti div:last').addClass("nova09_copertina_dx_review_riga_last");
			} else $('#approfondimenti').hide();
		} else $('#approfondimenti').hide();
	}
	
}

