<!--
function findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//---------------- Abre PopUp ----------------------
function popup(pTarget,pFeatures) { //v3.0
	//The link(file) is the attribute HREF
	//The parameter 'pTarget' must be the same of attribute TARGET and is the WinName value
	//Features: menubar=[yes|no],scrollbars=[yes|no],width=[value],height=[value],resizable=[0|1]
	newwin = window.open('',pTarget,pFeatures);
}

//---------------- Mostra e Esconde Layers ----------------------
function showHideLayers() { //v6.0
	var i,p,v,obj,args=showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
		obj.display=v; }
}

//---------------- Insere OBJECT (SWF) ----------------------
function writeEmbed(pName, swfFile, swfWidth, swfHeight, flashVars, pWmode, pClass){
	
	var swfversion = "9.0.45.0";
	
	document.write(		   
		'<object'
			+ ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'
			+ ' name="' + pName + '"'
			+ ' id="' + pName + '"'
			+ ' class="' + pClass + '"'
			+ ' width="' + swfWidth +'"'
			+ ' height="' + swfHeight +'">'
			+ '<param name="movie" value="' + swfFile + '">'
			+ '<param name="play" value="true">'
			+ '<param name="loop" value="false">'
			+ '<param name="quality" value="Best">'
			+ '<param name="menu" value="true">'
			+ '<param name="allowScriptAccess" value="always">'
			+ '<param name="FlashVars" value="' + flashVars + '">'
			+ '<param name="wmode" value="' + pWmode + '">'
			+ '<param name="swfversion" value="'+swfversion+'" />'
		
			// This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt.
			+ '<param name="expressinstall" value="../scripts/java/expressInstall.swf" />'
			
			// Next object tag is for non-IE browsers. So hide it from IE using IECC. -->              
			+ '<!--[if !IE]>-->'
			+ '<object type="application/x-shockwave-flash" data="'+swfFile+'" width="'+swfWidth+'" height="'+swfHeight+'">'
			+ '<!--<![endif]-->'
			+ '<param name="movie" value="' + swfFile + '">'
			+ '<param name="play" value="true">'
			+ '<param name="loop" value="false">'
			+ '<param name="quality" value="Best">'
			+ '<param name="menu" value="true">'
			+ '<param name="allowScriptAccess" value="always">'
			+ '<param name="FlashVars" value="' + flashVars + '">'
			+ '<param name="wmode" value="' + pWmode + '">'
			+ '<param name="swfversion" value="'+swfversion+'" />' //versão do flash player
			+ '<param name="expressinstall" value="../scripts/java/expressInstall.swf" />'
			
			// The browser displays the following alternative content for users with Flash Player 6.0 and older.
			+ '<div>'
			+ '  <h4>Esta p&aacute;gina requer uma nova vers&atilde;o mais recente do Adobe Flash Player.</h4>'
			+ '  <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Instalar Flash player" width="112" height="33" style="border:0px" /></a></p>'
			+ '</div>'
			
			+ '<!--[if !IE]>-->'
			+ '</object>'
			+ '<!--<![endif]-->'
		+ '</object>'
				
		+ '<script type="text/javascript">'
		+ '<!--'
		+ 'swfobject.registerObject("'+pName+'");'
		+ '//-->'
		+ '</script>'		
		);
}


/* OLD FLASH INSERT
function writeEmbed(pName, swfFile, swfWidth, swfHeight, flashVars, pWmode, pClass){
	document.write(
		'<OBJECT'
		+ ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'
		+ ' name="' + pName + '"'
		+ ' id="' + pName + '"'
		+ ' class="' + pClass + '"'
		+ ' width="' + swfWidth +'"'
		+ ' height="' + swfHeight +'"'
		+ ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">'
		+ '<PARAM name="movie" value="' + swfFile + '">'
		+ '<PARAM name="play" value="true">'
		+ '<PARAM name="loop" value="false">'
		+ '<PARAM name="quality" value="Best">'
		+ '<PARAM name="menu" value="true">'
		+ '<PARAM name="allowScriptAccess" value="always">'
		+ '<PARAM name="FlashVars" value="' + flashVars + '">'
		+ '<PARAM name="wmode" value="' + pWmode + '">'
		+ '<EMBED'
		+ ' name="' + pName + '"'
		+ ' id="' + pName + '"'
		+ ' src="' + swfFile +'"'
		+ ' width="' + swfWidth +'"'
		+ ' height="' + swfHeight +'"'
		+ ' play="true"'
		+ ' loop="false"'
		+ ' quality="Best"'
		+ ' class="' + pClass +'"'
		+ ' menu="true"'
		+ ' FlashVars="' + flashVars +'"'
		+ ' wmode="' + pWmode + '"'
		+ ' allowScriptAccess="always"' 
		+ ' type="application/x-shockwave-flash"'
		+ ' pluginspage="http://www.macromedia.com/go/getflashplayer"'
		+ '</EMBED>'
		+ '</OBJECT>');
}
*/
//----------	Zoom Foto	----------
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('ZoomLink') > -1) {
			lnks[i].onclick = function() {
				openZoom(this);
				return false;
			}
		}
	}
	var spans = container.getElementsByTagName('div');
	for(var iDiv=0,lend=spans.length;iDiv<lend;iDiv++) {
		if(spans[iDiv].className.indexOf('PhotoDetail') > -1) {
			var divDetail = spans[iDiv];
			container.onmouseover = function() {
				divDetail.style.visibility = 'visible';
				divDetail.style.cursor = 'pointer';
				return false;
			}
			
			container.onmouseout= function() {
				divDetail.style.visibility = 'hidden';
				return false;
			}
		
		}
	}
	
}

