// JavaScript Document
/*
title="Título da Bagaça"
_tipo="swf" 
_tamanho="500,400"  (acrescentar 50 na altura no caso de wmv)
_legenda="Legenda da bagaça"
*/
var ancora = "";
var ancoraSz = "";
var intervFD = "";
var intervBox = "";
var intervCont = "";

window.onload = start;

function start(){
	var ancoras = document.getElementsByTagName("A");
	for(i=0;i<=ancoras.length-1;i++){
		if(ancoras[i].getAttribute("_tipo")){
			ancoras[i].setAttribute("_src",ancoras[i].href);
			ancoras[i].onmousedown = function(){criaPop(this)};
			ancoras[i].href = "javascript:void(0)";
		}
	}
}

function criaPop(anc){
	ancora = anc;
	ancoraSz = anc.getAttribute("_tamanho").split(",");
	criaFundo();
}

function criaFundo(){
	window.scrollTo(0,0);
	var obj = document.createElement("DIV");
	 	obj.setAttribute("id","fd_tela")
		obj.style.position = "absolute";
		obj.style.top = 0;
		obj.style.left = 0;
		obj.style.backgroundColor = "#000000";
		obj.style.opacity = 0.2;
		obj.style.filter = "alpha(opacity=20)";
		obj.style.width = document.body.clientWidth + "px";
		obj.style.height = document.body.clientHeight + "px";
		document.body.appendChild(obj);
		window.onscroll=zeraScroll;
		intervFD = setInterval(function(){alteraAlphaFD(obj); },50);
}

function alteraAlphaFD(obj){
	obj.style.opacity = Number(obj.style.opacity)+0.2;
	obj.style.filter = "alpha(opacity="+Number(obj.style.opacity)*100+")";
	if(Number(obj.style.opacity) == 0.8){
		clearInterval(intervFD);
		setTimeout("criaBox()", 500);
	}
}

function criaBox(){
	var telaSzW = document.body.clientWidth;
	var telaSzH = document.body.clientHeight;
	var obj = document.createElement("DIV");
		obj.setAttribute("id","box_link")
		obj.style.backgroundColor = "#FFFFFF";
		obj.style.width = "10px";
		obj.style.height = "10px";
		obj.style.position = "absolute";
		obj.style.top = (telaSzH/2) - (parseInt(obj.style.height)/2);
		obj.style.left = (telaSzW/2) - (parseInt(obj.style.width)/2);
		document.body.appendChild(obj);
		intervBox = setInterval(function(){alteraBoxW(telaSzW,Number(ancoraSz[0])+20); },50);
}

function alteraBoxW(telaSzW,boxSz){
	var obj = document.getElementById("box_link");
	var dif = parseInt(obj.style.width) - boxSz;
		obj.style.width = (parseInt(obj.style.width) - (dif/2) >= boxSz-1)? boxSz + "px" : parseInt(obj.style.width) - (dif/2) + "px";
		obj.style.left = (telaSzW/2) - (parseInt(obj.style.width)/2);
	if(parseInt(obj.style.width) >= boxSz){
		clearInterval(intervBox);
		setTimeout("intervBoxH()", 500);
	}
}

function intervBoxH(){
	var telaSz = document.body.clientHeight;
	var boxTxts = (ancora.getAttribute("_legenda"))? 60 : 40;
	var finalSz = Number(ancoraSz[1])+boxTxts;
	intervBox = setInterval(function(){alteraBoxH(telaSz,boxTxts,finalSz); },50);
}

function alteraBoxH(telaSz,boxTxts,finalSz){
	var obj = document.getElementById("box_link");
	var dif = parseInt(obj.style.height) - finalSz;
		obj.style.height = (parseInt(obj.style.height) - (dif/2) >= finalSz-1)? finalSz + "px": parseInt(obj.style.height) - (dif/2) + "px";
		obj.style.top = (telaSz/2) - (parseInt(obj.style.height)/2);
	if(parseInt(obj.style.height) >= finalSz){
		clearInterval(intervBox);
		criaContents();
	}
}

function criaContents(){
	criaContainer();
	if(ancora.title)criaTitulo();
	criaBotao();
	criaObj();
	if(ancora.getAttribute("_legenda"))criaLegenda();
	var obj = document.getElementById("box_alpha");
	if(obj!=null)intervBox = setInterval(function(){alteraAlphaBox(obj); },50);//"alteraAlphaBox()",50);
}

