//Copyright 2002 LA NACION LINE

var mouseX = mouseY = 0;

function Pantalla(){
	this.bottom = function(){
		if (document.body.scrollHeight) return document.body.scrollHeight
	}
	this.height = function(){
		if (document.body.offsetHeight) return document.body.offsetHeight
	}
	this.visHeight = function(){
		if (window.innerHeight) return window.innerHeight;
		if (document.body.clientHeight) return document.body.clientHeight
	}
	this.width = function(){
		if (document.body.offsetWidth) return document.body.offsetWidth
	}
	this.scrollTop = function(){
		if(document.body.scrollTop) return document.body.scrollTop
		if (window.pageYOffset) return window.pageYOffset
		else return 0
	}
}

function inicializar(){
	objetoScreen = new Pantalla();
	if (document.getElementById("LayerNota") != null) initNota();	// inicializo nota
}

function Redibuja(){
	//Redibuja por fix del explorer en back
	document.getElementById("body").style.display = "block"
}

window.onload = Redibuja;

/* Compatibilidad Browser */
if (document.all) classFix = "className";
else classFix = "class"

if (!document.all){
	document.writeln('<style type="text/css">');
	document.writeln('.c, .click {cursor:pointer}');
	document.writeln('.noborder {border:1px solid}');
	document.writeln('</style>');
}

function mousePosition(e){
	if (e) event = e;	//Netscape
	mouseX = event.clientX;
	mouseY = event.clientY;
}

if (document.all) classFix = "className"
else classFix = "class"

var originalHeight;
var fontSize = FONT_NORMAL;
var lineHeight = 16;
var currentPos = 0;

var tHeight = 0;

var articleGraphic = null;
columnMode = COLUMA_NORMAL;

function DestacarNavegadorPagina(boton){
	//Muestra el icono de la próxima página cuando se mouseoverea la columna
	parentHeight = obtenerAlto("LayerTotal")

	if (((parentHeight*(currentPos+columnMode)) < tHeight & boton=="next" ) || (currentPos > 0 & boton=="prev")){
		objeto = eval(document.getElementById(boton + "Cool"))
		objeto.style.visibility = "hidden"
		objeto = document.getElementById(boton +"Hot")
		objeto.style.visibility = "visible"
		if (boton=="prev") {document.getElementById("at0").style.cursor= "hand"}
		else {
			if (columnMode == 2){
				document.getElementById("at1").style.cursor= "hand"
			}
			else{
				document.getElementById("at2").style.cursor= "hand"
			}
		}
	}
	else{
		if (boton=="prev") {document.getElementById("at0").style.cursor= "default"}
		else {
			if (columnMode == 2){
				document.getElementById("at1").style.cursor= "default"
			}
			else{
				document.getElementById("at2").style.cursor= "default"
			}
		}
	}
}

function DestacarNavegadorPaginaNext() {DestacarNavegadorPagina("next")}
function DestacarNavegadorPaginaPrev() {DestacarNavegadorPagina("prev")}

function ocultarPagina(){
	//Cambia el icono de previa/próxima página
	objeto = document.getElementById("prevCool")
	objeto.style.visibility = "visible"
	objeto = document.getElementById("prevHot")
	objeto.style.visibility = "hidden"

	objeto = document.getElementById("nextCool")
	objeto.style.visibility = "visible"
	objeto = document.getElementById("nextHot")
	objeto.style.visibility = "hidden"
}

function obtenerAlto(objeto){
	if (objeto == "window"){
		if (window.innerHeight) return window.innerHeight;
		else return 562; //Se podria poner un div en el body
		//anterior_no_sirve_692
	}
	else{
		objeto = document.getElementById(objeto)
		if (objeto.offsetHeight) return objeto.offsetHeight;
	}
}

