
/* - functions.js - */
// http://www.infondazione.it/portal_javascripts/functions.js?original=1
function scrollList(selector,offset,direction){relativeScroll=sign(offset)+'='+Math.abs(offset);if(direction!='down'){$(selector).animate({left:relativeScroll})}
else{$(selector).animate({top:relativeScroll})}}
function sign(number){if(number<0) return '-'
else return '+'}
initiallyVisibles=4;firstElementIndex=0;
function scrollUp(){listToScroll=$(this).siblings('.wraplist').children('ul')[0];selector='.'+$($(listToScroll).parent('div')[0]).attr('class')+' ul';$(selector+' li').removeClass('last');currentScroll=$(listToScroll).scrollTop();if(firstElementIndex>0){firstElementIndex-=1}
offset=$(selector+' li:eq('+firstElementIndex+')').outerHeight();scrollList(selector,offset,'down');return false}
function scrollDown(){listToScroll=$(this).siblings('.wraplist').children('ul')[0];selector='.'+$($(listToScroll).parent('div')[0]).attr('class')+' ul';$(selector+' li').removeClass('last');currentScroll=$(listToScroll).scrollTop();offset=$(selector+' li:eq('+firstElementIndex+')').outerHeight();if(firstElementIndex<$(selector+' li').length-1){firstElementIndex+=1}
scrollList(selector,-offset,'down');return false}
function scrollRight(){listToScroll=$(this).siblings('.wraplist').children('ul')[0];container_id=$(this).parent().attr('id');offset=$($(listToScroll).children()[0]).outerWidth({margin:true});n_elements=$(listToScroll).children().size();if(container_id=='opere-home'){n_elements=(n_elements+2)/2}
currentScroll=parseInt($(listToScroll).css('left'));limitReached=currentScroll<=-(n_elements-3) * offset;if(!limitReached){scrollList(listToScroll,-offset,'right')}
limitReached=currentScroll<=-(n_elements-4) * offset;if(limitReached){$(this).hide()}
$(this).siblings('a.left').show();return false}
function scrollLeft(){listToScroll=$(this).siblings('.wraplist').children('ul')[0];offset=$($(listToScroll).children()[0]).outerWidth({margin:true});n_elements=$(listToScroll).children().size();currentScroll=parseInt($(listToScroll).css('left'));limitReached=currentScroll>=0;if(!limitReached){scrollList(listToScroll,offset,'right')}
limitReached=currentScroll>=-offset;if(limitReached){$(this).hide()}
$(this).siblings('a.right').show();return false;return false}
function addEvents(){arrows=$('.up');if(arrows.length>0){arrows.click(scrollUp)}
arrows=$('.down');if(arrows.length>0){arrows.click(scrollDown)}
$('#libri-home .left, #opere-home .left, #sfoglialibri .left').click(scrollLeft);$('#libri-home .right, #opere-home .right, #sfoglialibri .right').click(scrollRight)}
function swap(img){src=img.src;dotPos=src.lastIndexOf('.');basePath=src.substring(0,dotPos)
ext=src.substring(dotPos)
if(src.lastIndexOf("_ro.")==src.length-7){nuova=basePath.substring(0,basePath.length-3)+ext}
else{nuova=basePath+"_ro"+ext}
img.src=nuova}
function noImgHover(){$('a:has(img)').addClass('nohover');$('#altri li li:has(a)').mouseover(function(){$(this).addClass('hover')})
$('#altri li li:has(a)').click(function(){link=$(this).children('a:eq(0)').attr('href');window.location.href=link})
$('#altri li li:has(a)').mouseout(function(){$(this).removeClass('hover')})}
function showDidascalia(){fotos=$('#page img').each(function(){foto=$(this);alt=foto.attr('alt');klass=foto.attr('class');width=foto.attr('width');if(klass!='nodidas'&&alt!=''&&alt!=undefined&&alt!='Locandina'&&alt!="Scarica l'invito in formato PDF"&&width!=undefined&&width>100){if(klass!=''&&klass!=undefined){klass_name='didas '+klass} else{klass_name='didas'}
foto.wrap('<div class="'+klass_name+'"></div>');foto.removeAttr('class');foto.after(alt)}})}
function alignGalleries(){$('.gallery-large').each(function(){fotos=$(this).find('li');minHeight=0;fotos.each(function(){minHeight=Math.max(minHeight,$(this).height())})
fotos.each(function(){$(this).height(minHeight)})})}
$(document).ready(function(){$("a.right").show();$('#page a').each(function(){url=$(this).attr('href');if(url.indexOf('http')!=-1&&url.indexOf(location.host)==-1){$(this).attr({'rel':'external','title':'Sito esterno, nuova finestra'})}})
$('a[rel=external]').click(function(){new_win=window.open(this.href,'nuova');new_win.focus();return false})
addEvents();noImgHover();showDidascalia();alignGalleries();$('td:empty').html('&nbsp;')})
