var fps=100;
var speed = parseInt(1000/fps);
var step = 5;
var displaceScrollC=0;
var displaceCounter=0;
var tfp=0;
var expandC=0;
var expandCounter=0;
var expandfp=0;
var expandT3C=0;
var expandT3Counter=0;
var expandT3fp=0;
var contractC=0;
var contractCounter=0;
var contractfp=0;
var contractT3C=0;
var contractT3Counter=0;
var contractT3fp=0;

var calcDelay=0;
var translation=0;

var IE6=false;
if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6.0")!=-1){
	IE6=true;
}

function calculatesizesdelay(){
	setTimeout('calculatesizes()',300);
}

var T5sel=new Array();

function calculatesizes(){

	if (IE6){
		a=(document.documentElement.clientHeight-(document.getElementById('header').offsetHeight+document.getElementById('footer').offsetHeight)-40);
	} else {
		var a=(document.body.clientHeight-(document.getElementById('header').clientHeight+document.getElementById('footer').clientHeight)-40);
	}
	
	if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0")!=-1){
		a=a-107;
	}
//	alert("a"+a);
	var ctw=0;
	if (document.getElementById('menucontainer')){
		document.getElementById('menucontainer').style.height=a+"px";
		b=document.getElementById('menucontainer').clientWidth;
//		alert ("largura menu:"+b);
		document.getElementById('menuborder').style.height=(a-12)+"px";
		document.getElementById('menuborder').style.width=(b-22)+"px";
		document.getElementById('menu').style.height=(a-42)+"px";
		document.getElementById('menu').style.width=(b-20)+"px";
		ctw+=b;
	}
	
	if (document.getElementById('contentscontainer')){
		document.getElementById('contentscontainer').style.height=a+"px";
		b=document.getElementById('contentscontainer').clientWidth;
//		alert ("largura contents:"+b);
		document.getElementById('contentsborder').style.height=(a-12)+"px";
		document.getElementById('contentsborder').style.width=(b-18)+"px";
		document.getElementById('contents').style.height=(a-42)+"px";
		document.getElementById('contents').style.width=(b-20)+"px";
		ctw+=b;
	}
	
	if (document.getElementById('selectioncontainer')){
		if (parseInt(document.getElementById('selection').innerHTML.length)>1){
			document.getElementById('selectioncontainer').style.height=a+"px";
			b=document.getElementById('selectioncontainer').clientWidth;
//			alert ("largura selection:"+b);
			document.getElementById('selectionborder').style.height=(a-12)+"px";
			document.getElementById('selectionborder').style.width=(b-18)+"px";
			document.getElementById('selection').style.height=(a-22)+"px";
			document.getElementById('selection').style.width=(b-20)+"px";
			document.getElementById('selectionborder').style.display="block";
			ctw+=b;
		} else{
			document.getElementById('selectionborder').style.display="none";
		}
	}
	
	if (document.getElementById('newscontainer')){
		document.getElementById('newscontainer').style.height=a+"px";
		b=document.getElementById('newscontainer').clientWidth;
//		alert ("largura news:"+b);
		document.getElementById('newsborder').style.height=(a-12)+"px";
		document.getElementById('newsborder').style.width=(b-18)+"px";
		document.getElementById('news').style.height=(a-42)+"px";
		document.getElementById('news').style.width=(b-20)+"px";
		ctw+=b;
	}
	if (document.getElementById('shownewscontainer')){
		document.getElementById('shownewscontainer').style.height=a+"px";
		b=document.getElementById('shownewscontainer').clientWidth;
//		alert ("largura shownews:"+b);
		document.getElementById('shownewsborder').style.height=(a-12)+"px";
		document.getElementById('shownewsborder').style.width=(b-18)+"px";
		document.getElementById('shownews').style.height=(a-22)+"px";
		document.getElementById('shownews').style.width=(b-20)+"px";
		ctw+=b;
	}
	
	if (document.getElementById('contactocontainer')){
		document.getElementById('contactocontainer').style.height=a+"px";
		b=document.getElementById('contactocontainer').clientWidth;
		document.getElementById('contactoborder').style.height=(a-12)+"px";
		document.getElementById('contactoborder').style.width=(b-18)+"px";
		document.getElementById('contacto').style.height=(a-22)+"px";
		document.getElementById('contacto').style.width=(b-20)+"px";
		document.getElementById('ctt').style.marginLeft = parseInt((document.getElementById('contacto').clientWidth-document.getElementById('ctt').clientWidth)/2)+"px";
		ctw+=b;
	}
	
	if (document.getElementById('pdvcontainer')){
		document.getElementById('pdvcontainer').style.height=a+"px";
		b=document.getElementById('pdvcontainer').clientWidth;
		document.getElementById('pdvborder').style.height=(a-12)+"px";
		document.getElementById('pdvborder').style.width=(b-18)+"px";
		document.getElementById('pdv').style.height=(a-22)+"px";
		document.getElementById('clientes').style.height=(a-52)+"px";
		document.getElementById('pdv').style.width=(b-20)+"px";
		ctw+=b;
	}
	//document.getElementById('menucontainer').style.marginLeft = parseInt((document.getElementById('container').clientWidth-ctw)/2)+"px";
}