function setearNota(){
	parentDiv = document.getElementById("LayerTotal")
	currentPos = 0;
	for (i=0; i < 3; i++){
		col = document.createElement("div")
		//Setea un id para el div
		col.setAttribute("id", "ac"+i)
		//Setea el estilo del div
		col.setAttribute(classFix, "artCol")
		parentDiv.appendChild(col);
		objeto = document.getElementById("LayerNota")
		artText = objeto.cloneNode(true)
		artText.setAttribute("id","at"+i)
		//Muestra la columna
		artText.style.display = "block"
		artText.style.top = "0px"
		artText.style.fontSize = fontSize+"px";
		artText.style.lineHeight = lineHeight+"px";
		col.appendChild(artText);
	}
	if (document.getElementById("LayerFinNota")){
		objeto = document.getElementById("LayerFinNota")
		articleGraphic = objeto;
	}
}

function layoutGraphic(){
	if (columnMode != 1){
		objeto = document.getElementById("at"+(columnMode-1));
		if ((parseInt(objeto.style.top) + objeto.offsetHeight) < (parentHeight)){
			colHeight = obtenerAlto("at0");
			graphicOffset = (columnMode-1)*parentHeight;
			articleGraphic.style.marginTop = lineHeight;
			articleGraphic.style.top = colHeight-((parentHeight*currentPos)+graphicOffset);
			if (parseInt(articleGraphic.style.top) < 0){
				articleGraphic.style.marginTop = 0;
				articleGraphic.style.top = 0;
			}
			if (columnMode == 2) articleGraphic.style.left = (1)*colWidth+20+"px"
			if (columnMode == 3) articleGraphic.style.left = (2)*colWidth+36+"px"
			articleGraphic.style.visibility = "visible"
		}
		else articleGraphic.style.visibility = "hidden"
	}
}

function layoutNotas(){
	parentHeight = obtenerAlto("LayerTotal")
	for (i = 0; i < columnMode; i++){
		objeto = document.getElementById("at"+i);
		if (parentHeight > 2*lineHeight){
			objeto.style.top = -1*(parentHeight*(i+currentPos))
		}
	}
	if (articleGraphic) layoutGraphic();
	setearPaginas();
}

function setSnap(mod){
	if (mod == null) mod =0;
	snap = lineHeight*Math.round((obtenerAlto("window")-mod)/lineHeight)
	if (snap < lineHeight*10){
		snap = lineHeight*10;
		if (window.scrollTo) window.scrollTo(0,75);
	}
	else if (window.scrollTo) window.scrollTo(0,0);
	return snap;
}

function setearAltoNota(){
	if (columnMode > 1){
		if (document.getElementById("LayerNota") != null){
			document.getElementById("LayerTotal").style.height = setSnap(295)
			tHeight = obtenerAlto("at1")
			if (articleGraphic) tHeight = tHeight+articleGraphic.offsetHeight;
			parentHeight = obtenerAlto("LayerTotal")
			while ((parentHeight*(currentPos+columnMode-1)) > tHeight && currentPos > 0){
				currentPos= currentPos-1;
			}
			layoutNotas()
		}
	}
}

function setearPaginas(){
	parentHeight = obtenerAlto("LayerTotal")
	totalColumns = tHeight/parentHeight;
	totalPages = Math.ceil(totalColumns);
	tPos = (currentPos+columnMode)/columnMode;
	pagesTotal = Math.ceil(totalPages/columnMode);
	pagesCurrent = Math.round(tPos);
	if (columnMode==1){pagesTotal=1}
	if (pagesTotal==1){document.getElementById("LayerFinNota").style.visibility = "hidden"}
	objCount = document.getElementById("LayerPagina");
	objCount.innerText= "Página: "+ pagesCurrent + " de " + pagesTotal
}

function paginaSiguiente(){
	parentHeight = obtenerAlto("LayerTotal")
	if ((parentHeight*(currentPos+columnMode)) < tHeight){
		currentPos= currentPos+columnMode
	}
	layoutNotas();
}

function paginaAnterior(){
	currentPos= currentPos-columnMode;
	if (currentPos < 0) currentPos = 0
	layoutNotas()
}

