
//// Chequea el navegador (requerido)

function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

///////////////////////////////////////
//  Variables
///////////////////////////////////////

timSpeed = 50 //Velocidad del Scroll
contHeight = 240 //Tamaño de zona scrollable del texto
var scrollTim = 1; //Timer del scroll
var active = 0; //Capa activa en el inicio
var zonascroll1 = 224 - 16 //Area vertical en pixeles por la que se va a desplazar el indicador1 - altura de la imagen


/*********************************************************************************
Constructor de objetos
*********************************************************************************/
function makeScrollObj(obj,nest){

	if (!nest) {
		nest = "";
	} else {
		nest = 'document.'+nest+'.';
	}

	if (bw.dom) {
		this.el = document.getElementById(obj);
	} else if (bw.ie4) {
		this.el = document.all[obj];
	} else if (bw.ns4) {
		this.el = eval(nest+'document.'+obj);
	} else {
		this.el = 0;
	}

	if (bw.dom) {
		this.css = document.getElementById(obj).style;
	} else if (bw.ie4) {
		this.css = document.all[obj].style;
	} else if (bw.ns4) {
		this.css = eval(nest+'document.'+obj);
	} else {
		this.css = 0;
	}

	if (bw.ns4) {
		this.height = this.css.document.height;
	} else {
		this.height = this.el.offsetHeight;
	}

	this.top=b_gettop										
	return this
}

// Añade "px" o no a las unidades dependiendo del navegador
if (bw.ns4 || window.opera) { //OR
	var px = "";
} else {
	var px = "px";
}

//Calcula la la posición de las capas
function b_gettop(){
	if (bw.ns4 || bw.ns6) {
		var gleft = parseInt(this.css.top);
	} else {
		var gleft = eval(this.css.pixelTop);
	}
	return gleft;
}


/*********************************************************************************
Función de scroll para las capas de texto
*********************************************************************************/
function scroll(speed){

	clearTimeout(scrollTim)
	
	destino = parseInt(oScroll[active].height-contHeight);
	dondeva = parseInt(oScroll[active].top());
	porcentaje = (dondeva*100)/destino;
	donde = parseInt(zonascroll1*(porcentaje/100))
	
	if (speed>0) {
		way = 1;
	} else {
		way = 0;
	}
	
	if ((!way && oScroll[active].top()>-oScroll[active].height+contHeight) || (oScroll[active].top()<0 && way)){
		oScroll[active].css.top = (oScroll[active].top()+speed)+px
		oIndicador[1].css.top = -donde + px;
		scrollTim = setTimeout("scroll("+speed+")",timSpeed)
	}

}

//Detiene los scrolls
function noScroll(){
	clearTimeout(scrollTim)
}

/*********************************************************************************
Cambia la capa activa de texto, oculta o muestra el indicador de desplazamiento y recoloca las capas a 0
*********************************************************************************/
function changeActive(num){
	oScroll[active].css.visibility = "hidden"
	active = num
	oScroll[active].css.top = 0+px
	oScroll[active].css.visibility = "visible"
	oIndicador[1].css.left = 0+px;
	oIndicador[1].css.top = 0+px;
	if (oScroll[active].top()<-oScroll[active].height+contHeight) {
		oIndicador[1].css.visibility = "hidden"
	} else {
		oIndicador[1].css.visibility = "visible"
	}
}

/*********************************************************************************
Inicializa los objetos del scroll.
Si se añaden más items, aquí es donde se tiene que hacer
*********************************************************************************/
function scrollInit(){
	
	if (!bw.ns4) {
		document.body.style.overflow='hidden';
	}
		
	oScroll = new Array()
	
	// Aquí se añaden las capas de texto
	oScroll[0] = new makeScrollObj('divScroll1','divTexto')
	
	oScroll[0].css.left = 0+px
	oScroll[0].css.top = 0+px
	oScroll[0].css.visibility = "visible"
	
	oIndicador = new Array()
	
	oIndicador[1] = new makeScrollObj('indicador1','divIndi1');
	oIndicador[1].css.left = 0+px;
	oIndicador[1].css.top = 0+px;
	
	changeActive(0)

}


