/**
* jQuery jESALightbox
* Version 1.0 - 01/03/2009
* @author Davide Pilato (Alias Esagod)
*
* Based on jESALightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/jESALightbox2/)
* Originally written to make use of the Prototype framework, and Script.acalo.us, now altered to use jQuery.
**/

(function($){$.fn.jESALightbox=function(settings){var caller=0;var doresize=true;var imagesArray=[];var setPosition=0;settings=jQuery.extend({animationSpeed:'normal',padding:40,opacity:0.35,showTitle:true,allowresize:true,theme:'light_rounded',onOpen:null,onChange:null,onClose:null,skin:{title:'<div class="jESALb_title"><div class="jESALb_title_left"></div><div class="jESALb_title_content">{0}</div><div class="jESALb_title_right"></div></div>',box:'<div class="jESALb_pic_holder">{0}{1}{2}</div>',top:'<div class="jESALb_top"><div class="jESALb_left"></div><div class="jESALb_middle"></div><div class="jESALb_right"></div></div>',bottom:'<div class="jESALb_bottom"><div class="jESALb_left"></div><div class="jESALb_middle"></div><div class="jESALb_right"></div></div>',content:'<div class="jESALb_content">{0}{1}{2}{3}{4}</div>',cntExpand:'<a href="#" class="jESALb_expand" title="{0}">{1}</a>',cntLoading:'<div class="jESALb_loaderIcon"></div>',cntHover:'<div class="hoverContainer">{0}{1}</div>',cntHoverNext:'<a class="jESALb_next" href="#">{0}</a>',cntHoverPrev:'<a class="jESALb_prev" href="#">{0}</a>',cntImage:'<div id="full_res"><img id="fullResImage" src="" /></div>',cntDetails:'<div class="jESALb_details clearfix">{0}{1}{2}</div>',cntDetailsClose:'<a class="jESALb_close" href="#">{0}</a>',cntDetailsDesc:'<p class="jESALb_description">{0}</p>',cntDetailsNav:'<div class="jESALb_nav">{0}<div class="jESALb_arrow">{1}{2}</div></div>',cntDetailsNavText:'<p class="currentTextHolder">{0}</p>',cntDetailsNavPrev:'<a href="#" class="jESALb_arrow_prev">{0}</a>',cntDetailsNavNext:'<a href="#" class="jESALb_arrow_next">{0}</a>'},text:{title:'{0}',expandTitle:'Espandi',expandLabel:'Espandi immagine',cntHoverNext:'prossima',cntHoverPrev:'precedente',cntDetailsClose:'chiudi',cntDetailsDesc:'<b>Descrizione:</b><br/> {0}',cntDetailsNavText:'Immagine {0} di {1}',cntDetailsNavPrev:'prossima',cntDetailsNavNext:'precedente'}},settings);$(window).scroll(function(){_centerPicture();});$(window).resize(function(){_centerPicture();_resizeOverlay();});$(document).keyup(function(e){switch(e.keyCode){case 37:if(setPosition==1)return;changePicture('previous');break;case 39:if(setPosition==setCount)return;changePicture('next');break;case 27:close();break;};});$(this).each(function(){var hasTitle=false;var isSet=false;var setCount=0;var arrayPosition=0;imagesArray[imagesArray.length]=this;$(this).bind('click',function(){open(this);return false;});});function open(el){caller=$(el);var theRel=$(caller).attr('rel');var galleryRegExp=new RegExp("\\[\#([a-zA-Z0-9_]*)\]","gi");var theArray=galleryRegExp.exec(theRel);if(theArray!=null){theGallery=theArray[1];}else{var name='image_'+(new Date().getTime());$(caller).attr('rel',theRel+'[#'+name+']');theGallery=name;}var themeRegExp=new RegExp("\\[\~([a-zA-Z0-9_]*)\]","gi");var theArray=themeRegExp.exec(theRel);if(theArray!=null){settings.theme=theArray[1];}isSet=false;setCount=0;for(i=0;i<imagesArray.length;i++){if($(imagesArray[i]).attr('rel').indexOf(theGallery)!=-1){setCount++;if(setCount>1)isSet=true;if($(imagesArray[i]).attr('href')==$(el).attr('href')){setPosition=setCount;arrayPosition=i;};};};if(settings.onOpen&&typeof settings.onOpen=="function")settings.onOpen($(el));_buildOverlay(isSet);$('div.jESALb_pic_holder p.currentTextHolder').text(_stringFormat(settings.text.cntDetailsNavText,setPosition,setCount));_centerPicture();$('div.jESALb_pic_holder #full_res').hide();$('.jESALb_loaderIcon').show();_preload();};showimage=function(width,height,containerWidth,containerHeight,contentHeight,contentWidth,resized){$('.jESALb_loaderIcon').hide();var scrollPos=_getScroll();if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth;}else{windowHeight=$(window).height();windowWidth=$(window).width();};$('div.jESALb_pic_holder .jESALb_content').animate({'height':contentHeight,'width':containerWidth},settings.animationSpeed);projectedTop=scrollPos['scrollTop']+((windowHeight/2)-(containerHeight/2));if(projectedTop<0)projectedTop=0+$('div.jESALb_title').height();$('div.jESALb_pic_holder').animate({'top':projectedTop,'left':((windowWidth/2)-(containerWidth/2)),'width':containerWidth},settings.animationSpeed,function(){$('#fullResImage').attr({'width':width,'height':height});$('div.jESALb_pic_holder').width(containerWidth);$('div.jESALb_pic_holder .hoverContainer').height(height).width(width);$('div.jESALb_pic_holder #full_res').fadeIn(settings.animationSpeed);_shownav();if(resized)$('a.jESALb_expand,a.jESALb_contract').fadeIn(settings.animationSpeed);});};function changePicture(direction){if(direction=='previous'){arrayPosition--;setPosition--;}else{arrayPosition++;setPosition++;};if(settings.onChange&&typeof settings.onChange=="function")settings.onChange($(imagesArray[arrayPosition]),direction);if(!doresize)doresize=true;$('div.jESALb_pic_holder .hoverContainer,div.jESALb_pic_holder .jESALb_details').fadeOut(settings.animationSpeed);$('div.jESALb_pic_holder #full_res').fadeOut(settings.animationSpeed,function(){$('.jESALb_loaderIcon').show();_preload();});_hideTitle();$('a.jESALb_expand,a.jESALb_contract').fadeOut(settings.animationSpeed,function(){$(this).removeClass('jESALb_contract').addClass('jESALb_expand');});};function close(){if(settings.onClose&&typeof settings.onClose=='function')settings.onChange();$('div.jESALb_pic_holder,div.jESALb_title').fadeOut(settings.animationSpeed,function(){$('div.jESALb_overlay').fadeOut(settings.animationSpeed,function(){$('div.jESALb_overlay,div.jESALb_pic_holder,div.jESALb_title').remove();if($.browser.msie&&$.browser.version==6){$('select').css('visibility','visible');};});});doresize=true;};function _checkPosition(){if(setPosition==setCount){$('div.jESALb_pic_holder a.jESALb_next').css('visibility','hidden');$('div.jESALb_pic_holder a.jESALb_arrow_next').removeClass('jESALb_arrow_next').addClass('jESALb_arrow_next_disabled').unbind('click');}else{$('div.jESALb_pic_holder a.jESALb_next').css('visibility','visible');$('div.jESALb_pic_holder a.jESALb_arrow_next_disabled').removeClass('jESALb_arrow_next_disabled').addClass('jESALb_arrow_next').bind('click',function(){changePicture('next');return false;});};if(setPosition==1){$('div.jESALb_pic_holder a.jESALb_prev').css('visibility','hidden');$('div.jESALb_pic_holder a.jESALb_arrow_prev').removeClass('jESALb_arrow_prev').addClass('jESALb_arrow_prev_disabled').unbind('click');}else{$('div.jESALb_pic_holder a.jESALb_prev').css('visibility','visible');$('div.jESALb_pic_holder a.jESALb_arrow_prev_disabled').removeClass('jESALb_arrow_prev_disabled').addClass('jESALb_arrow_prev').bind('click',function(){changePicture('previous');return false;});};$('div.jESALb_pic_holder p.currentTextHolder').text(_stringFormat(settings.text.cntDetailsNavText,setPosition,setCount));var $c=(isSet)?$(imagesArray[arrayPosition]):$(caller);if($c.attr('title')){$('div.jESALb_pic_holder .jESALb_description').show().html(_stringFormat(settings.text.cntDetailsDesc,unescape($c.attr('title'))));}else{$('div.jESALb_pic_holder .jESALb_description').hide().text('');};if($c.find('img').attr('title')&&settings.showTitle){$('div.jESALb_title .jESALb_title_content').html(_stringFormat(settings.text.title,unescape($c.find('img').attr('title'))));hasTitle=true;}else{hasTitle=false;};};function _fitToViewport(width,height){hasBeenResized=false;$('div.jESALb_pic_holder .jESALb_details').width(width);$('div.jESALb_pic_holder .jESALb_details p.jESALb_description').width(width-parseFloat($('div.jESALb_pic_holder a.jESALb_close').css('width')));contentHeight=height+parseFloat($('div.jESALb_pic_holder .jESALb_details').height())+parseFloat($('div.jESALb_pic_holder .jESALb_details').css('margin-top'))+parseFloat($('div.jESALb_pic_holder .jESALb_details').css('margin-bottom'));contentWidth=width;containerHeight=height+parseFloat($('div.jESALb_title').height())+parseFloat($('div.jESALb_pic_holder .jESALb_top').height())+parseFloat($('div.jESALb_pic_holder .jESALb_bottom').height());containerWidth=width+settings.padding;imageWidth=width;imageHeight=height;windowHeight=$(window).height();windowWidth=$(window).width();if(((containerWidth>windowWidth)||(containerHeight>windowHeight))&&doresize&&settings.allowresize){hasBeenResized=true;notFitting=true;while(notFitting){if((containerWidth>windowWidth)){imageWidth=(windowWidth-200);imageHeight=(height/width)*imageWidth;}else if((containerHeight>windowHeight)){imageHeight=(windowHeight-200);imageWidth=(width/height)*imageHeight;}else{notFitting=false;};containerHeight=imageHeight;containerWidth=imageWidth;};contentHeight=imageHeight+parseFloat($('div.jESALb_pic_holder .jESALb_details').height())+parseFloat($('div.jESALb_pic_holder .jESALb_details').css('margin-top'))+parseFloat($('div.jESALb_pic_holder .jESALb_details').css('margin-bottom'));contentWidth=imageWidth;containerHeight=imageHeight+parseFloat($('div.jESALb_title').height())+parseFloat($('div.jESALb_pic_holder .jESALb_top').height())+parseFloat($('div.jESALb_pic_holder .jESALb_bottom').height());containerWidth=imageWidth+settings.padding;$('div.jESALb_pic_holder .jESALb_details').width(contentWidth);$('div.jESALb_pic_holder .jESALb_details p.jESALb_description').width(contentWidth-parseFloat($('div.jESALb_pic_holder a.jESALb_close').css('width')));};return{width:imageWidth,height:imageHeight,containerHeight:containerHeight,containerWidth:containerWidth,contentHeight:contentHeight,contentWidth:contentWidth,resized:hasBeenResized};};function _centerPicture(){if($('div.jESALb_pic_holder').size()>0){var scrollPos=_getScroll();if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth;}else{windowHeight=$(window).height();windowWidth=$(window).width();};if(doresize){projectedTop=(windowHeight/2)+scrollPos['scrollTop']-($('div.jESALb_pic_holder').height()/2);if(projectedTop<0)projectedTop=0+$('div.jESALb_title').height();$('div.jESALb_pic_holder').css({'top':projectedTop,'left':(windowWidth/2)+scrollPos['scrollLeft']-($('div.jESALb_pic_holder').width()/2)});$('div.jESALb_title').css({'top':$('div.jESALb_pic_holder').offset().top-$('div.jESALb_title').height(),'left':$('div.jESALb_pic_holder').offset().left+(settings.padding/2)});};};};function _shownav(){if(isSet)$('div.jESALb_pic_holder .hoverContainer').fadeIn(settings.animationSpeed);$('div.jESALb_pic_holder .jESALb_details').fadeIn(settings.animationSpeed);_showTitle();};function _showTitle(){if(settings.showTitle&&hasTitle){$('div.jESALb_title').css({'top':$('div.jESALb_pic_holder').offset().top-22,'left':$('div.jESALb_pic_holder').offset().left+(settings.padding/2),'display':'none'});$('div.jESALb_title div.jESALb_title_content').css('width','auto');if($('div.jESALb_title').width()>$('div.jESALb_pic_holder').width())$('div.jESALb_title div.jESALb_title_content').css('width',$('div.jESALb_pic_holder').width()-(settings.padding*2));else $('div.jESALb_title div.jESALb_title_content').css('width','');$('div.jESALb_title').fadeIn(settings.animationSpeed);};};function _hideTitle(){$('div.jESALb_title').fadeOut(settings.animationSpeed);};function _preload(){_checkPosition();imgPreloader=new Image();nextImage=new Image();if(isSet&&setPosition>setCount)nextImage.src=$(imagesArray[arrayPosition+1]).attr('href');prevImage=new Image();if(isSet&&imagesArray[arrayPosition-1])prevImage.src=$(imagesArray[arrayPosition-1]).attr('href');$('div.jESALb_pic_holder .jESALb_content').css('overflow','hidden');if(isSet)$('div.jESALb_pic_holder #fullResImage').attr('src',$(imagesArray[arrayPosition]).attr('href'));else $('div.jESALb_pic_holder #fullResImage').attr('src',$(caller).attr('href'));imgPreloader.onload=function(){var correctSizes=_fitToViewport(imgPreloader.width,imgPreloader.height);imgPreloader.width=correctSizes['width'];imgPreloader.height=correctSizes['height'];setTimeout('showimage(imgPreloader.width,imgPreloader.height,'+correctSizes["containerWidth"]+','+correctSizes["containerHeight"]+','+correctSizes["contentHeight"]+','+correctSizes["contentWidth"]+','+correctSizes["resized"]+')',500);};(isSet)?imgPreloader.src=$(imagesArray[arrayPosition]).attr('href'):imgPreloader.src=$(caller).attr('href');};function _getScroll(){scrollTop=window.pageYOffset||document.documentElement.scrollTop||0;scrollLeft=window.pageXOffset||document.documentElement.scrollLeft||0;return{scrollTop:scrollTop,scrollLeft:scrollLeft};};function _resizeOverlay(){$('div.jESALb_overlay').css({'height':$(document).height(),'width':$(window).width()});};function _buildOverlay(){backgroundDiv="<div class='jESALb_overlay'></div>";$('body').append(backgroundDiv);$('div.jESALb_overlay').css('height',$(document).height()).bind('click',function(){close();});pictureHolder=_getTemplate('box');titleHolder=_getTemplate('title');$('body').append(pictureHolder).append(titleHolder);$('.jESALb_pic_holder,.titleHolder').css({'opacity':0});$('.jESALb_pic_holder,.jESALb_title').addClass(settings.theme);$('a.jESALb_close').bind('click',function(){close();return false;});$('a.jESALb_expand').bind('click',function(){if($(this).hasClass('jESALb_expand')){$(this).removeClass('jESALb_expand').addClass('jESALb_contract');doresize=false;}else{$(this).removeClass('jESALb_contract').addClass('jESALb_expand');doresize=true;};_hideTitle();$('div.jESALb_pic_holder .hoverContainer,div.jESALb_pic_holder #full_res').fadeOut(settings.animationSpeed);$('div.jESALb_pic_holder .jESALb_details').fadeOut(settings.animationSpeed,function(){_preload();});return false;});$('.jESALb_pic_holder .jESALb_prev,.jESALb_pic_holder .jESALb_arrow_prev').bind('click',function(){changePicture('previous');return false;});$('.jESALb_pic_holder .jESALb_next,.jESALb_pic_holder .jESALb_arrow_next').bind('click',function(){changePicture('next');return false;});$('.hoverContainer').css({'margin-left':settings.padding/2});if(!isSet)$('.hoverContainer,.jESALb_nav').hide();if($.browser.msie&&$.browser.version==6){$('body').addClass('ie6');$('select').css('visibility','hidden');};$('div.jESALb_overlay').css('opacity',0).fadeTo(settings.animationSpeed,settings.opacity,function(){$('div.jESALb_pic_holder').css('opacity',0).fadeIn(settings.animationSpeed,function(){$('div.jESALb_pic_holder').attr('style','left:'+$('div.jESALb_pic_holder').css('left')+';top:'+$('div.jESALb_pic_holder').css('top')+';');});});};function _getTemplate(type){if(type=='box'){var cntExpand=_stringFormat(settings.skin.cntExpand,settings.text.expandTitle,settings.text.expandLabel);var cntHover=_stringFormat(settings.skin.cntHover,_stringFormat(settings.skin.cntHoverNext,settings.text.cntHoverNext),_stringFormat(settings.skin.cntHoverPrev,settings.text.cntHoverPrev));var cntDetailsNav=_stringFormat(settings.skin.cntDetailsNav,_stringFormat(settings.skin.cntDetailsNavText,_stringFormat(settings.text.cntDetailsNavText,0,0)),_stringFormat(settings.skin.cntDetailsNavPrev,settings.text.cntDetailsNavPrev),_stringFormat(settings.skin.cntDetailsNavNext,settings.text.cntDetailsNavNext));var cntDetails=_stringFormat(settings.skin.cntDetails,_stringFormat(settings.skin.cntDetailsClose,settings.text.cntDetailsClose),cntDetailsNav,_stringFormat(settings.skin.cntDetailsDesc,_stringFormat(settings.text.cntDetailsDesc,'')));var skinContent=_stringFormat(settings.skin.content,cntExpand,settings.skin.cntLoading,cntHover,settings.skin.cntImage,cntDetails);return _stringFormat(settings.skin.box,settings.skin.top,skinContent,settings.skin.bottom);}else return _stringFormat(settings.skin.title,_stringFormat(settings.text.title,''));}_stringFormat=String.format||function(B){var A=Array.prototype.slice.call(arguments,1);return B.replace(/\{(\d+)\}/g,function(C,D){return A[D]})};};})(jQuery);//****************************

//****************************
//********* AUTORUN **********
$(document).ready
(
	function()
	{
		$("a[rel^='jESALightbox']").jESALightbox();
	}
);
//****************************