function T4Pressed(id){	
	if (document.getElementById('ctt_'+id).style.display == 'block') {
		contract('ctt_'+id);
		//document.getElementById('imgT4_'+id).src = '/images/masg.gif';
	} else {
		document.getElementById('ctt_'+id).style.display = 'block';
		//if (checkForTranslation(id)>0)trans=checkForTranslation(id); else trans=0;
		hd=document.getElementById('ctt_'+id).clientHeight;
		document.getElementById('ctt_'+id).style.height = '0px';
		expand('ctt_'+id,hd,0);
		//document.getElementById('imgT4_'+id).src = '/images/menosg.gif';
	}
}

function T1Pressed(id,childrens){
	arrChildren=childrens.split("##");
	toggleCookie(id);
	if (IE6){
		if (document.getElementById('T2_'+id).style.display == 'block') {
			document.getElementById('T2_'+id).style.display = 'none';
		} else {
			document.getElementById('T2_'+id).style.display = 'block'
		}
	} else {	
	if (document.getElementById('T2_'+id).style.display == 'block') {
		contract('T2_'+id);
		document.getElementById('icon_'+id).src = 'http://andremenks.net/flint/images/rightT1.png';
	} else {
			document.getElementById('T2_'+id).style.display = 'block';
			if (checkForTranslation(id)>0)trans=checkForTranslation(id); else trans=0;
			hd=document.getElementById('T2_'+id).clientHeight;
			document.getElementById('T2_'+id).style.height = '0px';
			expand('T2_'+id,hd,trans);
			document.getElementById('icon_'+id).src = 'http://andremenks.net/flint/images/downT1.png';
		}
	}
}

function contract(element){
	clearInterval(contractC);
	contractCounter=document.getElementById(element).clientHeight;
	contractfp=contractCounter;
	eval ('contractC=setInterval("contractAux('+"'"+element+"'"+')",speed)');	
}

function contractAux(element) {
	contractCounter -= step;
	if (contractCounter>=0) {
		document.getElementById(element).style.height = contractCounter+"px";
	} else {
		clearInterval(contractC);
		document.getElementById(element).style.display = 'none';
		document.getElementById(element).style.height=contractfp+"px";
		setCookieScroll();
	}
}

function expand(element,h,tr){
	clearInterval(expandC);
	expandCounter=0;
	expandfp=h;
	translation=tr;
	eval ('expandC=setInterval("expandAux('+"'"+element+"',"+tr+')",speed)');	
}

function expandAux(element,tr) {
	expandCounter += step;	
	if (expandfp>=expandCounter) {
		//alert (document.getElementById(element).offsetTop+"  "+document.getElementById("menu").scrollTop);
		document.getElementById(element).style.height = expandCounter+"px";
		if (document.getElementById(element).offsetTop-document.getElementById("menu").scrollTop<160){
			translation=0;
		}
		if (translation>0) {
			//if (document.getElementById(element).scrollTop>step){
				document.getElementById("menu").scrollTop+=step;
				translation-=step;
				
			//}
		}
	} else {
		document.getElementById(element).style.height = expandfp+"px";
		clearInterval(expandC);
		setCookieScroll();
	}
}

