var scrollStep = 0;
var t;

function cancel() {
	clearTimeout(t);
}

function scrollText (direction) {
	var infoSize = $('#content_info').height(); //gets the size of the info div
	var contSize = $('#content').height(); //gets the size of the content div
	var pos = infoSize - contSize; //defines the difference in sizes between the info div and content div
	var ch = "";
	
	ch = pos.toString(); 
	ch = ch.charAt(ch.length - 1);
	ch = parseInt(ch);
			
	if (pos < 0 )
		pos = Math.abs(pos) - 10 + (10 - ch);
	else
		pos = Math.abs(pos) + 30 + (10 - ch);
			
	pos = "-" + pos.toString() + "px";
	
	scroll(direction, infoSize, contSize, pos);
	
	if (direction == 'down')
		t = setTimeout("scrollText('down')", 75);
	else
		t = setTimeout("scrollText('up')", 75);
}

function scroll(direction, infoSize, contSize, pos) {
	if ( (infoSize - contSize) >= -40) {
		if ( (direction == "up") && ($("#content_info").css('top') < "0px") ) {
			scrollStep = scrollStep + 10;
			$("#content_info").css('top', scrollStep.toString() + "px");
		} else if ( (direction == "down") && ($("#content_info").css('top') != pos) ) {
			scrollStep = scrollStep - 10;
			$("#content_info").css('top', scrollStep.toString() + "px");
		}
	}
}

function loadPages(page) {
	var pagePath;
	
	$("#content").fadeIn(1000);
	switch (page) {
		case "intro":
			$("#content").load('empresa/intro.html');
			scrollStep = 0;
			break;
		case "qsomos":
			$("#content").load('empresa/qsomos.html');
			scrollStep = 0;
			break;
		case "actividade":
			$("#content").load('empresa/actividade.html');
			scrollStep = 0;
			break;
		case "clientes":
			$("#content").load('clientes/clientes.html');
			scrollStep = 0;
			break;
		case "obrasexec":
			$("#content").load('obras/obrasexec.html');
			scrollStep = 0;
			break;
		case "fotos1":
			$("#content").load('obras/obras.html');
			scrollStep = 0;
			break;
		case "fotos2":
			$("#content").load('obras/obras2.html');
			scrollStep = 0;
			break;
		case "fotos3":
			$("#content").load('obras/obras3.html');
			scrollStep = 0;
			break;
		case "fotos4":
			$("#content").load('obras/obras4.html');
			scrollStep = 0;
			break;
		case "contacto":
			$("#content").load('contactos/contacto.html');
			scrollStep = 0;
			break;
	}
}

