
var imv =
{
	et : true, // et = enableTitle - Should "title" attribute of link be used as description?
	ea : true, // ea = enableAnimation - Enable fading animation?
	ft : '<div class="ft">Fechar X</div>', // ft = footer - Define HTML for footer interface
	ld : 'Carregando Imagem...', // ld = loading  Define HTML for "loading" div
	tb : null,
	ti : null,
	tld : null,
	tit : false,

	/////////////No need to edit beyond here/////////////////////////
	tl :[], // tl = targetlinks - Array to hold links with rel="thumbnail"

	ctb : function() // tb = createthumbBox
	{
		//write out HTML for Image Thumbnail Viewer plus loading div
		var bd = utl.get('body')[0];
		//pc = popup container
		pc = document.createElement('div');
		pc.id = 'imv';
		pc.onclick = imv.closeit;
		pc.innerHTML = '<div id="imvi"></div>' + imv.ft;
		bd.appendChild( pc );
		//document.write('<div id="imv" onClick="imv.closeit()"><div id="imvi"></div>'+imv.ft+'</div>')
		ld = document.createElement('div');
		ld.id = 'imvl';
		ld.innerHTML = imv.ld;
		bd.appendChild( ld );		
		//document.write('<div id="imvl">'+imv.ld+'</div>')
		imv.tb = utl.gei("imv") // tb = thumbBox
		imv.ti = utl.gei("imvi") //ti = thumbImage - Reference div that holds the shown image
		imv.tld = utl.gei("imvl") // tld = thumbLoading - Reference "loading" div that will be shown while image is fetched
	},


	cd : function(o) // cd = centerDiv Centers a div element on the page
	{
		utl.cen(o);
		o.style.visibility = "visible";
	},

	st : function() //st = show thumbbox Show ThumbBox div
	{
		imv.cd(imv.tb)
		if (imv.ea) //If fading animation enabled
		{
			var s=20, t=0;
			for(i=0;i<=10;i++) setTimeout('utl.opa(\'imvi\','+i+')',t++ * s);
		}
	},
	li : function(link) //li = load image - Load image function that gets attached to each link on the page with rel="thumbnail"
	{
		if (imv.tb.style.visibility=="visible") //if thumbox is visible on the page already
		imv.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
		var ih = '<img src="'+link.getAttribute("href")+'" style="'+imv.opacitystring+'" />' // ih = imageHTML - Construct HTML for shown image
		if (imv.et && link.getAttribute("title")) //Use title attr of the link as description?
		{
			imv.tit = true;
			ih += '<p id="imvTitle">' + link.getAttribute("title") + '</p>';
		}
		imv.cd(imv.tld) //Center and display "loading" div while we set up the image to be shown
		imv.ti.innerHTML = ih //Populate ti div with shown image's HTML (while still hidden)
		imv.fi = imv.ti.getElementsByTagName("img")[0] //fi = featureImage - Reference shown image itself
		imv.fi.onload = function() //When target image has completely loaded
		{
			imv.tld.style.visibility="hidden" //Hide "loading" div
			imv.st() //Display "thumbbox" div to the world!
			if ( imv.tit )
			{
				utl.gei('imvTitle').style.width = imv.fi.width + 'px';
			}
		}
		if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload 	bug: panoramio.com/blog/onload-event/
		imv.fi.src = link.getAttribute( "href" );
		imv.fi.onerror=function() //If an error has occurred while loading the image to show
		{
			imv.tld.style.visibility = "hidden" //Hide "loading" div, game over
		}
	},


	closeit:function() //Close "thumbbox" div function
	{
		imv.tb.style.visibility="hidden"
		imv.ti.innerHTML=""
		imv.tb.style.left="-6000px"
		imv.tb.style.top="-6000px"
	},

	cleanup:function() //Clean up routine on page unload
	{
		imv.tld=null
		if (imv.fi) imv.fi.onload=null
		imv.fi=null
		imv.ti=null
		for (var i=0; i<imv.tl.length; i++)
			imv.tl[i].onclick=null
		imv.tb=null
	},

	init : function() //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
	{
		var pl=document.getElementsByTagName("a")
		for (var i=0; i<pl.length; i++) //BEGIN FOR LOOP
		{
			if (pl[i].getAttribute("rel") && pl[i].getAttribute("rel")=="thumbnail") //Begin if statement
			{
				pl[i].onclick=function()
				{
					imv.li(this) //Load image
					return false
				}
				imv.tl[imv.tl.length]=pl[i] //store reference to target link
			} //end if statement
		} //END FOR LOOP
		//Reposition "thumbbox" div when page is resized
		utl.ade(window, "resize", function(){if (imv.tb.style.visibility=="visible") imv.cd(imv.tb)})
	} //END init() function
}
if(typeof( window[ 'showImage' ] ) != "undefined")
{
	imv.ctb() //Output HTML for the image thumbnail viewer
	utl.ade(window,"load",function(){imv.init()});
	utl.ade(window,"unload",function(){imv.cleanup()});	
}
