function getCoordinates(element)
{
	var curleft = curtop = 0;
	var obj = element;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return {
			left:	curleft,
			top:	curtop,
			width:	element.width,
			height:	element.height
		};
	
}

function fadeIn(element, duration)
{
	element.style.opacity = 0.0;
	var effect = new Fx.Styles(element, {duration: duration});
	effect.start({ 'opacity': [0.0, 1.0] });
	element.style.visible = 'visible';
	return effect;
}

// Loads an image and calls the callback when it's done
function preloadImage(image, callback)
{
	var preload    = new Image;
	preload.onload = function() { callback(preload) };
	preload.src    = image;
	return preload;
}

function preloadStop(preload)
{
	preload.onload = null;
	preload.src    = '';
}

function showLargeBlogImage(src, fade, element, full)
{

	// Don't allow the user to click to enlarge the image again
	element.onclick = null;

	var coordinates = getCoordinates(element);
	var image = document.createElement("img");
	
	var parentCoordinates = getCoordinates(element.parentNode);
	
	image.className         = "zoomloading";
	image.style.position 	= "absolute";
	image.style.top 		= (coordinates.top - parentCoordinates.top) + "px";
	image.style.left		= (coordinates.left - parentCoordinates.left) + "px";
	image.style.width       = coordinates.width+"px";
	image.style.height      = coordinates.height+"px";
	image.style.zIndex 		= "1";
	image.style.cursor		= 'wait';
	image.onclick           = null;
	//editado
	image.style.border		="3px solid #abc";
	image.style.padding		="1px";
	image.style.background	="#fff";
	//fim edição
	
	var effect = null;
	
	var showLoading = function(preload)
		{
			image.src = preload.src;
			image.style.visibility   = "hidden";
			element.parentNode.appendChild(image);
			effect = fadeIn(image, 300);
		};
	
	// Set the image for the loading element to be an invisible GIF since otherwise the image
	// displays a "file not found" icon. We need to preload the image as well, since if it's not
	// loaded when we set the src we also get the file not found icon.
	var loadingPreload = preloadImage("plugins/invisible.gif", showLoading);
	
	var zoom = function(preload)
		{
		
			if (effect) {
				effect.stop();
			}
			preloadStop(loadingPreload);
			
			image.style.visible = 'hidden';
			image.style.top = coordinates.top + "px";
			image.style.left = coordinates.left + "px";
			document.body.appendChild(image);
			
			var duration = 500;
			var start_opacity = fade ? 0 : 1;
			
			image.style.opacity = start_opacity;
			image.style.cursor 	= "pointer";
			image.className 	= 'bot_thumbnail_large';
			image.src       	= preload.src;
			image.style.visible = 'visible';
			
			var browser_width  = getBrowserWidth();
			var browser_height = getBrowserHeight();

			var image_width  = Math.min(preload.width, 800);
			var image_height = image_width * preload.height / preload.width;
			
			var topPosition = getViewTop() + Math.max((browser_height - image_height) / 2, 10);
			var leftPosition = ((browser_width/2)-(image_width/2));
			
			// If a fullsize image was specified, create a button that will link to it when we're zoomed.
			var zoomButton = null;
			if (full) {
				zoomButton = document.createElement("a");
			}
			
			var contract = function() {
			
				// Get rid of the zoom button.
				if (zoomButton) {
					document.body.removeChild(zoomButton);
				}
				
				// Don't allow the user to "recontract" while we're contracting.
				image.onclick = null;					
				var contractImage = new Fx.Styles(image,{duration: duration,onComplete: function() {
					document.body.removeChild(image);
					// Re-enable the ability to enlarge the image.
					element.onclick = function() { showLargeBlogImage(src, fade, element, full); };
				}});
				// The browser may have resized and repositioned the element (say if it's centered), so get the current coordinates.
				var coordinates = getCoordinates(element);
				contractImage.start({
					'opacity': [1, start_opacity],				
					'top': [topPosition,coordinates.top],
					'left': [leftPosition,coordinates.left],
					'width': [image_width,coordinates.width],
					'height': [image_height,coordinates.height]
				});
			};	
					
			var enlargeImage = new Fx.Styles(image,{duration: duration,onComplete: function() {
				
				// Contract the image when it's clicked.
				image.onclick = contract
				
				// Setup the zoom button.
				if (zoomButton)
				{
					zoomButton.target		      = '_blank';
					zoomButton.href      		  = full;
					zoomButton.className          = "bot_thumbnail_zoombutton";             
					zoomButton.style.position 	  = "absolute";
					zoomButton.style.top 		  = topPosition + (image_height - 40) + "px";
					zoomButton.style.left		  = leftPosition + (image_width - 40) + "px";
					zoomButton.style.zIndex       = "1";
					zoomButton.style.visibility   = "hidden";
					document.body.appendChild(zoomButton);
					fadeIn(zoomButton, 400);
				}
				
			}});
			enlargeImage.start({
				'opacity': [start_opacity, 1],		
				'top': [coordinates.top,topPosition],
				'left': [coordinates.left,((browser_width/2)-(image_width/2))],
				'width': [coordinates.width,image_width],
				'height': [coordinates.height,image_height]
			});
			
			
		};
	
	// Load the image and when we're done, zoom.
	preloadImage(src, zoom);

}