function eventoUnaColumna(flag){
	currentPos = 0;
	columnMode =1 
	colWidth = col1Width;
	objeto = document.getElementById("at0")
	objeto.style.width = colWidth;
	objeto.style.left=0
	objeto = document.getElementById("LayerTotal");
	objeto.style.height = obtenerAlto("at0")//col2Width;
	objeto = document.getElementById("at1")
	objeto.style.display = 'none';
	objeto = document.getElementById("at2")
	objeto.style.display = "none"
	parentHeight = obtenerAlto("LayerTotal")

	for (i = 0; i < columnMode; i++){
		objeto = document.getElementById("at"+i);
		objeto.style.top = -1*(parentHeight*(i+currentPos))	//"px"//-1*(parentHeight*(i+currentPos))+"px"
	}

	articleGraphic.style.top = document.getElementById("at0").offsetHeight-articleGraphic.offsetHeight+"px";
	articleGraphic.style.left = "480px"
	articleGraphic.style.visibility = "visible";
	if (flag) saveFaceSize();
	setearPaginas();
	document.getElementById("LayerFinNota").style.display = "none";
	document.getElementById("SiguientePagina").style.display = "none";
	document.getElementById("AnteriorPagina").style.display = "none";
}

function eventoDosColumnas(flag){
	if (window.scrollTo) window.scrollTo(0,0);
	dosColumnas();
	setearAltoNota();
	if (flag) saveFaceSize();
	setearPaginas();
}

function eventoTresColumnas(flag){
	if (window.scrollTo) window.scrollTo(0,0);
	tresColumnas();
	setearAltoNota();
	if (flag) saveFaceSize();
	setearPaginas();
}

function dosColumnas(){
	currentPos = 0;
	columnMode = 2
	colWidth = col2Width;
	if (fontSize > 18) {fontSize = 18}
	objeto = document.getElementById("at0")
	if (document.all) objeto.style.cursor = "hand";
	else objeto.style.cursor = "pointer";
	objeto.style.zIndex = 5;
	objeto.style.width = colWidth;
	objeto.onmousemove = DestacarNavegadorPaginaPrev;
	objeto.onmouseout = ocultarPagina;
	//objeto.onmousedown = paginaAnterior;
	objeto.onclick = paginaAnterior;
	objeto.onmouseup = ocultarPagina;
	objeto.style.left = 0;
	objeto = document.getElementById("at1")
	if (document.all) objeto.style.cursor = "hand";
	else objeto.style.cursor = "pointer";
	objeto.style.display = "block"
	objeto.style.left = colWidth+16;
	objeto.style.width = colWidth;
	objeto.onmousemove = DestacarNavegadorPaginaNext;
	objeto.onmouseout = ocultarPagina;
	objeto.onclick = paginaSiguiente;
	objeto.onmouseup = ocultarPagina;
	objeto = document.getElementById("at2")
	objeto.style.display = "none"
	document.getElementById("LayerFinNota").style.display = "block";
	document.getElementById("SiguientePagina").style.display = "block";
	document.getElementById("AnteriorPagina").style.display = "block";
}

function tresColumnas(){
	currentPos = 0;
	columnMode = 3
	colWidth = col3Width;
	if (fontSize > 18) {fontSize = 18}
	objeto = document.getElementById("at0")
	if (document.all) objeto.style.cursor = "hand";
	else objeto.style.cursor = "pointer";
	objeto.style.zIndex = 5;
	objeto.style.width = colWidth;
	objeto.onmousemove = DestacarNavegadorPaginaPrev;
	objeto.onmouseout = ocultarPagina;
	//objeto.onmousedown = paginaAnterior;
	objeto.onmousedown = paginaAnterior;
	objeto.onmouseup = ocultarPagina;
	objeto.style.left = 0;
	objeto = document.getElementById("at1")
	objeto.style.left = colWidth+16;
	objeto.style.display = "block"
	objeto.style.width = col3Width;
	objeto.style.cursor = "default";
	objeto.onmousemove = null;
	objeto.onmouseout = null;
	objeto.onclick = null;
	objeto.onmouseup = null;
	objeto = document.getElementById("at2")
	if (document.all) objeto.style.cursor = "hand";
	else objeto.style.cursor = "pointer";
	objeto.style.display = "block"
	objeto.style.left = 2*(colWidth+16);
	objeto.style.width = colWidth;
	objeto.onmousemove = DestacarNavegadorPaginaNext;
	objeto.onmouseout = ocultarPagina;
	objeto.onclick = paginaSiguiente;
	objeto.onmouseup = ocultarPagina;
	document.getElementById("LayerFinNota").style.display = "block";
	document.getElementById("SiguientePagina").style.display = "block";
	document.getElementById("AnteriorPagina").style.display = "block";
}