function checkForTranslation(ID){
	yClick=document.getElementById('T2_'+ID).offsetTop;
	hClick=document.getElementById('T2_'+ID).clientHeight;
	yMenu=document.getElementById('menu').offsetTop;
	hMenu=document.getElementById('menu').clientHeight;
	scrollP=document.getElementById("menu").scrollTop;
	//if (hClick>hMenu){
		//r=hMenu-hClick;
	//} else {
		r=yClick-yMenu-hMenu-scrollP+hClick;
		//r=yClick+hClick-hMenu-scrollP;
		//r=800;
	//}
	//alert ("altura do menu "+hMenu+"\n"+"y click "+yClick+"\n y Menu"+yMenu+"\n"+"altura do item"+hClick+"\n"+"scroll position"+scrollP+"\n retorno"+r);
	//alert (document.getElementById("catalogo").offsetTop+"  "+document.getElementById("catalogo").offsetHeight);
	//alert ("r="+r+"\n yc="+yClick);
	if (r<yClick) r=yClick;
	return(r);
}

function checkForTranslationT2(ID){
	yClick=document.getElementById('T3_'+ID).offsetTop;
	hClick=document.getElementById('T3_'+ID).clientHeight;
	yMenu=document.getElementById('menu').offsetTop;
	hMenu=document.getElementById('menu').clientHeight;
	scrollP=document.getElementById("menu").scrollTop;
	//alert ("altura do menu "+hMenu+"\n"+"y click "+yClick+"\n y Menu"+yMenu+"\n"+"altura do item"+hClick+"\n"+"scroll position"+scrollP+"\n retorno"+(yClick-yMenu-hMenu-scrollP+hClick));
	return(yClick-yMenu-hMenu-scrollP+hClick);
}

function T2Pressed(id,parentID) {
	if (IE6){
		if (document.getElementById('T3_'+id).style.display == 'block') {
			document.getElementById('T3_'+id).style.display = 'none';
		} else {
			document.getElementById('T3_'+id).style.display = 'block'
		}
	} else {
	if (document.getElementById('T3_'+id).style.display == 'block') {
		//alert(parentID);
		contractT3('T3_'+id,parentID);
		//document.getElementById('T3_'+id).style.display = 'none';
		//document.getElementById('imgT4_'+id).src = '/images/masg.gif';
	} else {
			document.getElementById('T3_'+id).style.display = 'block';
			if (checkForTranslationT2(id)>0)trans=checkForTranslationT2(id); else trans=0;
			hd=document.getElementById('T3_'+id).clientHeight;
			document.getElementById('T3_'+id).style.height = '0px';
			expandT3("T3_"+id,hd,trans,parentID);		
		
	//		document.getElementById('T3_'+id).style.display = 'block';
			//document.getElementById('imgT4_'+id).src = '/images/menosg.gif';
		}
	}
}

function contractT3(element,parentID){
	clearInterval(contractT3C);
	contractT3Counter=document.getElementById(element).clientHeight;
	contractT3fp=contractT3Counter;
	prt="T2_"+parentID.toString();
	//alert(parentID);
	eval ('contractT3C=setInterval("contractT3Aux('+"'"+element+"'"+','+"'"+prt+"'"+')",speed)');	
}

function contractT3Aux(element,parent) {
	//alert (parent);
	contractT3Counter -= step;
	if (contractT3Counter>=0) {
		document.getElementById(element).style.height = contractT3Counter+"px";
		ht2=document.getElementById(parent).clientHeight - step;
		document.getElementById(parent).style.height = ht2+"px";
	} else {
		clearInterval(contractT3C);
		document.getElementById(element).style.display = 'none';
		document.getElementById(element).style.height=contractT3fp+"px";
		setCookieScroll();
	}
}

function expandT3(element,h,tr,parentID){
	clearInterval(expandT3C);
	expandT3Counter=0;
	expandT3fp=h;
	prt="T2_"+parentID.toString();
	eval ('expandT3C=setInterval("expandT3Aux('+"'"+element+"',"+tr+','+"'"+prt+"'"+')",speed)');	
}

function expandT3Aux(element,tr,parente) {
	expandT3Counter += step;	
	if (expandT3fp>=expandT3Counter) {
		document.getElementById(element).style.height = expandT3Counter+"px";
		ht2=document.getElementById(parente).clientHeight + step;
		document.getElementById(parente).style.height = ht2+"px";
		if (tr>0) {
			document.getElementById("menu").scrollTop+=step;
			tr-=step;
		}
	} else {
		document.getElementById(element).style.height = expandT3fp+"px";
		clearInterval(expandT3C);
		setCookieScroll();
	}
}