function closeZoom(obj) {
	document.body.removeChild(document.getElementById('zoom'));
	document.body.removeChild(document.getElementById('shadow'));
	obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}

function resizeZoom(obj) {
	var largura = obj.width;
	var altura = obj.height;
	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 + 'px';
		if(divDescricao) divDescricao.style.width = largura + 'px';
	} catch(erro) {}
}

function openZoom(obj) {
	//alert(obj);
	var pageSize = getPageSize();
	var codimgAnt = '';
	var codimgPos = '';
	var PrevId = '';
	var NextId = '';
	var source = '';
	var descricao = '';
	var classe = 'abc';
	var spans = obj.parentNode.getElementsByTagName('span');
	for(var i=0,len=spans.length;i<len;i++) {
		if(spans[i].className.indexOf('cod-img-ant') > -1) codimgAnt = spans[i].innerHTML;
		if(spans[i].className.indexOf('cod-img-pos') > -1) codimgPos = spans[i].innerHTML;
		if(spans[i].className.indexOf('source') > -1) source = spans[i].innerHTML;
		if(spans[i].className.indexOf('title') > -1) descricao = spans[i].innerHTML;
	}
	var divContainer = document.createElement('div');
	divContainer.id = 'zoom';
	divContainer.className = 'zoom';
	divContainer.style.height = (pageSize.pageHeight + 'px');
	var divSombra = document.createElement('div');
	divSombra.id = 'shadow';
	divSombra.className = 'shadow';
	divSombra.style.height = (pageSize.pageHeight + 'px');
	document.body.appendChild(divSombra);
	var divZoom = document.createElement('div');
	divZoom.id = 'zoom_' +  classe;
	divZoom.className = 'zoom-photo';
	
	if (codimgAnt != ''){
		var spanImgAnt = document.createElement('a');
		spanImgAnt.id = 'link-ant';
		spanImgAnt.title = 'anterior';
		spanImgAnt.className = 'ico-nav-anterior';
		spanImgAnt.innerHTML = '<span class="hidden">&laquo;</span>';
		spanImgAnt.href = '#';
		PrevId= 'Img'+codimgAnt
		spanImgAnt.onclick = function() {
			//alert(document.getElementById(PrevId));
			navigateZoom(PrevId);
			closeZoom(this);
			return false;
		}
	}
	
	if (codimgPos != ''){
		var spanImgPos = document.createElement('a');
		spanImgPos.id = 'link-post';
		spanImgPos.title = 'posterior';
		spanImgPos.className = 'ico-nav-posterior';
		spanImgPos.innerHTML = '<span class="hidden">&raquo;</span>';
		spanImgPos.href = '#';
		NextId= 'Img'+codimgPos
		spanImgPos.onclick = function() {
			//alert(document.getElementById(NextId));
			navigateZoom(NextId);
			closeZoom(this);
			return false;
		}
	}
	
	var spanFonte = document.createElement('span');
	spanFonte.className = 'source';
	spanFonte.innerHTML = source;
	var imgZoom = document.createElement('img');
	imgZoom.id = 'img_' +  classe;
	imgZoom.className = classe;
	imgZoom.src = obj.href;
	imgZoom.alt = 'Foto';
	var divDescricao = document.createElement('div');
	divDescricao.id = 'desc_' +  classe;
	divDescricao.className = 'title';
	var p = document.createElement('p');
	p.innerHTML = descricao;
	var divFechar = document.createElement('span');
	divFechar.className = 'btnClose';
	var spanFechar = document.createElement('a');
	spanFechar.title = 'fechar';
	spanFechar.innerHTML = 'x';
	spanFechar.href = '#';
	spanFechar.onclick = function() {
		closeZoom(this);
		return false;
	}
	divDescricao.appendChild(imgZoom);
	divFechar.appendChild(spanFechar);
	divDescricao.appendChild(p);
	divZoom.appendChild(divFechar);
	if (codimgAnt != '') divZoom.appendChild(spanImgAnt);
	if (codimgPos != '') divZoom.appendChild(spanImgPos);
	divZoom.appendChild(spanFonte);
	divZoom.appendChild(divDescricao);
	divContainer.appendChild(divZoom);

	document.body.appendChild(divContainer);
	
	if(imgZoom.width && imgZoom.width > 56) {
	 resizeZoom(imgZoom);
	}
	imgZoom.onload = function() {
	  resizeZoom(this);
	  return false;
	}
}

function navigateZoom(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('ZoomLink') > -1) {
			obj = lnks[i];
		}
	}
	//alert(obj);
	openZoom(obj);	
}
//-->