function saveFaceSize(){
	var expire = new Date ();
	expire.setTime (expire.getTime() + (6000 * 24 * 3600000)); //expira en 6 días
	expire = expire.toGMTString();
	document.cookie="fontSize="+fontSize+"; path=/; domain=lanacion.com.ar; expires="+expire;
	document.cookie="columnMode="+columnMode+"; path=/; domain=lanacion.com.ar; expires="+expire;
}

function seteoFuente(flag){
	lineHeight = fontSize+Math.round(.3*fontSize);
	for (i = 0; i < 3; i++){
		objeto = document.getElementById("at"+i);
		objeto.style.fontSize = fontSize+"px";
		objeto.style.lineHeight = lineHeight+"px"
	}
	setearAltoNota();
	if (columnMode == 1) eventoUnaColumna(flag);
	if (flag) saveFaceSize();
}

function eventoMasGrande(){
	fontSize = fontSize+1;
	if (fontSize > FONT_LARGEST) fontSize = FONT_LARGEST;
	seteoFuente(true)
}

function eventoMasPequenio(){
	fontSize = fontSize-1
	if (fontSize < FONT_SMALLEST) fontSize = FONT_SMALLEST;
	seteoFuente(true);
}

function eventArticleFocus(){
	layoutNotas();
	event.cancelBubble = true;
}

function testArticle(){
	objeto = document.getElementById("LayerTotal")
	objeto.doScroll("up");
	window.status = "Esta interface no soporta scrolling.";
}

function cargarTamanioFuente(){
	//Carga el tamaño de la fuente de la cookie
	tempArray = document.cookie.split(";");
	for (tA = 0; tA < tempArray.length; tA++){
		if (tempArray[tA].indexOf('fontSize') > -1){
			//Encuentra la sección de la fuente en la cookie
			fontValue = tempArray[tA].split("=")
			fontSize = parseInt(fontValue[1]);
			lineHeight = fontSize+Math.round(.3*fontSize);
		}
		if (tempArray[tA].indexOf('columnMode') > -1){
			//Encuentra la sección de la fuente en la cookie
			colValue = tempArray[tA].split("=")
			columnMode = parseInt(colValue[1]);
		}
	}
}

function initNota(){
	// Inicializa la nota
	if (document.getElementById("LayerNota") != null){
		cargarTamanioFuente();
		setearNota();
		setearAltoNota();
		if (columnMode == 1){
			eventoUnaColumna(true);
		}
		else if (columnMode == 2){
			eventoDosColumnas(true);
		}
		else if (columnMode == 3 && MAX_COLUMAS == 2){
			eventoDosColumnas(false);
		}
		else{
			eventoTresColumnas(true);
		}
		layoutNotas()
		objeto = document.getElementById("LayerTotal");
		objeto.onkeyup = eventArticleFocus;
		objeto.onscroll = testArticle;
	}
}

function eventoEstiloInicial(){
	fontSize = FONT_NORMAL;
	columnMode = COLUMA_NORMAL;
	eventoUnaColumna(true);
	seteoFuente(true);
}

/*var menu;
function showMenu(evt){
	if(document.all){
		var bd = document.body;
		var cm = document.all.contextMenu;
		var menuobj=document.getElementById("contextMenu");
		var rightedge=bd.clientWidth-event.clientX;
		var bottomedge=bd.clientHeight-event.clientY;
		cm.style.pixelLeft = rightedge < menuobj.offsetWidth ? bd.scrollLeft+event.clientX-menuobj.offsetWidth : bd.scrollLeft+event.clientX;
		cm.style.pixelTop = bottomedge < menuobj.offsetHeight ? bd.scrollTop+event.clientY-menuobj.offsetHeight : bd.scrollTop+event.clientY;
		cm.style.visibility = 'visible'; 
		return false; 
	}
	return true;
}
function hideMenu(evt){
		document.all.contextMenu.style.visibility = 'hidden';
}
if (document.all) document.oncontextmenu=showMenu;
if (document.all) document.onclick=hideMenu;*/

//Copyright 2002 LA NACION LINE