var intervalId = "";
var animationSpeed = 1;
var speedDivisor = 4;
var correctionBuffer = 10;
var pending = "";

function init(args) {
	var content = document.getElementById("content");
	
	content.style.top = "-1000px";
	content.style.visibility = "visible";
	
	fill("html/laEmpresa.html");
}

function menu_DoFSCommand(command, args) {
	eval(command + "('" + args + "')");
}

function getSection(section) {
	animateFill("html/" + section + ".html");
}

function findTitle(title) {
	window.location.hash=title;
}

function ajaxObject() {
	var request = null;
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById("content").innerHTML = "Lo sentimos, su browser no soporta ajax.  Por favor descargue un browser mas actualizado.  <br />Gracias";
	}
	return request;
}

function animateFill(file){
	document.body.style.cursor = 'wait';
	pending = file;
	hideContent();
}

function fill(file) {

	var request = ajaxObject();
	
	request.onreadystatechange = function() {
		if(request.readyState == 4) {
			document.getElementById("text").innerHTML = request.responseText;
			document.body.style.cursor = 'auto';
			showContent();
		}
	}
	request.open ("GET", file, true);
	request.send (null);
}

function getStyleNumber(cssStyle) {
	var result = cssStyle.split("px");
	return result[0]*1;
}

function hideContent(){
	var content = document.getElementById("content");
	
	clearInterval(intervalId);
	
	intervalId = setInterval(function() { hideContent_EnterFrame() }, animationSpeed);
}

function hideContent_EnterFrame() {
	var content = document.getElementById("content");
	var top = getStyleNumber(content.style.top);
	
	if (top > -content.offsetHeight + correctionBuffer) {
		content.style.top = (top + (-(top+content.offsetHeight)/speedDivisor)) + "px";
	} else {
		fill(pending);
		content.style.top = (-content.offsetHeight) + "px";
		clearInterval(intervalId);
	}
}


function showContent(){
	var content = document.getElementById("content");
	
	clearInterval(intervalId);
	
	content.style.top = (-content.offsetHeight) + "px";
	
	intervalId = setInterval(function() { showContent_EnterFrame() }, animationSpeed);
}

function showContent_EnterFrame(){
	var content = document.getElementById("content");
	var top = getStyleNumber(content.style.top);

	if (top < -correctionBuffer) {
		content.style.top = (top + (-top/speedDivisor)) + "px";
	} else {
		content.style.top = "0px";
		clearInterval(intervalId);
	}
}            

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function gotoSection(msg) {
	eval("document.getElementById('menu_movie').goto" + msg + "()");
}
