rootElement=("onorientationchange" in window)?$(document):$(window);position=1;function init(){$("#gal-prev, #gal-next").remove();$("#gal-thumbs").css("left",0);if($("#gal-thumbs li").size()>5){$left=$("#gal-thumbs li").width()+10;$("#gal-thumbs").css("width",$("#gal-thumbs li").size()*($("#gal-thumbs li").width()+10));$totalWidth=$("#gal-thumbs").width();$btn_prev=$('<a id="gal-prev" title="Precedenti"></a>').appendTo("#gal-thumbs-container").css({visibility:"hidden"}).click(showPrev);$btn_next=$('<a id="gal-next" title="Successive"></a>').appendTo("#gal-thumbs-container").css({visibility:"visible"}).click(showNext)}}function showPrev(){$galleryLeft=$("#gal-thumbs").position().left;$shift=$galleryLeft+($left*5);if($galleryLeft<0){$("#gal-thumbs").animate({left:$shift},300,function(){$btn_next.css("visibility","visible");if($shift==0){$btn_prev.css("visibility","hidden")}})}}function showNext(){$shift=$("#gal-thumbs").position().left-($left*5);if(Math.abs($shift)<$totalWidth){$("#gal-thumbs").animate({left:$shift},300,function(){$btn_prev.css("visibility","visible");if(($totalWidth-Math.abs($shift))<=($left*5)){$btn_next.css("visibility","hidden")}})}}function loading(){if(position==12){$("#loading").css("background-position","0 0");position=1}else{$("#loading").css("background-position","0 "+-position*40+"px");position++}}function loadImage(obj){if(typeof timer!="undefined"){clearInterval(timer)}$("#loading").remove();$to_remove=$("#backstretch img");$('<div id="loading" />').css({position:"absolute",top:(($(window).height()-120)/2)-20,left:($(window).width()/2)-20,width:40,height:40,backgroundImage:"url('/assets/i/loading.png')",zIndex:2}).appendTo("#backstretch");position=1;timer=setInterval("loading()",100);img=$('<img class="gal-current" />').css({position:"absolute",top:0,left:0,opacity:0}).bind("load",function(e){$("#loading").css("z-index","0").remove();clearTimeout(timer);var self=$(this);imgRatio=$(e.target).width()/$(e.target).height();obj.parent().siblings().find("a").removeClass("active");obj.addClass("active");_adjustBG(function(){self.animate({opacity:1},500,function(){self.css("position","relative");self.removeClass("gal-current");$to_remove.remove();if(typeof callback=="function"){callback()}})})}).appendTo($("#backstretch"));img.attr("src",obj.attr("href"));$(window).resize(_adjustBG)}function _adjustBG(fn){try{bgCSS={left:0,top:0};bgWidth=rootElement.width();bgHeight=bgWidth/imgRatio;if(bgHeight>=rootElement.height()){bgOffset=(bgHeight-rootElement.height())/2}else{bgHeight=rootElement.height();bgWidth=bgHeight*imgRatio;bgOffset=(bgWidth-rootElement.width())/2;bgCSS={left:"-"+bgOffset+"px"}}if($("#backstretch img.gal-current").length){$("#backstretch img.gal-current").width(bgWidth).height(bgHeight).css(bgCSS)}else{$("#backstretch img").width(bgWidth).height(bgHeight).css(bgCSS)}}catch(err){}if(typeof fn=="function"){fn()}}function startSlideshow(){$("#gal-slideshow").unbind("click").css("cursor","default");$("#gallery-container").animate({bottom:-100},1000);$('<div id="fs-gallery-console"><img src="/assets/i/gal-pause-fs.png" alt="Pause" /></div>').appendTo($("body"));$("#fs-gallery-console img").css("cursor","pointer").unbind("click").bind("click",function(evt){stopFsSlideshow();$("#fs-gallery-console img").attr("src","/assets/i/gal-play-fs.png").attr("alt","Play").css("cursor","pointer")});$("#hideall").find("img").remove();$('<img src="/assets/i/fullscreen-off.png" alt="Toggle">').appendTo($("#hideall"));$("#hideall").unbind("click").click(function(){stopSlideshow();$("#fs-gallery-console").remove()});startImgLoop();slidetimer=setInterval("startImgLoop()",5000)}function startFsSlideshow(){startImgLoop();slidetimer=setInterval("startImgLoop()",5000);$("#hideall").find("img").remove();$('<img src="/assets/i/fullscreen-off.png" alt="Toggle">').appendTo($("#hideall"));$("#hideall").unbind("click").click(function(){stopSlideshow();$("#fs-gallery-console").remove()});$("#fs-gallery-console img").css("cursor","pointer").unbind("click").bind("click",function(evt){stopFsSlideshow();$("#fs-gallery-console img").attr("src","/assets/i/gal-play-fs.png").attr("alt","Play").css("cursor","pointer")})}function stopSlideshow(){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}$("#gallery-container").animate({bottom:20},1000);$("#hideall").find("img").remove();$('<img src="/assets/i/fullscreen.png" alt="Toggle">').appendTo($("#hideall"));$("#hideall").unbind("click").click(function(){if($("#gallery-container").css("bottom")=="20px"){$("#gallery-container").animate({bottom:-100},1000);$(this).find("img").remove();$('<img src="/assets/i/fullscreen-off.png" alt="Toggle">').appendTo($(this));$('<div id="fs-gallery-console"><img src="/assets/i/gal-play-fs.png" alt="Pause" /></div>').appendTo($("body"));$("#fs-gallery-console img").css("cursor","pointer").unbind("click").bind("click",function(evt){startFsSlideshow();$("#fs-gallery-console img").attr("src","/assets/i/gal-pause-fs.png").attr("alt","Pause").css("cursor","pointer")})}else{$("#gallery-container").animate({bottom:20},1000);$(this).find("img").remove();$('<img src="/assets/i/fullscreen.png" alt="Toggle">').appendTo($(this));$("#fs-gallery-console").remove()}return false});$("#gal-slideshow").css("cursor","pointer").unbind("click").click(function(){startSlideshow()})}function stopFsSlideshow(){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}$("#fs-gallery-console img").css("cursor","pointer").unbind("click").bind("click",function(evt){startFsSlideshow();$("#fs-gallery-console img").attr("src","/assets/i/gal-pause-fs.png").attr("alt","Pause").css("cursor","pointer")})}function startImgLoop(){var $active=$("#gal-thumbs li a.active").parent();if($active.length==0){$active=$("#gal-thumbs li:last a").parent()}var $next=($active.next().length)?$active.next().find("a"):$("#gal-thumbs li:first a");loadImage($next)}$(document).ready(function(){if($("#gal-navigation ul li").size()>0&&$("#gal-navigation ul li.active").length==0){$("#gal-navigation ul li:first").addClass("active")}$("a.gallery").unbind("click").click(function(){$("#hideall").unbind("click").bind("click",function(){if($("#gallery-container").css("bottom")=="20px"){$("#gallery-container").animate({bottom:-100},1000);$(this).find("img").remove();$('<img src="/assets/i/fullscreen-off.png" alt="Toggle">').appendTo($(this))}else{$("#gallery-container").animate({bottom:20},1000);$(this).find("img").remove();$('<img src="/assets/i/fullscreen.png" alt="Toggle">').appendTo($(this))}return false});$("#gallery-container").animate({bottom:20},1000);$("#navigation").animate({left:-300},1000);$("#booking").animate({right:-300},1000);$("#panel *").animate({opacity:0},1000);$("#panel").animate({opacity:0},1000);return false});$("a#gal-close").unbind("click").click(function(){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}if($("#page-gallery-container").length>0){$("#viewpagegallery").animate({opacity:1},1000)}$("#hideall").unbind("click").bind("click",function(){if($("#navigation").css("left")=="12px"){$("#navigation").animate({left:-300},1000);$("#booking").animate({right:-300},1000);$("#panel *").animate({opacity:0},1000);$("#panel, #viewpagegallery").animate({opacity:0},1000,function(){$("#viewpagegallery").hide()});$(this).find("img").remove();$('<img src="/assets/i/fullscreen-off.png" alt="Toggle">').appendTo($(this))}else{$("#navigation").animate({left:12},1000);$("#booking").animate({right:12},1000);$("#panel *").animate({opacity:1},1000);$("#panel").animate({opacity:1},1000,function(){if(jQuery.browser.msie){this.style.removeAttribute("filter")}});if($("#page-gallery-container").length>0){$("#viewpagegallery").show();$("#viewpagegallery").animate({opacity:1},1000)}$(this).find("img").remove();$('<img src="/assets/i/fullscreen.png" alt="Toggle">').appendTo($(this))}return false});$("#gallery-container").animate({bottom:-100},1000);$("#navigation").animate({left:12},1000);$("#booking").animate({right:12},1000);$("#panel *").animate({opacity:1},1000);$("#panel").animate({opacity:1},1000,function(){if(jQuery.browser.msie){this.style.removeAttribute("filter")}});return false});$("#gal-navigation a").unbind("click").click(function(){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}separator=$(this).attr("id").indexOf("-")+1;gal_id=$(this).attr("id").substring(separator);clicked=$(this);$.ajax({url:"/ajax-backend/get-main-gallery.html?id="+gal_id,dataType:"html",success:function(data,textStatus,xhr){$("#gal-thumbs-container").animate({opacity:0},500,function(){$("#gal-thumbs").html(data);$("#gal-thumbs a").click(function(evt){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}loadImage($(this));evt.stopPropagation();return false});init();$("#gal-thumbs img").load(function(){$("#gal-thumbs-container").animate({opacity:1},500,function(){clicked.parent().siblings().removeClass("active");clicked.parent().addClass("active")})})})}});return false});$("#gal-thumbs a").unbind("click").click(function(evt){if(typeof slidetimer!="undefined"){clearInterval(slidetimer)}loadImage($(this));evt.stopPropagation();return false});$("#gal-slideshow").unbind("click").click(function(evt){startSlideshow();evt.stopPropagation();return false});init()});
