	
	$(document).ready(
		function(){
			$(window).resize(
				function(){
					$('#ingrandimento').width($(window).width()).height($(window).height());
				}
			);
		}
	);
	
	function playFoto(url){
		var imageObj = new Image();
		imageObj.src = url;
		imageObj.onabort = function() {alert('onabort');}
		imageObj.onerror = function() {alert('onerror');}
		imageObj.onload = function() {
			$('#ingrandimento_wrapper #loader').hide();
			$('#ingrandimento_wrapper').animate({	
				width: imageObj.width+36,
				height: imageObj.height+36
				}, 500, function() {
					$('#ingrandimento_content').animate({	
						width: imageObj.width,
						height: imageObj.height
						}, 500, function() {
							$("#next").css('top', (imageObj.height/2)+22);
							$("#prev").css('top', (imageObj.height/2)+22);
							$('#ingrandimento_content img').attr('src', imageObj.src).fadeIn('fast');
								
							showCommand();
						}
					);
				}
			);	
		}
	}
	
	function showGallery(){
		$('#ingrandimento').width($(window).width()).height($(window).height()).show();
		return false;
	}
	
	function showCommand(){
		$("#close").show();
	}
	
	function caricaFoto(url){
		$('#ingrandimento_content').width(32).height(1).show();
		$('#ingrandimento_wrapper').width(82).height(32).show();
		$('#ingrandimento_wrapper #loader').show();
		$('#ingrandimento_content img').attr('src', 'img/blank.gif');
		//$('#ingrandimento_content img').hide();
		//$('#myytplayer').hide();
		
		showGallery();
		playFoto(url);
		return false;
	}
	
	$(document).ready(
		function(){
			
			$("#close").click(function () {
				//$("#close").hide();
				$('#ingrandimento').hide();
				return false;
			});
			
			$(".extra .thumbs a").click(function () {
				//$(".active").removeClass('active').prev().addClass('active');
				//$("#next").hide();
				//$("#prev").hide();
				
				caricaFoto($(this).attr('href'));
				return false;
			});
			
			$("#promozione .thumbs a").click(function () {
				//$(".active").removeClass('active').prev().addClass('active');
				//$("#next").hide();
				//$("#prev").hide();
				
				caricaFoto($(this).attr('href'));
				return false;
			});
			
			$(".zoom").click(function () {
				//$(".active").removeClass('active').prev().addClass('active');
				//$("#next").hide();
				//$("#prev").hide();
				
				caricaFoto($(this).attr('href'));
				return false;
			});

		}
	);	