function toggleT3(id) {
	toggleCookie(id);
	setCookieScroll();
	if (document.getElementById('T3_'+id).style.display == 'block') {
		document.getElementById('T3_'+id).style.display = 'none';
		//document.getElementById('imgT4_'+id).src = '/images/masg.gif';
	} else {
		document.getElementById('T3_'+id).style.display = 'block';
		//document.getElementById('imgT4_'+id).src = '/images/menosg.gif';
	}
}

function setCookieScroll(){
	//alert("set "+document.getElementById("menu").scrollTop);
	createCookie("menuScroll",document.getElementById("menu").scrollTop);
}

function setScroll(sc){
	//alert("read"+sc);
	document.getElementById("menu").scrollTop=sc;
	//alert(document.getElementById("menu").scrollTop);
}


function toggleCookie(id){
	idc = "."+id+".";
	var dataIDs = readCookie("ids");
	if (dataIDs==null){
		createCookie("ids",idc+"#");
	} else {
		if (dataIDs.indexOf(idc)!=-1){
			var ck=remove (idc,dataIDs);
		} else {
			var ck=insert (idc,dataIDs);
		}
		createCookie("ids",ck);
	}

}
function remove(val,str){
	return str.substring(0,str.indexOf(val))+str.substring(str.indexOf(val)+val.length+1,str.length);
}

function insert(val,str){
	return str+val+"#";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value) {
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setSel2(id){
	document.getElementById('sel2_'+id).className = "selecionadoT2";
}

function setSel1(id){
	document.getElementById('sel1_'+id).className = "selecionadoT1";
}

function moveToSel(id,tit){
	if (id in oc(T5sel)){
		//alert ("j‡ incluso");
	} else {
		T5sel.push(id);
		tit=tit.replace(/##/,'"');
		tit=tit.replace(/##/,'"');
		newCtt="<div id='sel_"+id+"' ><div style='float:left;'></div><div class='MenuCtt'><div style='float: left;margin-left:16px;'>"+tit+"</div><div class='MenuSel'><a class='MenuT4' onclick='removeSel("+id+")' href='javascript:void(0)'><img src='http://andremenks.net/flint/images/cerrar.png' style='margin-top:2px;'/></a></div></div><div style='clear:both;'>";
		newCtt+=document.getElementById('cttd_'+id).innerHTML+"</div></div>"+document.getElementById('selection').innerHTML;
		document.getElementById('selection').innerHTML=newCtt;
		document.getElementById('tx_'+id).style.backgroundColor="#8EADD7";
		document.getElementById('tx_'+id).style.color="#ffffff";
		
	}
	calculatesizes();
	
}

function removeSel(id){
	document.getElementById('sel_'+id).innerHTML="";
	T5sel.remove(id);
	document.getElementById('tx_'+id).style.backgroundColor="#ffffff";
	document.getElementById('tx_'+id).style.color="#8EADD7";
	if (T5sel.length==0){
		document.getElementById('selection').innerHTML="";
	}
	calculatesizes();
}

function setLayerHTML(LAYEROBJ,STR) {
	var dyn = (document.all || document.layers || document.getElementById) ? true : false;
	   if (navigator.userAgent.indexOf('MSIE 5.0') && navigator.userAgent.indexOf('Mac') != -1) STR += '\n';
	   if (dyn) LAYEROBJ.innerHTML = STR;
}

function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

Array.prototype.remove=function(s){
	for(i=0;i<this.length;i++){
		if(s==this[i]) this.splice(i, 1);
	}
}

function dumpProps(obj, parent) {
	   // Go through all the properties of the passed-in object
	   for (var i in obj) {
	      // if a parent (2nd parameter) was passed in, then use that to
	      // build the message. Message includes i (the object's property name)
	      // then the object's property value on a new line
	      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
	      // Display the message. If the user clicks "OK", then continue. If they
	      // click "CANCEL" then quit this level of recursion
	      if (!confirm(msg)) { return; }
	      // If this property (i) is an object, then recursively process the object
	      if (typeof obj[i] == "object") {
	         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
	      }
	   }
	}

function expandListaDist(){
	b=document.getElementById('listDist').clientWidth;
	document.getElementById('listDist').style.width=(b+22)+"px";
	
}




