var css = {
	showed: {
		marginLeft:"30px",
		opacity:"1"
	},

	hiding: {
		marginLeft:"0",
		opacity:"0"
	},

	hidden: {
		marginLeft:"100%"
	}
};

var panoramaOpts = {
	viewport_width:850,
	speed:30000
};

var galleriaOpts = {
	history:true,
	clickNext:true,
	insert:'#gallery_image',
	mode_360:true
};

var corte = {
	init: function () {
		$('.ad-gallery').adGallery({
			loader_image: 'img/loader.gif',
			width: 500,
			height: 375,
			display_next_and_prev: true,
			display_back_and_forward: false,
			slideshow: {
				enable: false
			},
			effect: 'slide-hori',
			enable_keyboard_move: false,
			callbacks: {
				init: function () {
					this.preloadImage(0);
					this.preloadImage(1);
				}
			}
		});
		$('.ad-gallery').hide();
		
		$('.tour').panorama(panoramaOpts);
		$('.panorama-viewport').hide();
		
		$('.map').hide();
		
		$('#contents').show();
		
		$("#pages").css(css.hidden);
		$("#localpage").show();

		$("#pages").animate(css.showed, 1500, "swing"/*, function () { $(corte.current).fadeIn(); }*/);
	
		$('.link').bind('click', corte.onClick);
	},

	onClick: function () {
		var name;
		var toShow;

		name = this.name;
		toShow = '#'+name;
		
		$('#pages').animate(css.hiding, 800, "swing");
		
		if (name == "tour")
			corte.showTour();
		else if (name == "gallery")
			corte.showGallery();
		else if (name == "map")
			corte.showMap();
		else {
			corte.hideTour();
			corte.hideGallery();
			corte.hideMap();
			corte.show(toShow);
		}
	},

	pagesHideCbs: {
		onTour: function () {
			$('.page').hide(function () {
				$('.ad-gallery').hide();
				$('.map').hide();
				$('.panorama-viewport').fadeIn();
			});
		},
		
		onGallery: function () {
			$('.page').hide(function () {
				$('.panorama-viewport').hide();
				$('.map').hide();
				$('.ad-thumb-list').attr('style', 'width:9000px');
				$('.ad-gallery').fadeIn();
			});
		},
		
		onMap: function () {
			$('.page').hide(function () {
				$('.panorama-viewport').hide();
				$('.ad-gallery').hide();
				$('.map').html(
					'<iframe width="700" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=via+gardesane+46,+verona&amp;sll=45.450497,10.93425&amp;sspn=0.008972,0.022724&amp;ie=UTF8&amp;hq=&amp;hnear=Via+Gardesane,+46,+37139+Verona,+Veneto&amp;t=h&amp;ll=45.4511,10.93277&amp;spn=0.024085,0.060081&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.it/maps?f=q&amp;source=embed&amp;hl=it&amp;geocode=&amp;q=via+gardesane+46,+verona&amp;sll=45.450497,10.93425&amp;sspn=0.008972,0.022724&amp;ie=UTF8&amp;hq=&amp;hnear=Via+Gardesane,+46,+37139+Verona,+Veneto&amp;t=h&amp;ll=45.4511,10.93277&amp;spn=0.024085,0.060081&amp;z=14" style="color:#0000FF;text-align:left">Visualizzazione ingrandita della mappa</a></small>'+
					'<img src="img/calce.jpg" alt="" />').fadeIn();
			});
		},
		
		onOther: function (toShow) {
			$('.page').hide();
		}
	},

	hideTour: function () {
		$('.panorama-viewport').fadeOut();
	},

	showTour: function () {
		$('#pages').hide(corte.pagesHideCbs.onTour);
	},
	
	showGallery: function () {
		$('#pages').hide(corte.pagesHideCbs.onGallery);
	},
	
	hideGallery: function () {
		$('.ad-gallery').fadeOut();
	},
	
	showMap: function () {
		$('#pages').hide(corte.pagesHideCbs.onMap);
	},
	
	hideMap: function () {
		$('.map').fadeOut();
	},

	show: function (toShow) {
		$('#pages').hide(function (toShow) { corte.pagesHideCbs.onOther(toShow); });
		$('#pages').show(function () {
			/* TODO: do this without an inline funcion */
			$(toShow).show();
		});

		$('#pages').animate(css.showed, 1000, "swing");
	}
};

$(document).ready(function () { setTimeout(corte.init, 500) });
