//script based on a too simple version of Image Thumbnail Viewer Script, for full source script visit:http://www.dynamicdrive.com/
var yacPic={
setTitle: true, //Should "title" attribute of link be used as description?
setheader: '<div class="headerbar">Fechar</div>', //Define HTML for footer interface
setLoadMsg: '<img src="imagens/loading.gif" /> Carregando...',//Define HTML for "loading" div

scrollbarwidth: 16,
targetlinks:[], //Array to hold links with rel="showimgs"

createBoxPic:function(){
//write out HTML for Image showimgs Viewer plus loading div
document.write('<div id="boxpic" onclick="yacPic.fermerpic()">'+this.setheader+'<div id="thePic"></div></div>');
document.write('<div id="msgLoading">'+this.setLoadMsg+'</div>');
this.boxpic=document.getElementById("boxpic");
this.thePic=document.getElementById("thePic"); //Reference div that holds the shown image
this.msgLoading=document.getElementById("msgLoading"); //Reference "loading" div that will be shown while image is fetched
this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
},


centerDiv:function(divobj){ //Centers a div element on the page
var ie=document.all && !window.opera
var dom=document.getElementById
var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
var docwidth=(ie)? this.standardbody.clientWidth : window.innerWidth-this.scrollbarwidth
var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
var objwidth=divobj.offsetWidth //width of div element
var objheight=divobj.offsetHeight //height of div element
var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px" //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
divobj.style.left=docwidth/2-objwidth/2+"px" //Center div element horizontally
divobj.style.top=Math.floor(parseInt(topposition))+"px"
divobj.style.visibility="visible"
},

showboxpic:function(){ //Show boxpic div
this.centerDiv(this.boxpic)
},


loadimage:function(link){ //Load image function that gets attached to each link on the page with rel="showimgs"
if (this.boxpic.style.visibility=="visible") //if thumbox is visible on the page already
this.fermerpic() //Hide it first (not doing so causes triggers some positioning bug in Firefox								
var imageHTML='<img src="'+link.getAttribute("hreflang")+'" style="'+this.opacitystring+'" />' //Construct HTML for shown image
if (this.setTitle && link.getAttribute("title")) //Use title attr of the link as description?
imageHTML+='<p>'+link.getAttribute("title")+'</p>'
this.centerDiv(this.msgLoading) //Center and display "loading" div while we set up the image to be shown
this.thePic.innerHTML=imageHTML //Populate thePic div with shown image's HTML (while still hidden)
this.featureImage=this.thePic.getElementsByTagName("img")[0] //Reference shown image itself
this.featureImage.onload=function(){ //When target image has completely loaded
yacPic.msgLoading.style.visibility="hidden" //Hide "loading" div
yacPic.showboxpic() //Display "boxpic" div to the world!
}	
if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload bug
this.featureImage.src=link.getAttribute("hreflang")
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
yacPic.msgLoading.style.visibility="hidden"//Hide "loading" div, game over
}
},

fermerpic:function(){ //Close "boxpic" div function
this.boxpic.style.visibility="hidden"
this.thePic.innerHTML=""
this.boxpic.style.left="-4000px"
this.boxpic.style.top="-4000px"
},

cleanup:function(){ //Clean up routine on page unload
this.msgLoading=null
if (this.featureImage) this.featureImage.onload=null
this.featureImage=null
this.thePic=null
for (var i=0; i<this.targetlinks.length; i++)
this.targetlinks[i].onclick=null
this.boxpic=null
},

dotask:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener){
target.addEventListener(tasktype, functionref, false);}
else if (target.attachEvent){
target.attachEvent(tasktype, functionref);}
},

init:function(){ //Initialize showimgs viewer script by scanning page and attaching appropriate function to links with rel="showimgs"
var pagelinks=document.getElementsByTagName("a");
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="showimgs"){//Begin if statement
pagelinks[i].onclick=function(){
	if(this.getAttribute("hreflang")==null || this.getAttribute("hreflang")==""){this.setAttribute("hreflang",this.getAttribute("href"));}
yacPic.loadimage(this); //Load image
this.setAttribute("href","javascript:void(0);");
//alert(this.getAttribute("hreflang"));
return false;
}

this.targetlinks[this.targetlinks.length]=pagelinks[i]; //store reference to target link
} //end if statement
} //END FOR LOOP
//Reposition "boxpic" div when page is resized
this.dotask(window, function(){if (yacPic.boxpic.style.visibility=="visible") yacPic.centerDiv(yacPic.boxpic)}, "resize")


} //END init() function

}
yacPic.createBoxPic() //Output HTML for the image showimgs viewer
yacPic.dotask(window, function(){yacPic.init()}, "load") //Initialize script on page load
yacPic.dotask(window, function(){yacPic.cleanup()}, "unload")