	lightRoom_class = function(parent, id, classe, path){
		
		if (path!=''){
			// load stili .css
			_fileref=document.createElement("link");
			_fileref.setAttribute("rel", "stylesheet");
			_fileref.setAttribute("type", "text/css");
			_fileref.setAttribute("href", path+'style.css');
			$('head').append(_fileref);
		}
		
		this._single=0;
		this._classe=classe;
		this._id=id;
		this._totale=$('#'+id+' li').length;
		this._active=1;
		$('#'+id+' li:first-child').addClass('active');
		
		this._body='<div id="nd_gallery" class="'+this._classe+'">';
		this._body+='<div id="nd_gallery_wrapper">';
		this._body+='<div id="nd_gallery_top"><div></div></div>';
		this._body+='<div id="nd_gallery_bottom"><div></div></div>';
		this._body+='<div id="nd_gallery_left"></div>';
		this._body+='<div id="nd_gallery_right"></div>';
		this._body+='<div id="nd_gallery_container">';
		this._body+='<a href="#" class="close"><img src="'+path+'close.png"></a>';
		this._body+='<img class="linguetta" src="'+path+'linguetta.png">';
		this._body+='<div id="nd_gallery_yt"></div>';
		this._body+='<div id="nd_gallery_content"><img src="'+path+'blank.gif"></div>';        
		this._body+='</div>';
		this._body+='<div id="label"></div>';
		this._body+='<div id="label2"></div>';
		this._body+='<div id="counter"></div>';	
		this._body+='<div><div></div></div>';
		this._body+='<div class="loader"><img src="'+path+'loading.gif"></div>';
		this._body+='<a href="#" class="next"><img src="'+path+'next.png"></a>';
		this._body+='<a href="#" class="play"><img src="'+path+'play.png"></a>';
		this._body+='<a href="#" class="pausa"><img src="'+path+'pausa.png"></a>';
		this._body+='<a href="#" class="prev"><img src="'+path+'prec.png"></a>';
		this._body+='</div>';
		this._body+='</div>';
		
		$(parent).append(this._body);
		
		var object=this;
		object.inizialize();
		
		$('#'+this._classe+' .close').click(
			function(){
				object.close();
				return false;
			}
		);
		
		$('#'+this._classe+' .prev').click(
			function(){
				object.prev();
				return false;
			}
		);
		
		$('#'+this._classe+' .next').click(
			function(){
				object.next();
				return false;
			}
		);
		
		$(window).resize(
			function(){
				object.resize();
			}
		);
		
/*		$('#'+this._id+' li a').click({obj: this}, function(e){
			$(".active").removeClass('active');
			$(this).parent().addClass('active');
			e.data.obj.zoom();
			return false;
		});
		
		$('#'+this._classe+' .prev').click({obj: this}, function(e){
			//obj.zoom();
			e.data.obj.prev();
			return false;
		});
		
		$('#'+this._classe+' .next').click({obj: this}, function(e){
			e.data.obj.next();
			return false;
		});
		
		$('#'+this._classe+' .close').click(function(e){
			alert ('close');
			e.data.obj.close();
			return false;
		});*/
	}
	
	lightRoom_class.prototype =
	{
		inizialize : function(){
			var object=this;
			$('#'+this._id+' li a').click(
				function(){
					$(".active").removeClass('active');
					$(this).parent().addClass('active');
					object.zoom();
					return false;
				}
			);
			$('.galleryZoom').click(
				function(){
					$(".active").removeClass('active');
					$(this).addClass('active');
					object.single();
					return false;
				}
			);
			return false;
		},
		
		playFoto : function(){
			var src;
			
			$('#nd_gallery_content img').hide();
			$('#nd_gallery_wrapper .loader').show();
			$('#nd_gallery_wrapper .counter').html(this._active+" di "+this._totale);
			
			if (this._single)
				src='.active';
			else
				src='#'+this._id+' .active a';
			
			if ($(src).hasClass('video')){
				$('#nd_gallery_yt').load(path+'video.php', {id: $(src).attr('href')}, function(){
					$('#nd_gallery_wrapper .loader').hide();
					$('#nd_gallery_wrapper').animate({	
						width: 640,
						height: 390,
						marginTop: (Math.max(5, ( $(window).height()/2)-((390+100)/2) ) )
						}, 500, function() {
							$('#nd_gallery_content').hide();
							$('#nd_gallery_yt').show();
						}
					);
				})
			} else {
				imageObj.src = $(src).attr('href');
				$('#nd_gallery_yt').empty().hide();
				$('#nd_gallery_content').show();
			}
			if (this._totale>1){
				$("#nd_gallery_wrapper .next").show();
				$("#nd_gallery_wrapper .prev").show();
				$('#nd_gallery_wrapper .counter').show();
			}
			$("#nd_gallery_wrapper .close").show();
			return false;
		},
		
		showGallery : function(){
			$('#nd_gallery').show();
			//this.resize();
			return false;
		},

		caricaFoto : function(){
			//$('#nd_gallery_content').width(32).height(1).show();
			$('#nd_gallery_wrapper').width(182).height(132).show();
			$('#nd_gallery_wrapper .loader').show();
			$('#nd_gallery_content img').attr('src', 'img/blank.gif');
			
			this.showGallery();
			this.playFoto();
			return false;
		},
		
		playFirst : function () {
			$("#nd_gallery_wrapper .next").hide();
			$("#nd_gallery_wrapper .prev").hide();
			$("#nd_gallery_wrapper .close").hide();
			$("#nd_gallery_wrapper .counter").hide();
			//alert ('play');
			this._single=0;	
			this.caricaFoto();
			return false;
		},
		
		zoom : function () {
			$("#nd_gallery_wrapper .next").hide();
			$("#nd_gallery_wrapper .prev").hide();
			$("#nd_gallery_wrapper .close").hide();
			$("#nd_gallery_wrapper .counter").hide();
			
			//$('#'+this._id+' li:first-child').addClass('active');
			
			this._single=0;	
			this.caricaFoto();
			return false;
		},
		
		single : function () {
			$("#nd_gallery_wrapper .next").hide();
			$("#nd_gallery_wrapper .prev").hide();
			$("#nd_gallery_wrapper .close").hide();
			$("#nd_gallery_wrapper .counter").hide();
			
			//$('#'+this._id+' li:first-child').addClass('active');
			
			this._single=1;
			this.caricaFoto();
			return false;
		},
		
		next : function(){
			if ($('#'+this._id+' li.active').is(':last-child')){
				this._active=1;
				$('#'+this._id+' li.active').removeClass('active');
				$('#'+this._id+' li:first-child').addClass('active');
			}
			else{
				++this._active;
				$('#'+this._id+' li.active').removeClass('active').next().addClass('active');
			}
			this.playFoto();
		},
		
		prev : function(){
			if ($('#'+this._id+' li.active').is(':first-child')){
				this._active=this._totale;
				$('#'+this._id+' li.active').removeClass('active');
				$('#'+this._id+' li:last-child').addClass('active');
			}
			else{
				$('#'+this._id+' li.active').removeClass('active').prev().addClass('active');
				--this._active;
			}
			this.playFoto();
			return false;
		},
		
		close : function(){
			$('#nd_gallery').fadeOut();
		},
		
		resize : function(){
			$('.'+this._classe+' #nd_gallery_wrapper').animate({
				marginTop: (Math.max(5, ( $(window).height()/2)-($('.'+this._classe+' #nd_gallery_wrapper').innerHeight()/2) ) )											   
				}, 500, function() {
				}
			);											   
		}
		
	}
	
	function popUpClose(){
		$('#popUp_wrapper').fadeOut();
	}
	
	var imageObj = new Image();	
	imageObj.onabort = function() {alert('errore caricamento foto');}
	imageObj.onerror = function() {alert('errore caricamento foto');}
	imageObj.onload = function() {
		if (imageObj.height>(-100+$(window).height())){
			customWidth=((-100+$(window).height())/imageObj.height)*imageObj.width;
			customHeight=-100+$(window).height();
		} else {
			customWidth=imageObj.width;
			customHeight=imageObj.height;
		}
		$('#nd_gallery_wrapper .loader').hide();
		$('#nd_gallery_wrapper #label').html("");
		$('#nd_gallery_wrapper #label2').html("");
		$('#nd_gallery_wrapper').animate({	
			width: customWidth,
			height: customHeight,
			marginTop: (Math.max(5, ( $(window).height()/2)-((imageObj.height+100)/2) ) )
			}, 500, function() {
				$('#nd_gallery_content img').attr('src', imageObj.src).css('height', customHeight).fadeIn('fast');
				$('#nd_gallery_wrapper #label').html($('.active a').attr('title'));
				$('#nd_gallery_wrapper #label2').html($('.active a').attr('alt'));
			}
		);
	}
	
	$(document).ready(
		function(){
			nd_gallery = new lightRoom_class('body', 'galleryFoto', 'nd_gallery', './class/lightroom/');
		}
	);
	
	$(window).load(
		function(){
			nd_gallery.playFirst();
		}
	);
