
if('undefined'===typeof Alo_Objects){var Alo_Objects=[];}
function Alo_PhotoAlbum(container,config){this.id=Alo_Objects.length;var self=Alo_Objects[this.id]=this;this.ref="Alo_Objects["+this.id+"]";if("string"===typeof container){this.e=document.getElementById(container);}else{this.e=container;}
this.selectedIndex=null;this.view=null;this.debugDiv=null;this.listeners=[];this.config=config;this.width=config['width'];this.height=config['height'];this.itemCount=config['itemCount'];this.addListener=function(obj){this.listeners[this.listeners.length]=obj;}
this.alert=function(message){if(this.debugDiv){this.debugDiv.innerHTML=message;}}
this.setView=function(view){var oldValue=this.view;if(view===oldValue)return false;this.raiseEvent('beforeSetView',view,oldValue);this.view=view;this.raiseEvent('afterSetView',view,oldValue);return false;}
this.next=function(){return this.playItem(this.selectedIndex+1);}
this.prev=function(){return this.playItem(this.selectedIndex-1);}
this.playItem=function(index){var oldValue=this.selectedIndex;if(index<0)index=this.itemCount-1;if(index>=this.itemCount)index=0;if(index===oldValue)return false;this.raiseEvent('beforePlayItem',index,oldValue);this.selectedIndex=index;this.raiseEvent('afterPlayItem',index,oldValue);return false;}
this.raiseEvent=function(eventName,newValue,oldValue){for(var i=0;i<this.listeners.length;i++){var obj=this.listeners[i];if("undefined"!==typeof obj[eventName]){obj[eventName](newValue,oldValue);}}}
var col=this.e.getElementsByTagName("*");var i=0;var node;while(node=col[i++]){switch(node.className){case'PhotoAlbumToolbar':break;case'PhotoAlbumToolbarView0':node.onclick=function(){return self.setView(0);}
break;case'PhotoAlbumToolbarView1':node.onclick=function(){return self.setView(1);}
break;case'PhotoAlbumToolbarView2':node.onclick=function(){return self.setView(2);}
break;case'PhotoAlbumToolbarPrev':self.addListener(node);node.afterSetView=function(index){this.style.display=(0===index)?'none':'inline';}
node.onclick=function(){self.prev();return self.setView(2);}
break;case'PhotoAlbumToolbarNext':self.addListener(node);node.afterSetView=function(view){this.style.display=(0===view)?'none':'inline';}
node.onclick=function(){self.next();return self.setView(2);}
break;case'PhotoAlbumToolbarLabel':self.addListener(node);node.afterSetView=function(view){this.afterPlayItem(self.selectedIndex);}
node.afterPlayItem=function(index){if(2===self.view){this.innerHTML='foto '+(index+1)+' de '+self.itemCount;}else{this.innerHTML=self.itemCount+" fotos";}}
break;case'PhotoAlbumTabs':node.style.width=self.width+"px";node.style.height=self.height+"px";break;case'PhotoAlbumImagerotator':node.style.width=self.width+"px";node.style.height=self.height+"px";self.addListener(node);node.afterSetView=function(view){this.style.visibility=(0===view)?'visible':'hidden';}
break;case'ObjectImagerotator':node.style.width=self.width+"px";node.style.height=self.height+"px";self.addListener(node);node.afterSetView=function(view){this.style.visibility=(0===view)?'visible':'hidden';}
break;case'PhotoAlbumThumbs':node.style.width=self.width+"px";node.style.height=self.height+"px";node.style.overflow='hidden';self.addListener(node);node.afterSetView=function(view){this.style.display=(1===view)?'block':'none';}
node.afterLoad=function(){if("undefined"!==typeof self.config["thumbs"]){var div=this.appendChild(document.createElement('div'));self.initThumbs(self.config['thumbs'],div);var thumbHeight=self.config['thumbHeight']+self.thumbExtra;var maxHeight=self.config['height'];var height=Math.min(maxHeight,Math.floor(maxHeight/thumbHeight)*thumbHeight);div.style.height=height+"px";div.style.overflow='auto';var y=Math.round((maxHeight-height)/2);div.style.marginTop=y+'px';}}
break;case'PhotoAlbumDebug':this.debugDiv=node;break;case'PhotoAlbumImageDesc':self.addListener(node);node.afterSetView=function(view){this.style.display=(2===view)?'block':'none';this.afterPlayItem(self.selectedIndex);}
node.afterPlayItem=function(index){if((null===index)||("undefined"===typeof self.config.images[index].description))return;while(this.firstChild){this.removeChild(this.firstChild);}
var div=self.config.images[index].description;if("string"===typeof(div)){var html=div;var div=document.createElement('div');div.innerHTML=html;self.config.images[index].description=div;}
this.appendChild(div);}
break;case'PhotoAlbumImage':node.style.width=self.width+"px";node.style.height=self.height+"px";node.style.overflow="hidden";self.addListener(node);node.afterSetView=function(view){this.style.display=(2===view)?'block':'none';this.afterPlayItem(self.selectedIndex);}
node.afterPlayItem=function(index){if((2!==self.view)||(null===index))return;while(this.firstChild){this.removeChild(this.firstChild);}
var img=self.config.images[index];if("undefined"===typeof img.tagName){var imgInfo=img;var img=document.createElement('img');img.src=imgInfo.src;img.originalWidth=imgInfo.width;img.originalHeight=imgInfo.height;img.title=img.alt=imgInfo.alt;img.description=imgInfo.description;self.config.images[index]=img;}
this.appendChild(img);var zoom=Math.min((self.width/img.originalWidth),(self.height/img.originalHeight));this.clearTimeout();this.showImage(zoom);}
node.clearTimeout=function(){if(this.timerId){window.clearTimeout(this.timerId);this.timerId=0;}}
node.onclick=function(){self.PhotoAlbumImage=this;var targetZoom=Math.min(10,this._zoom*2);targetZoom=Math.round(targetZoom*100)/100;this.clearTimeout();this.timer(targetZoom);}
node.timer=function(targetZoom){this.timerId=0;var zoom=(targetZoom+this._zoom)/2;var z1=Math.round(zoom*10);var z2=Math.round(targetZoom*10);if(z1==z2){this.showImage(targetZoom);}else{this.showImage(zoom);var js=self.ref+'.PhotoAlbumImage.timer('+targetZoom+')';this.timerId=window.setTimeout(js,100);}}
node.showImage=function(zoom){var img=this.firstChild;var cx=Math.round(img.originalWidth*zoom);var cy=Math.round(img.originalHeight*zoom);var x=Math.round((self.width-cx)/2);var y=Math.round((self.height-cy)/2);this._zoom=zoom;self.alert("z="+zoom+" size="+cx+" x "+cy+" pos="+x+", "+y+" dim="+img.originalWidth+" x "+img.originalHeight);img.style.display="block";img.width=cx;img.height=cy;img.style.margin=y+"px 0 0 "+x+"px";}
break;case'PhotoAlbumImages':self.config.images=[];var col=node.childNodes;for(var i=0;i<col.length;i++){var div=col[i];var img=div.firstChild;img.originalWidth=img.getAttribute("width",2);img.originalHeight=img.getAttribute("height",2);img.title=img.getAttribute("alt");img.description=img.nextSibling;self.config.images[i]=img;}
break;}}
self.raiseEvent('afterLoad');var view=config['view']|0;self.setView(view);self.playItem(0);}
Alo_PhotoAlbum.prototype.initThumbs=function(thumbs,parentNode){var self=this;var width=this.config['thumbWidth'];var height=this.config['thumbHeight'];this.thumbExtra=4+(2*(3+1));var html="";for(var i=0;i<thumbs.length;i++){var src=thumbs[i];html+='<a href="#" style="display:block; cursor:pointer; margin:0 4px 4px 0; float:left; padding:3px; border:1px solid #ccc; width:'+width+'px; height:'+height+'px;">'
+'<div style="background: url(\''+src+'\') no-repeat top; width:'+width+'px; height:'+height+'px;"></div>'
+'</a>';}
var div=parentNode.appendChild(document.createElement('div'));div.innerHTML=html;var col=div.childNodes;for(var i=0;i<col.length;i++){var node=col.item(i);node.index=i;node.onclick=function(){self.playItem(this.index);return self.setView(2);}
if("undefined"!==typeof self.config.images[i]){node.title=self.config.images[i].alt;}}}
