// ======================= http://meddle.dzygn.com =======================
// LatScro v.0.10: (Lat)eral (Scro)ller. Modified from 13thparallel.org
// Free to use for personal projects. Contact meddle for commercial use
// Requires Dan and Michael's columns.js, api.js, and animation.js files
// see 13thparallel.org/?title=about for more specific Copyright
// ======================= Copyright (c) 2002-2003 =======================                   


// Scoping Navigation methods:
LatScro  = {
	// properties for da navigation:
	slidin 			: 0, 
	active 			: 0, 
	startX 			: 0, 
	colW 			: 210, 
	colH 			: 250, 
	colD 			: 30, 
	siempreVisibles		: 2,
	moveDist 		: 0,
	colsNum			: 0,
	
	init 			: function(){
		// setting value of scrolling distance for one column:
		LatScro.moveDist = parseInt( LatScro.colW + LatScro.colD);
		
		// creating layer to compute sizes/columns:
		var daSizerDiv = document.createElement("div");
			daSizerDiv.id = "divSizer";
		document.getElementsByTagName( 'body' ).item( 0 ).appendChild( daSizerDiv );	
	
		// creating scroll containing layer via DOM+innerHTML:
		var daDiv = document.createElement("div");
			daDiv.id = "cajaGrandeDiv";
		document.getElementsByTagName( 'body' ).item( 0 ).appendChild( daDiv );	
		document.getElementById( 'cajaGrandeDiv' ).innerHTML = '<div id="cajaDiv"></div>';
		capaObj = new make("cajaDiv");
		
		// creating left navigation layer via DOM+innerHTML:
		var butDiv = document.createElement("div");
			butDiv.id = "botScrIzqDiv";
		document.getElementsByTagName( 'body' ).item( 0 ).appendChild( butDiv );
		document.getElementById( 'botScrIzqDiv' ).innerHTML = '<img src="/_stop.gif" alt="Stop" />';
	
	
		// creating right navigation layer via DOM+innerHTML:
		var butDiv = document.createElement("div");
			butDiv.id = "botScrDchDiv";
		document.getElementsByTagName( 'body' ).item( 0 ).appendChild( butDiv );
		document.getElementById( 'botScrDchDiv' ).innerHTML = '<a href="#" onclick="LatScro.goRG(); return false"><img src="/_right.gif" alt="Ir derecha" /></a><a href="#" onclick="LatScro.goMax(LatScro.colsNum-LatScro.siempreVisibles); return false"><img src="/_totright.gif" alt="Ir máximo a derecha" /></a>';
	
		// creating navigation info layer via DOM:
		var infoDiv = document.createElement("div");
			infoDiv.id = "infoScrDiv";
		document.getElementsByTagName( 'body' ).item( 0 ).appendChild( infoDiv );
		
		// computing columns:
		var donde = "container";
		var exampleColumns = Columns.splitText(document.getElementById( donde ).innerHTML, LatScro.colW, LatScro.colH);
		
		// resetting values for scroller: 
		var pos = LatScro.startX;
		capaObj.timeSlide(0,0,550,-1);
		LatScro.colsNum = exampleColumns.length;
	
		// Recomputing info values inside infoScrDiv:
		LatScro.showInfo();
	
		// Writting the text for each column:
		for (var i = 0; i < exampleColumns.length; i ++)
		{
			if (i!=0) pos = LatScro.startX+(i*(LatScro.colW+LatScro.colD)); 
			document.getElementById( 'cajaDiv' ).innerHTML += "<div id='col"+i+"' class='columna'>" +exampleColumns[i]+"</div>";
			document.getElementById( 'col'+i ).style.left = pos + "px";
		}
	
		// Printing hack for dhtml version:
		addPrinter();
	},
	
	goLT 			: function(){
	if (LatScro.active>0 && LatScro.slidin==0){
		LatScro.slidin=1;
		capaObj.timeSlideBy(LatScro.moveDist,0,750,-1,null,'LatScro.resetSlide()');
		LatScro.active--;
		LatScro.showInfo();
		LatScro.checkStop();
		}
	},
	
	goRG 			: function(){
	if (LatScro.active<LatScro.colsNum-LatScro.siempreVisibles && LatScro.slidin==0){
		LatScro.slidin=1;
		capaObj.timeSlideBy(-LatScro.moveDist,0,750,-1,null,'LatScro.resetSlide()');
		LatScro.active++;
		LatScro.showInfo();
		LatScro.checkStop();
		}
	},
	
	goMax 			: function(w){
	if (LatScro.slidin==0){
		LatScro.slidin=1;  
		if(!w)	w=0;
		w=parseInt(w);
		capaObj.timeSlide(-LatScro.moveDist*w,0,750,-1,null,'LatScro.resetSlide()');
		LatScro.active=w;
		LatScro.showInfo();
		LatScro.checkStop();
		}
	},
	
	checkStop 		: function(){
		if(LatScro.colsNum>2){
			if (LatScro.active==LatScro.colsNum-LatScro.siempreVisibles){
				document.getElementById( 'botScrIzqDiv' ).innerHTML = '<a href="#" onclick="LatScro.goMax(); return false"><img src="/_totleft.gif" alt="Ir máximo a izquierda" /></a><a href="#" onclick="LatScro.goLT(); return false"><img src="/_left.gif" alt="Ir izquierda" /></a>';
				document.getElementById( 'botScrDchDiv' ).innerHTML = '<img src="/_stop.gif" alt="Stop" />';
			}	
			else {
				if (LatScro.active<1){
					document.getElementById( 'botScrIzqDiv' ).innerHTML = '<img src="/_stop.gif" alt="Stop" />';
					document.getElementById( 'botScrDchDiv' ).innerHTML = '<a href="#" onclick="LatScro.goRG(); return false"><img src="/_right.gif" alt="Ir derecha" /></a><a href="#" onclick="LatScro.goMax(LatScro.colsNum-LatScro.siempreVisibles); return false"><img src="/_totright.gif" alt="Ir máximo a derecha" /></a>';
				}
				else {
					document.getElementById( 'botScrIzqDiv' ).innerHTML = '<a href="#" onclick="LatScro.goMax(); return false"><img src="/_totleft.gif" alt="Ir máximo a izquierda" /></a><a href="#" onclick="LatScro.goLT(); return false"><img src="/_left.gif" alt="Ir izquierda" /></a>';
					document.getElementById( 'botScrDchDiv' ).innerHTML = '<a href="#" onclick="LatScro.goRG(); return false"><img src="/_right.gif" alt="Ir derecha" /></a><a href="#" onclick="LatScro.goMax(LatScro.colsNum-LatScro.siempreVisibles); return false"><img src="/_totright.gif" alt="Ir máximo a derecha" /></a>';
				}
			}
		}
		else { // dos cols. o menos
		document.getElementById( 'botScrIzqDiv' ).innerHTML = '';
		document.getElementById( 'botScrDchDiv' ).innerHTML = '';
		document.getElementById( 'infoScrDiv' ).innerHTML = '';
		}
	},
	
	resetSlide		: function(){
		LatScro.slidin=0;
	},
	
	showInfo 		: function(){
		if(LatScro.colsNum>2){
		var pagina = parseInt(LatScro.active+1);
		document.getElementById( 'infoScrDiv' ).innerHTML = pagina+"-"+(pagina+1)+"/"+LatScro.colsNum;
		}
	}
}

//===============================================================================================
// If browser supports enough DOM/CSS we change CSS on the fly and start javascript functions.
//===============================================================================================
if (document.getElementById && document.getElementsByTagName && document.createElement 
&& !brw.konq && typeof document.getElementsByTagName("head")[0].innerHTML != "undefined" ) {

addStyleSheet("/css/popuplect.css", "screen");
	onload=LatScro.init;
}

