// Sistema de animação estilo Dropbox.

var theBANK = new Array();//array que guarda as divs que serão animadas
var theCounter = 0; //contador do array theBANK
var theFACTOR = 50; // numero de passos na animação
var theINDEX, theHEIGHT, theSIZE, itemp, htemp, stemp, animateTimerId, temp, theTEMP = 0;

function bank(t,n){
	temp = new Array();
	temp = [t,document.getElementById(t).offsetHeight +"px"]; 
	theBANK[theCounter] = temp;
	if(n==0){
		document.getElementById(t).style.height='0px';
		document.getElementById(t).style.opacity='1';
		document.getElementById(t).style.display='none';
	}else{
		document.getElementById(t).style.height=temp[1];
		document.getElementById(t).style.opacity='1';
		document.getElementById(t).style.display='block';
	}
	theCounter++;
}

function teste(param){
	for(var c=0;c<theBANK.length;c++){
		if(theBANK[c][0]==param){
			theINDEX = c;
			if(document.getElementById(theBANK[c][0]).style.height == "0px"){
				document.getElementById(theBANK[c][0]).style.overflow = 'visible';
				document.getElementById(theBANK[c][0]).style.display = 'block';
				theTEMP=document.getElementById(theBANK[c][0]).style.height;
				document.getElementById(theBANK[c][0]).style.height = null;
				theHEIGHT=document.getElementById(theBANK[c][0]).offsetHeight;
				theBANK[c][1]=theHEIGHT+"px";
				document.getElementById(theBANK[c][0]).style.overflow = 'hidden';
				document.getElementById(theBANK[c][0]).style.display = 'none';
				document.getElementById(theBANK[c][0]).style.height = theTEMP;
			}else{
				theHEIGHT = theBANK[c][1].substring(0,theBANK[c][1].indexOf('px'));
			}
		}
	}
	if(document.getElementById(param).style.height=='0px'){
		document.getElementById(param).style.display='block';
		animate(theINDEX,theHEIGHT,1);
	}else{
		animate(theINDEX,theHEIGHT,-1);
	}
}

function animate(i,h,s){
	theSIZE = document.getElementById(theBANK[i][0]).style.height;
	theSIZE = Number(theSIZE.substring(0,theSIZE.indexOf('px')));
	theSIZE = theSIZE + Math.round(h/theFACTOR*s);

	itemp = i;htemp = h;stemp = s;
	if(theSIZE<0){
		theSIZE=0;
	}
	document.getElementById(theBANK[i][0]).style.height = (theSIZE)+"px";
	//document.getElementById('OverlayContainer').style.height = document.height+'px'; //atualizar altura do overlay ao manipular tamanho das fontes
	if(stemp > 0){
		if(theSIZE<h){
			animateTimerId = setTimeout ( "animate(itemp,htemp,stemp)", 500/theFACTOR );
		}else{
			document.getElementById(theBANK[i][0]).style.height = htemp+"px";
			//document.getElementById('OverlayContainer').style.height = document.height+'px'; //atualizar altura do overlay ao manipular tamanho das fontes
			clearTimeout ( animateTimerId );
		}
	}else{
		if(theSIZE>0){
			animateTimerId = setTimeout ( "animate(itemp,htemp,stemp)", 500/theFACTOR );
		}else{
			document.getElementById(theBANK[i][0]).style.height = "0px";
			document.getElementById(theBANK[i][0]).style.display='none';
			//document.getElementById('OverlayContainer').style.height = document.height+'px'; //atualizar altura do overlay ao manipular tamanho das fontes
			clearTimeout ( animateTimerId );
		}
	}
}

/*
 * Funcao padrao para abrir janelas.
 */
function TAU_openBrWindow(theURL,winName,features,largura,altura,f) { //v2.0
  if(f==1){
    l=0;t=0;largura=(screen.availWidth-10);altura=(screen.availHeight-26);
  }else{
    var l = ((screen.availWidth)/2) - (largura/2);
    var t = ((screen.availHeight)/2) - ((altura/2)+20);
  }
  features = features + ",width=" + largura + ",height=" + altura + ",left=" + l + ",top=" + t;
  window.open(theURL,winName,features);
}

function popIt (path, titulo, larg, alt) {
	if (larg == 0){ larg = 200; }
	if (alt == 0){ alt = 200; }
	var estilo='';
	estilo = 'scrollbars = yes, status=no, location=no, menubar=no, toolbar=no, width='+larg+'px, height='+alt+'px';
	window.open(path, titulo, estilo);
}