function criaContainer(){
	var box = document.getElementById("box_link");
	var boxHSz = (ancora.getAttribute("_legenda"))? Number(ancoraSz[1])+60 : Number(ancoraSz[1])+40;
	var divtt = "<div id=box_container><div id=box_alpha style=\"background-color:#FFFFFF;position:absolute;top:0;left:0;width:"+(Number(ancoraSz[0])+20)+"px;height:"+boxHSz+"px;opacity:1.0;filter:alpha(opacity=100);\"></div></div>"
	box.innerHTML = divtt;
}

function criaTitulo(){
	var box = document.getElementById("box_container");
	var divtt = "<div id=div_tt style=\"margin-top:10px; margin-left:10px; float:left; font-family:Arial,Helvetica; font-size:14px; line-height:16px; font-weight:bold; height:20px\">"+ancora.title+"</div>"
	box.innerHTML += divtt;
}

function criaBotao(){
	var box = document.getElementById("box_container");
	var divtt = "<div id=div_botao style=\"margin-top:10px; margin-right:10px; float:right; clear:right; font-family:Arial,Helvetica; font-size:11px; font-weight:bold; height:20px\"><a href=\"javascript:void(0)\" onclick=\"fechaPop()\" style=\"color:#666\">Fechar</a></div>"
	box.innerHTML += divtt;
}

function criaObj(){
	var box = document.getElementById("box_container");
	if(ancora.getAttribute("_tipo")){
		var _type = _pluginspage = _autostart = _showcontrols = "";
		var _src = " src="+ancora.getAttribute("_src");

		var _tamanho = ancora.getAttribute("_tamanho").split(",");
		var _width = " width="+_tamanho[0];
		var _height = " height="+_tamanho[1];
		
		if(ancora.getAttribute("_tipo") != "img"){
			switch(ancora.getAttribute("_tipo")){
				case "avi","asf","asx","rmi","wav","wax","wma","wmv" :
					_type = " type=application/x-mplayer2";
					_pluginspage = " pluginspace=http://www.microsoft.com/Windows/MediaPlayer/";
					_autostart = " autostart=1";
					_showcontrols = " showcontrols=1";
					break;
				case "mov" :
					_type = " type=video/quicktime";
					_pluginspage = " pluginspace=http://www.apple.com/quicktime/download/";
					_autostart = " AUTOPLAY=true";
					_showcontrols = " CONTROLLER=false";
					break;	
				case "swf" :
					_type = " type=application/x-shockwave-flash";
					_pluginspage = " pluginspace=http://www.macromedia.com/go/getflashplayer wmode=transparent";
					break;
				case "mp3" :
					_autostart = " autostart=true";
					_showcontrols = " hidden=true";
					break;	
			}
			_str = "<div id=div_obj style=\"margin-left:10px;\"><embed"+_src+""+_pluginspage+""+_autostart+""+_showcontrols+""+_width+""+_height+"></embed></div>";
		}else{
			_str = "<div id=div_obj style=\"margin-left:10px;\"><img"+_src+""+_width+""+_height+"></div>";
		}
		box.innerHTML += _str;
	}
}

function criaLegenda(){
	var box = document.getElementById("box_container");
	var divtt = "<div id=div_legenda style=\"margin-left:10px; overflow:hidden; font-family:Arial,Helvetica; font-size:11px; color:#404040; line-height:12px; font-weight:bold; height:20px; padding-top:5px;\">"+ancora.getAttribute("_legenda")+"</div>"
	box.innerHTML += divtt;
}

function fechaPop(){
	var div01 = document.getElementById("box_link");
		if(div01)div01.parentNode.removeChild(div01);
	var div02 = document.getElementById("fd_tela");
		if(div02)div02.parentNode.removeChild(div02);
		window.onscroll="";	
}

function alteraAlphaBox(obj){
	obj.style.opacity = (Number(obj.style.opacity)-0.2 <= 0)? 0 : Number(obj.style.opacity)-0.2;
	obj.style.filter = "alpha(opacity="+Number(obj.style.opacity)*100+")";
	if(Number(obj.style.opacity) <= 0){
		obj.style.display="none";
		clearInterval(intervBox);
	}
}

function zeraScroll(){
	window.scrollTo(0,0); 
}