function $(s)
{
	return document.getElementById(s);
}

function InitElements2()
{
	var dvBgZoom = document.createElement('div');
	var dvLoad = document.createElement('div');
	var flashLoad;
	var dvZoom = document.createElement('div');
	var dvImage = document.createElement('div');
	var dvImageClose = document.createElement('div');
	var txtClose = document.createElement('span');
	var linkClose = document.createElement('a');
	var dvCaption = document.createElement('div');
	var txtCaption = document.createElement('span');
	var image = new Image();
	var arrPageSize = getPageSize2();
	var arrPageScroll = getPageScroll2();
	
	dvBgZoom.setAttribute('id', 'dvBgZoom');
	dvBgZoom.style.position = 'absolute';
	dvBgZoom.style.width = arrPageSize[0] + 'px';
	dvBgZoom.style.height = arrPageSize[1] + 'px';
	dvBgZoom.style.top = '0px';
	dvBgZoom.style.left = '0px';
	dvBgZoom.style.backgroundColor = '#000000';
	dvBgZoom.style.opacity = 0.3;
	dvBgZoom.style.filter = 'alpha(opacity=30)';
	dvBgZoom.style.visibility = 'hidden';
	
	flashLoad = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	flashLoad += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ';
	flashLoad += 'width="90"  ';
	flashLoad += 'height="30">';
	flashLoad += '<param name="movie" value="/imagens/fla_loading.swf">';
	flashLoad += '<param name="quality" value="high">';
	flashLoad += '<param name="wmode" value="transparent">';
	flashLoad += '<embed src="/imagens/fla_loading.swf" quality="high" ';
	flashLoad += 'pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ';
	flashLoad += 'width="90" height="30" wmode="transparent">';
	flashLoad += '</embed>';
	flashLoad += '</object>';
	
	dvLoad.setAttribute('id', 'dvLoad');
	dvLoad.style.position = 'absolute';
	dvLoad.style.width = '200px';
	dvLoad.style.height = '50px';
	dvLoad.style.top = '50%';
	dvLoad.style.left = '50%';
	dvLoad.style.marginLeft = '-100px';
	dvLoad.style.marginTop = + (arrPageScroll[1] == 0) ? '-25' : (arrPageScroll[1] - 25) + 'px';
	dvLoad.style.textAlign = 'center';
	dvLoad.style.visibility = 'hidden';
	dvLoad.innerHTML = flashLoad;
	
	dvZoom.setAttribute('id', 'dvZoom');
	dvZoom.style.position = 'absolute';
	dvZoom.style.top = '0';
	dvZoom.style.left = '0';
	dvZoom.style.visibility = 'hidden';
	dvZoom.appendChild(dvImage);
	
	txtClose.setAttribute('id', 'txtClose');
	txtClose.style.fontSize = '11px';
	txtClose.style.fontFamily = 'arial';
	txtClose.style.color = '#666666';
	txtClose.innerHTML = '<div style="width:800px;text-align:right;"><img src="/imagens/bt_fechar_floater.gif" border="0" style="margin-bottom:8px;" /></div>';
	
	dvImageClose.style.marginBottom = '3px';
	dvImageClose.style.textAlign = 'right';
	dvImageClose.appendChild(txtClose);
	
	image.setAttribute('id', 'imgZoom');
	image.setAttribute('alt', 'Fechar');
	image.style.display = 'block';
	image.style.border = '0px';
	image.style.visibility = 'hidden';
	
	linkClose.setAttribute('href', 'javascript: void(0)');
	linkClose.appendChild(txtClose);
	linkClose.appendChild(image);

	
	if(navigator.appName.indexOf('Microsoft Internet Explorer') == 0)
		linkClose.attachEvent('onclick', CloseZoom2);
	else
		linkClose.setAttribute('onclick', 'CloseZoom2()');
	
	txtCaption.setAttribute('id', 'txtCaption');
	
	dvCaption.setAttribute('id', 'dvCaption');
	dvCaption.style.width = image.width + 'px';
	dvCaption.style.height = '22px';
	dvCaption.style.paddingTop = '5px';
	dvCaption.style.display = 'none';
	dvCaption.style.fontSize = '11px';
	dvCaption.style.fontFamily = 'arial';
	dvCaption.style.textAlign = 'left';
	dvCaption.appendChild(txtCaption);
	
	dvImage.setAttribute('id', 'dvImage');
	dvImage.style.border = 'solid 15px #FFFFFF';
	//dvImage.style.textAlign = 'right';
	dvImage.style.backgroundColor = '#FFFFFF';
	dvImage.appendChild(dvImageClose);
	dvImage.appendChild(linkClose);
	dvImage.appendChild(dvCaption);
	
	document.body.appendChild(dvBgZoom);
	document.body.appendChild(dvLoad);
	document.body.appendChild(dvZoom);
}

function OpenZoom2(imageUrl, caption)
{
	CloseZoom2();
	InitElements2();
	
	if((caption != null) && (caption != ''))
	{
		$('txtCaption').innerHTML  = caption;
		$('dvCaption').style.display = 'block';
	}
	
	$('dvBgZoom').style.visibility = 'visible';
	$('dvLoad').style.visibility = 'visible';
	
	$('imgZoom').src = imageUrl;
	
	if(navigator.appName.indexOf('Microsoft Internet Explorer') == 0)
		$('imgZoom').onload = new function() { ProcessZoom2(); }
	else
		$('imgZoom').setAttribute('onload', 'ProcessZoom2()');
		
	$('imgZoom').onmouseover = function() { $('txtClose').style.color = '#FF0000'; }
	$('imgZoom').onmouseout = function() { $('txtClose').style.color = '#666666'; }
}

function ProcessZoom2()
{
	var x = parseInt($('imgZoom').width / 2);
	var y = parseInt($('imgZoom').height / 2);
	var arrPageScroll = getPageScroll2();
	
	y = ($('txtCaption').innerHTML == '') ? (y + 15) : (y + 35);
	
	$('dvCaption').style.width = $('imgZoom').width + 'px';
	//$('dvZoom').style.top = '50%';
	$('dvZoom').style.left = '50%';
	$('dvZoom').style.marginLeft = '-415px';
	//$('dvZoom').style.marginTop = (arrPageScroll[1] == 0) ? ('-' + y) : (arrPageScroll[1] - y) + 'px';
	$('dvZoom').style.marginTop = '50px'
	$('dvLoad').style.visibility = 'hidden';
	$('imgZoom').style.visibility = 'visible';
	$('dvZoom').style.visibility = 'visible';
}

function CloseZoom2()
{
	if($('dvBgZoom') != null)
		document.body.removeChild($('dvBgZoom'));
		
	if($('dvZoom') != null)
		document.body.removeChild($('dvZoom'));
}

//
// getPageScroll2()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll2()
{
	var xScroll, yScroll;

	if (self.pageYOffset) 
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} 
	else if (document.documentElement && document.documentElement.scrollTop)
	{	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} 
	else if (document.body) 
	{// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

//
// getPageSize2()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize2()
{
	var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}