/* 
 This code creates some layers (overlay, lightbox, etc.) to show images,
 while fading the document viewport.
 
 Code was built upon Lightbox JS, with many modifications by
 Joao Rodrigues for www.atbt.org.br - Jan2009.
 $version 0.3 - 2009-03-30
 
 Inspired by the work of John Resig (jspro.org/files/code/09.zip),
 Peter-Paul Koch (quirksmode.org) and Lokesh Dhakar, creator of
 Lightbox JS: Fullsize Image Overlays 
 - http://huddletogether.com/projects/lightbox 

 Dependencies: atbt102_p.js; lightbox.css; ajax_circle1.gif; and close_20x20.gif

*/
function jrBoxObject(){this.init();}
jrBoxObject.prototype={images:{"loadingImage":"images/design/ajax_circle1.gif","closeButtonImage":"images/design/close_20x20.gif"},elements:{},createElements:function(){var $parentNode=document.getElementsByTagName("body").item(0),$newDiv,$linkTag,els=this.elements;($newDiv=document.createElement("div")).setAttribute('id',"overlay");($linkTag=document.createElement("a")).href="#";$linkTag.setAttribute("title","Clique aqui para cancelar");$linkTag.onclick=function(){jrShowDivLayer.hideLayers();return false;};(els.imgLoadingImage=document.createElement("img")).setAttribute("id","loadingImage");els.imgLoadingImage.src=this.images.loadingImage;$linkTag.appendChild(els.imgLoadingImage);$newDiv.appendChild($linkTag);$parentNode.appendChild($newDiv);els.divOverLay=$newDiv;($newDiv=document.createElement("div")).setAttribute('id',"lightbox");($linkTag=document.createElement("a")).href="#";$linkTag.setAttribute("title","Clique na imagem ou tecle X para fechar");$linkTag.onclick=function(){jrShowDivLayer.hideLayers();return false;};(els.imgLightBoxImage=document.createElement("img")).setAttribute("id","lightboxImage");(els.divLightBoxCloseMsg=document.createElement("div")).setAttribute('id','lightboxCloseMsg');els.divLightBoxCloseMsg.innerHTML="Fechar";(els.imgCloseButtonImage=document.createElement("img")).setAttribute("id","closeButtonImage");els.imgCloseButtonImage.src=this.images.closeButtonImage;$linkTag.appendChild(els.imgLightBoxImage);$linkTag.appendChild(els.divLightBoxCloseMsg);$linkTag.appendChild(els.imgCloseButtonImage);$newDiv.appendChild($linkTag);$parentNode.appendChild($newDiv);els.divLightBox=$newDiv;(els.divLightBoxDetails=document.createElement("div")).setAttribute('id','lightboxDetails');(els.divLightBoxCaption=document.createElement("div")).setAttribute('id','lightboxCaption');els.divLightBoxDetails.appendChild(els.divLightBoxCaption);els.divLightBox.appendChild(els.divLightBoxDetails);this.divsCreated=(els.divOverLay&&els.divLightBox&&els.divLightBoxDetails&&els.divLightBoxCaption&&els.divLightBoxCloseMsg);},divsCreated:false,getKey:function(evt){var keynum=(window.event)?event.keyCode:evt.which;var key=String.fromCharCode(keynum).toLowerCase();if(key=='x'){jrShowDivLayer.hideLayers();}},getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=document.body.scrollWidth;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=windowWidth;}else{pageWidth=xScroll;}
return new Array(pageWidth,pageHeight,windowWidth,windowHeight);},getPageScroll:function(){var yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;}else if(document.body){yScroll=document.body.scrollTop;}
return new Array('',yScroll);},hideLayers:function(){this.elements.divOverLay.style.display="none";this.elements.divLightBox.style.display="none";selects=document.getElementsByTagName("select");for(var i=0;i!=selects.length;i++){selects[i].style.visibility="visible";}
document.onkeypress='';},init:function(){var i,$link,$links=document.links,$linksHRef=[];for(i=0;i<$links.length;i++){$link=$links[i];if($link.href&&$link.rel=="lightbox"){$linksHRef.push($link.href);$link.onclick=function(){jrShowDivLayer.showLayers(this);return false;};}}
this.preloadImages($linksHRef);this.createElements();},listenKey:function(){document.onkeypress=jrShowDivLayer.getKey;},pause:function(numberMillis){var now=new Date();var exitTime=now.getTime()+numberMillis;while(true){now=new Date();if(now.getTime()>exitTime){return;}}},preloadImages:function(){var $imgArray=[],$imgPreloader=new Image();for(var i=0,a=arguments;i<a.length;i++){$imgPreloader.src=a[i];$imgArray.push($imgPreloader);}},showLayers:function(varLink){if(!this.divsCreated){return;}
var $arrayPageSize=this.getPageSize(),$arrayPageScroll=this.getPageScroll(),$imgLoadingImage=this.elements.imgLoadingImage;if($imgLoadingImage){$imgLoadingImage.style.top=($arrayPageScroll[1]+(($arrayPageSize[3]-35-$imgLoadingImage.height)/2)+'px');$imgLoadingImage.style.left=((($arrayPageSize[0]-20-$imgLoadingImage.width)/2)+'px');$imgLoadingImage.style.display='block';}
this.elements.divOverLay.style.height=($arrayPageSize[1]+'px');this.elements.divOverLay.style.display='block';var that=this;var imgPreload=new Image();imgPreload.onload=function(){that.elements.imgLightBoxImage.src=varLink.href;var lightboxTop=$arrayPageScroll[1]+(($arrayPageSize[3]-35-imgPreload.height)/2);var lightboxLeft=(($arrayPageSize[0]-20-imgPreload.width)/2);that.elements.divLightBox.style.top=(lightboxTop<0)?"0px":lightboxTop+"px";that.elements.divLightBox.style.left=(lightboxLeft<0)?"0px":lightboxLeft+"px";that.elements.divLightBoxDetails.style.width=imgPreload.width+'px';if(varLink.getAttribute('title')){that.elements.divLightBoxCaption.style.display='block';that.elements.divLightBoxCaption.innerHTML=varLink.getAttribute('title');}else{that.elements.divLightBoxCaption.style.display='none';}
var isMSIE=false;if(isMSIE){that.pause(250);}
if(that.elements.imgLoadingImage){that.elements.imgLoadingImage.style.display='none';}
selects=document.getElementsByTagName("select");for(var i=0;i!=selects.length;i++){selects[i].style.visibility="hidden";}
that.elements.divLightBox.style.display='block';$arrayPageSize=that.getPageSize();that.elements.divOverLay.style.height=($arrayPageSize[1]+'px');that.listenKey();return false;};imgPreload.src=varLink.href;}};jr$.addLoadEvent(function(){window.jrShowDivLayer=new jrBoxObject();});