// Largura do box descri??o do Zoom

function larguraBoxZoom()  {
	if (document.getElementById('imgZoom') != null) {
		var largura = document.getElementById('imgZoom').width;	
	}	
	
	if (document.getElementById('fotoZoom')) document.getElementById('descricao').style.width=largura;
}
	
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){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	return arrayPageSize;
}
	
function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
	else if (document.body) yScroll = document.body.scrollTop;
	arrayPageScroll = {yScroll:yScroll};
	return arrayPageScroll;
}
	
function initZoom(div) {
	var container = document.getElementById(div);	
	var lnks = container.getElementsByTagName('a');
	for(var i=0,len=lnks.length;i<len;i++) {
		if(lnks[i].className.indexOf('linkZoom') > -1) {
			lnks[i].onclick =
			function() {
				openZoom(this);
				return false;
			}
		}
	}
}
	
function closeZoom(obj) {

	document.body.removeChild(document.getElementById('sombra'));
	document.body.removeChild(document.getElementById('zoom'));
	
	//document.body.removeChild(document.getElementById(ret.id));
	//obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}	
	
function resizeZoom(obj) {
	var largura = 567;
	var altura = 500;
	var box = obj.parentNode.parentNode;
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	var boxTop = pageScroll.yScroll + ((pageSize.windowHeight - altura - 26) / 2);
	var boxLeft = ((pageSize.pageWidth - largura - 40) / 2);
	box.style.top = (boxTop < 0) ? "0px" : boxTop + "px";
	box.style.left = (boxLeft < 0) ? "0px" : boxLeft + "px";
	box.style.visibility = 'visible';
	try {
			var divZoom = document.getElementById('zoom_'+obj.className);
			var divDescricao = document.getElementById('desc_'+obj.className);
			if(divZoom) divZoom.style.width = largura;
			if(divDescricao) divDescricao.style.width = largura;
		 } catch(erro) {}
}
	
function openZoom(obj, fonte, descricao, num, cd_matia) {
	
	var pageSize = getPageSize();
	var classe = 'abc';
	
	var iframe = document.createElement("iframe");
	iframe.width="547";
	iframe.height="132";
	iframe.frameborder="0";
	iframe.marginheight="0"; 
	iframe.marginwidth="0"; 
	iframe.scrolling="no";
	iframe.style.marginTop="-10px";
	iframe.src = "/includes/paginas/galeria_de_fotos2_trab.php?num="+num+"&cd_matia="+cd_matia;
	
	

	var divContainer = document.createElement('div');
	divContainer.id = 'zoom';
	divContainer.className = 'lvZoom';
	divContainer.style.align = 'center';
	divContainer.style.height = (pageSize.pageHeight + 'px');
			
	var divSombra = document.createElement('div');
	divSombra.id = 'sombra';
	
	if (navigator.appVersion.indexOf("MSIE 7.0") != -1) {
		divSombra.className = 'lvSombraIE7';
	} else {
		divSombra.className = 'lvSombraIE6MOZ';
	}
	
	divSombra.style.height = (pageSize.pageHeight + 'px');
		
	document.body.appendChild(divSombra);
	
	var divZoom = document.createElement('div');
	divZoom.id = 'zoom_' +  classe;
	divZoom.className = 'lvFotoZoom';
	
	var spanFonte = document.createElement('span');
	spanFonte.className = 'fonte';
	spanFonte.innerHTML = fonte;
	spanFonte.id = 'credito';	
		
	var divDescricao = document.createElement('div');
	divDescricao.id = 'desc_' +  classe;
	divDescricao.className = 'descricao';
	
	
	var p = document.createElement('p');
	
	p.appendChild(iframe);
	
	var divFechar = document.createElement('div');
	divFechar.className = 'fechar';
	
	var aFechar = document.createElement('a');
	aFechar.title = 'fechar';
	aFechar.innerHTML = 'fechar';
	aFechar.href = '#';
	aFechar.onclick = 
		function() {
			if (navigator.appVersion.indexOf("MSIE") != -1) {
				try {
					document.getElementById("fivecomlv").Stop();
				} 
				catch (e) {
				
				}
			}
			closeZoom(this);
			return false;
	}
	
	
	divDescricao.appendChild(obj);
	
	divFechar.appendChild(aFechar);
	divDescricao.appendChild(p);
	divZoom.appendChild(divFechar);
	divZoom.appendChild(spanFonte);
	divZoom.appendChild(divDescricao);
	divContainer.appendChild(divZoom);		
	
	document.body.appendChild(divContainer);

	if(obj.width && obj.width > 56) {
		 resizeZoom(obj);
	}
		
	obj.onload = 
		function() {
		 	 resizeZoom(this);
			 return false;
		}	
}
		
window.onload = larguraBoxZoom;


