// ########################################################################################
function returnPos(obj){
	var pos = obj.style.marginLeft;
		pos = pos.replace('px','');
		if(!pos){
			var pos = obj.offsetLeft;
		}
	return pos;
}
function returnHeight(obj){
	var pos = obj.style.height;
		if(pos) pos = pos.replace('px','');
		if(!pos){
			var pos = obj.offsetHeight;
		}
	return pos;
}
function addMovie(obj){
	 var posEnd = obj.posEnd;
 	var posHeight = obj.posHeight;

		var pos = returnPos(obj);
		pos = Number(pos) + Number((posEnd - pos)*0.1);

		if(posEnd<pos) obj.style.marginLeft = Math.floor(pos) + 'px';
		else obj.style.marginLeft = Math.ceil(pos) + 'px';
	
		var valHeight = returnHeight(document.getElementById('pageContent'));
		valHeight = Number(valHeight) + Number((posHeight - valHeight)*0.1) ;
		
		if(posHeight<valHeight) document.getElementById('pageContent').style.height =  Math.floor(valHeight) + 'px';
		else document.getElementById('pageContent').style.height =  Math.ceil(valHeight) + 'px';
		
	if(posEnd == pos && posHeight == valHeight){
		clearInterval(obj.interval);
	}
}
function movie(goTO){
	var goTO = document.getElementById(goTO);
	var obj = goTO.parentNode;
	if(!obj || !goTO) return false;
	
	clearInterval(obj.interval);
	obj.posEnd = - (goTO.offsetLeft);
	obj.posHeight = goTO.offsetHeight;
	obj.interval = setInterval(function(){addMovie(obj);}, 5);
	addMovie(obj);
}

// ########################################################################################
function showHide(field, modeIni){
	if (field.nodeName == "#text") field = field.nextSibling;
	
	if (field.nodeType != 1) var target = document.getElementById(field);
	else target = field;
	if (target){
		if (!target.style.display) target.style.display = modeIni;
		else if (target.style.display == "none") target.style.display = "block";
		else									 target.style.display = "none";
	}
}



function navigation(pos, directText){
	
	var _back = document.getElementById('back');
	var _next = document.getElementById('next');
	_back.style.visibility='hidden';
	_next.style.visibility='hidden';
	if(!array.length) return false;

	if(directText){
		for(var i=0; i<array.length; i++){
			if(directText == array[i]){
				textoPos = i;
				break;
			}
			pos = 1;
		}
	}else{
		textoPos += pos;
		
	}
	
	$("#video-yt").hide();
	
	
	str = array[textoPos].indexOf('.html');
	if(str >= 1) document.location = array[textoPos];
	else if(textoPos<=0){
		_back.style.visibility='hidden';
		_next.style.visibility='visible';
		$("#video-yt").show();
		textoPos = 0;
	}else if(textoPos>=(array.length-1)){
		_back.style.visibility='visible';
		_next.style.visibility='hidden';
		textoPos = array.length-1;
	}else{
		_back.style.visibility='visible';
		_next.style.visibility='visible';
	}
	if(pos) movie(array[textoPos]);
	if(!directText) directText = array[textoPos];

	if(directText =='texto9f')
	{
			
	}
	//alert(-document.body.offsetHeight)
	window.scrollBy(0, -document.body.offsetHeight);
	checkLink(directText);
}

function checkLink(directText){
	var _link = document.getElementsByName(directText+'_link');
	
	if(_link[0]){
		resetCheckList();
		_link[0].parentNode.className='check';
	}
}
function resetCheckList(){
	var subMenu = document.getElementById('subMenu');
		subMenu = subMenu.getElementsByTagName('ul');
		subMenu = subMenu[0];
	var subMenuList = subMenu.getElementsByTagName('li');
	for( var i=0; i<subMenuList.length; i++){
		subMenuList[i].className='';
	}
}


function startNavigation(newArray){
	if(newArray){
		array = newArray;
		textoPos = 0;
	}else{
		array = [];
		textoPos = 0;
	}
	navigation(0);
}


/*== print ==*/
function CheckIsIE() { 
	if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') return true; 
	else return false; 
}
function printImg(url){
	targetPrint.innerHTML='<img src="' + url + '">';
	if (CheckIsIE() == true){ 
		document.frameSys.focus(); 
		document.frameSys.print();
	}else{ 
		window.frames['frameSys'].focus(); 
		window.frames['frameSys'].print(); 
	}
}
function printPopUpText(pagina,nome,w,h,scroll){
   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
   settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
   win = window.open(pagina,nome,settings);
}