/* Função GERAL para manipulação de páginas 
autor: Tadeu Rodrigues Arias */

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
 
	return yScroll;
}

function getPageSize(){
	
	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){ // 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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function montarjanela() {
	var qdr = document.getElementById('detalhes');
	qdr.style.visibility = 'visible';
	qdr.style.top = getPageScroll()+(getPageSize()[3] / 2)- 280+'px';
	//if (getPageScroll() < 250) { qdr.style.top = '230px'; }
	qdr.style.left =(getPageSize()[2] / 2) - 400+'px';
	
	window.document.getElementById('close').innerHTML = '<strong><a href="javascript:closeDT();" title="Fechar Amplia&ccedil;&atilde;o">X&nbsp;&nbsp;</a></strong>';
	window.document.getElementById('bar_titulo').innerHTML = 'Imagem ampliada';
	window.document.getElementById('dt_miolo').innerHTML = '<img src="./sistema/load.gif" id="imgbig" name="imgbig" />';
	
	
	var fundo = document.getElementById('black');
	fundo.style.display = 'block';
	fundo.style.position = 'absolute';
	fundo.style.top = '0';
	fundo.style.MozOpacity = '0.9';
	fundo.style.opacity = '0.9';
    fundo.style.filter = 'alpha(opacity=90)';
	fundo.style.width = '100%';
	fundo.style.height = getPageSize()[1]+'px';
	fundo.style.left = '0';
	fundo.style.backgroundColor = '#000';
	fundo.style.visibility = "visible";

return true;
}

function popimg(foto,titulo) {	
	pathfoto = foto;	// url da foto
	if (pathfoto.indexOf('url("') >= 0)
	{
		pathfoto = pathfoto.replace('url("','');
		pathfoto = pathfoto.replace('")','');
	}
	if (pathfoto.indexOf("url('") >= 0)
	{
		pathfoto = pathfoto.replace("url('",'');
		pathfoto = pathfoto.replace("')",'');
	}
	if (pathfoto.indexOf("url(") >= 0)
	{
		pathfoto = pathfoto.replace("url(",'');
		pathfoto = pathfoto.replace(")",'');
	}			
	
		//alert(pathfoto);
	bigfoto = new Image;
		
	bigfoto.onload = function() {
		
		window.document.getElementById('bar_titulo').innerHTML = titulo; //'Imagem ampliada ('+bigfoto.width+'-'+bigfoto.height+')';
		document.getElementById('imgbig').src = bigfoto.src;
		
		if (bigfoto.width > 800 ) { 
			document.getElementById('imgbig').width = 780;
			document.getElementById('detalhes').style.width = '800px';
			document.getElementById('close').style.marginLeft = ((800)-50)+'px';
			document.getElementById('bar_titulo').style.width = (800)-7+'px';			
		}
		else { 
			if (bigfoto.width < 120) {
				document.getElementById('imgbig').width = 780;
				document.getElementById('detalhes').style.width = '800px';
				document.getElementById('close').style.marginLeft = ((800)-50)+'px';
				document.getElementById('bar_titulo').style.width = (800)-7+'px';
			} else {
				document.getElementById('imgbig').width = bigfoto.width; 
				document.getElementById('detalhes').style.width = (bigfoto.width+30)+'px';
				document.getElementById('close').style.marginLeft = ((bigfoto.width+30)-50)+'px';
				document.getElementById('bar_titulo').style.width = (bigfoto.width+30)-7+'px';
			}
		}	
			
	}
	montarjanela();
	bigfoto.src = pathfoto;
	bigfoto.load;
}

function closeDT() {
	window.document.getElementById('detalhes').style.visibility="hidden"; // esconde form foto
	window.document.getElementById('black').style.visibility="hidden"; // esconde fundo preto
	window.document.getElementById('black').style.height = 0;
	document.getElementById('close').innerHTML = '';
	document.getElementById('dt_miolo').innerHTML = '';
	document.getElementById('bar_titulo').innerHTML = '';
	bigfoto.src = './sistema/load.gif';
	document.getElementById('detalhes').style.height = null;
}


