// ---------------------------------------------------- //
// Librerias dhtml base					//
// Intermark Multimedia 2001				//
// ---------------------------------------------------- //


function checknavegador() {
	n = navigator.appName;
	v = parseInt(navigator.appVersion)
	this.ie4 = (n=="Microsoft Internet Explorer" && v>=4)
	this.ns4 = (n=="Netscape" && v>=4)
}
nav = new checknavegador();
// ---------------------------------------------------- //

var x=0, y=0;
document.onmousemove = posiciona
if (nav.ns4) document.captureEvents(Event.MOUSEMOVE)

function posiciona(e){
	if (nav.ns4) {
		x = e.pageX
		y = e.pageY
	} else if (nav.ie4) {
		x = window.event.x
		y = window.event.y
	}
}



function objetoCapa(capaid,capaparent) {
	if (nav.ns4) {
		this.propiedad = (capaparent)? eval("document."+capaparent+".document."+capaid) : document.layers[capaid]
		this.x = parseInt(this.propiedad.left)
		this.y = parseInt(this.propiedad.top)
		//this.w = parseInt(this.propiedad.clip.width)
		//this.h = parseInt(this.propiedad.clip.height)
		this.w = parseInt(this.propiedad.document.width)
		this.h = parseInt(this.propiedad.document.height)
	} else if (nav.ie4) {
		this.propiedad = document.all[capaid].style
		this.elm = document.all[capaid]
		this.x = parseInt(this.propiedad.left)
		this.y = parseInt(this.propiedad.top)
		//this.w = parseInt(this.propiedad.width)
		//this.h = parseInt(this.propiedad.height)
		this.w = parseInt(document.all[capaid].offsetWidth)
		this.h = parseInt(document.all[capaid].offsetHeight)
	}
	this.obj = capaid + "objeto"
	eval(this.obj + "=this")
		
	this.mover_a = movercapa
	this.mostrar = mostrarcapa
	this.ocultar = ocultarcapa
	this.clipping = clippingcapa
	this.valorclipping = valoresdelclipping
	this.escribecapa = escribec
	
	this.scrollaba = scrollabajo
	this.scrollarr = scrollarriba
	this.scrollder = scrollderecha
	this.scrollizq = scrollizquierda
	this.scrollini = scrollinicializa
	this.scrollactiva = scrollactivar
	this.scrollpara = scrollparar
	this.scrollposini = scrollposicioninicial
	
	this.scrollnews = iniscrollnews
	this.scrollnewsp = scrollnewsprincipal
	
	this.scrollrat = iniscrollraton
	this.muevescrollrat = muevescrollraton
	
	this.desplaza = desplazamiento
}

function movercapa(x, y) {
	this.x = x
	this.y = y
	this.propiedad.left = x
	this.propiedad.top = y
}

function mostrarcapa() {
	this.propiedad.visibility = (nav.ns4) ? "show" : "visible"
}
function ocultarcapa() {
	this.propiedad.visibility = (nav.ns4) ? "hide" : "hidden"
}

function clippingcapa(t,r,b,l) {
	if (nav.ns4) {
		this.propiedad.clip.top = t
		this.propiedad.clip.right = r
		this.propiedad.clip.bottom = b
		this.propiedad.clip.left = l
	} else if (nav.ie4) {
		this.propiedad.clip = "rect(" +t+ "px " +r+ "px " +b+ "px " +l+ "px)"
	}
}
function valoresdelclipping(quevalor) {
	if (this.propiedad.clip == '') return
	if (nav.ie4) var clipv = this.propiedad.clip.split("rect(")[1].split(")")[0].split("px")
	if (quevalor=="t") return (nav.ns4)? this.propiedad.clip.top : Number(clipv[0])
	if (quevalor=="r") return (nav.ns4)? this.propiedad.clip.right : Number(clipv[1])
	if (quevalor=="b") return (nav.ns4)? this.propiedad.clip.bottom : Number(clipv[2])
	if (quevalor=="l") return (nav.ns4)? this.propiedad.clip.left : Number(clipv[3])
}

function escribec(txt) {
	if (nav.ie4) {
		this.elm.innerHTML = txt;
	} else if (nav.ns4) {
		this.propiedad.document.open();
		this.propiedad.document.write(txt);
		this.propiedad.document.close();
	}
}

function scrollinicializa() {
if (this.h > this.valorclipping('b')) {
	this.activoV = 1	
}else {
	this.activoV = 0
}
this.topearriba = this.y - (this.h - this.valorclipping('b'))
this.topeabajo = this.y
this.topearribaclipt = 0
this.topearribaclipb = this.valorclipping('b')
this.topeabajoclipt = this.valorclipping('t') + (this.h - this.valorclipping('b'))
this.topeabajoclipb = this.valorclipping('b') + (this.h - this.valorclipping('b'))
		
if (this.w > this.valorclipping('r')) {
	this.activoH = 1	
}else {
	this.activoH = 0
}
this.topeizquierda = this.x - (this.w - this.valorclipping('r'))
this.topederecha = this.x
this.topeizquierdaclipl = 0
this.topeizquierdaclipr = this.valorclipping('r')
this.topederechaclipl = this.valorclipping('l') + (this.w - this.valorclipping('r'))
this.topederechaclipr = this.valorclipping('r') + (this.w - this.valorclipping('r'))
		
this.primeravez = 1		
}
function scrollactivar(direccion, aumento) {
	if (direccion == 'abajo') func = 'scrollaba'
	if (direccion == 'arriba') func = 'scrollarr'
	if (direccion == 'derecha') func = 'scrollder'
	if (direccion == 'izquierda') func = 'scrollizq'
	
	if (aumento == null) aumento = 8
	
	if (this.primeravez==null) {
		this.scrollini();
	}
	
	this.activo = 1
	
	if (direccion == 'abajo' || direccion == 'arriba') {
		if (this.activoV) eval("this."+func+"(this.valorclipping('t'),this.valorclipping('r'),this.valorclipping('b'),this.valorclipping('l'),this.x, this.y,"+aumento+")");
	}
	if (direccion == 'izquierda' || direccion == 'derecha') {
		if (this.activoH) eval("this."+func+"(this.valorclipping('t'),this.valorclipping('r'),this.valorclipping('b'),this.valorclipping('l'),this.x, this.y,"+aumento+")");
	}
}

function scrollposicioninicial() {
	if (this.primeravez==null) {
		this.scrollini();
	}
	
	this.posiy = this.topeabajo
	this.clipt = this.topearribaclipt
	this.clipb = this.topearribaclipb
	this.mover_a(this.x, this.posiy);
	this.clipping(this.clipt, this.valorclipping('r'), this.clipb, this.valorclipping('l'));
	
	
	this.posix = this.topederecha
	this.clipl = this.topeizquierdaclipl
	this.clipr = this.topeizquierdaclipr
	this.mover_a(this.posix, this.y);
	this.clipping(this.valorclipping('t'), this.clipr, this.valorclipping('b'), this.clipl);
}
function scrollabajo(clipt, clipr, clipb, clipl, x, y, aumento) {

if (this.activo) {
	
	this.posiy = y - aumento;
	this.clipt = clipt + aumento;
	this.clipb = clipb + aumento;

	if (this.posiy > this.topearriba) {
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
		setTimeout(this.obj+".scrollaba("+this.clipt+", "+clipr+", "+this.clipb+", "+clipl+", "+this.x+", "+this.posiy+", "+aumento+")",10);
	}else {
		this.posiy = this.topearriba
		this.clipt = this.topeabajoclipt
		this.clipb = this.topeabajoclipb
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
	}
}
}
function scrollarriba(clipt, clipr, clipb, clipl, x, y, aumento) {

if (this.activo) {
	
	this.posiy = y + aumento;
	this.clipt = clipt - aumento;
	this.clipb = clipb - aumento;

	if (this.posiy < this.topeabajo) {
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
		setTimeout(this.obj+".scrollarr("+this.clipt+", "+clipr+", "+this.clipb+", "+clipl+", "+this.x+", "+this.posiy+", "+aumento+")",10);
	}else {
		this.posiy = this.topeabajo
		this.clipt = this.topearribaclipt
		this.clipb = this.topearribaclipb
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
	}
}
}
function scrollderecha(clipt, clipr, clipb, clipl, x, y, aumento) {

if (this.activo) {
	
	this.posix = x - aumento;
	this.clipl = clipl + aumento;
	this.clipr = clipr + aumento;

	if (this.posix > this.topeizquierda) {
		this.mover_a(this.posix, this.y);
		this.clipping(clipt, this.clipr, clipb, this.clipl);
		setTimeout(this.obj+".scrollder("+clipt+", "+this.clipr+", "+clipb+", "+this.clipl+", "+this.posix+", "+this.y+", "+aumento+")",10);
	}else {
		this.posix = this.topeizquierda
		this.clipl = this.topederechaclipl
		this.clipr = this.topederechaclipr
		this.mover_a(this.posix, this.y);
		this.clipping(clipt, this.clipr, clipb, this.clipl);
	}
}
}
function scrollizquierda(clipt, clipr, clipb, clipl, x, y, aumento) {

if (this.activo) {
	
	this.posix = x + aumento;
	this.clipl = clipl - aumento;
	this.clipr = clipr - aumento;

	if (this.posix < this.topederecha) {
		this.mover_a(this.posix, this.y);
		this.clipping(clipt, this.clipr, clipb, this.clipl);
		setTimeout(this.obj+".scrollizq("+clipt+", "+this.clipr+", "+clipb+", "+this.clipl+", "+this.posix+", "+this.y+", "+aumento+")",10);
	}else {
		this.posix = this.topederecha
		this.clipl = this.topeizquierdaclipl
		this.clipr = this.topeizquierdaclipr
		this.mover_a(this.posix, this.y);
		this.clipping(clipt, this.clipr, clipb, this.clipl);
	}
}
}
function scrollparar() {
	this.activo = 0;
}


function iniscrollnews(aumento) {

	if (aumento == null) aumento = 1
	this.posiyini = this.y
	this.topey = this.y - (this.h)
	//alert(this.topey)
	this.topetini = this.valorclipping('t')
	this.topebini = this.valorclipping('b')
	this.activo = 1
	eval("this.scrollnewsp(this.valorclipping('t'),this.valorclipping('r'),this.valorclipping('b'),this.valorclipping('l'),this.x, this.y,"+aumento+")");
}
function scrollnewsprincipal(clipt, clipr, clipb, clipl, x, y, aumento) {

if (this.activo) {

	this.posiy = y - aumento;
	this.clipt = clipt + aumento;
	this.clipb = clipb + aumento;

	if (this.posiy > this.topey) {
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
	}else {
		this.posiy = this.posiyini
		this.clipt = this.topetini
		this.clipb = this.topebini
		this.mover_a(this.x, this.posiy);
		this.clipping(this.clipt, clipr, this.clipb, clipl);
	}
	setTimeout(this.obj+".scrollnewsp("+this.clipt+", "+clipr+", "+this.clipb+", "+clipl+", "+this.x+", "+this.posiy+", "+aumento+")",30);
}
}


function iniscrollraton(topeizq, topeder, medio){

	if (nav.ns4) {
		totalventana = window.innerWidth
	}
	else if (nav.ie4) {
		totalventana = document.body.clientWidth
	}

	if (medio == null) this.medio = totalventana / 2
	else this.medio = medio
	
	this.ancho = this.w
	this.xactual = this.x
	if (topeizq == null) this.topeizq = 0
	else this.topeizq = topeizq
	
	if (topeder == null) this.topeder = -(this.ancho-totalventana)
	else this.topeder = topeder
	
	this.mover_a(this.xactual,this.y)
	
	this.muevescrollrat();
}
function muevescrollraton(){
	xm = x

	if (xm <= this.medio) {
		this.xactual = this.xactual + ((this.medio-xm) / 40)
		if (this.xactual >= this.topeizq) {
			this.xactual = this.topeizq
		}
	} else 	{
		this.xactual = this.xactual - ((xm-this.medio) / 40)
		if (this.xactual <= this.topeder) {
			this.xactual = this.topeder
		}
	}

	this.mover_a(this.xactual,this.y)

	setTimeout(this.obj+".muevescrollrat()",5)			
}



function desplazamiento(pxini,pyini,pxfin,pyfin,pasostotal,acel) {
	
if (acel == null) acel = 0
if (pasostotal == null) pasostotal = 0

if (this.primeravez==null) {
	this.posix = pxini
	this.posiy = pyini
	distx = pxini - pxfin
	disty = pyini - pyfin
	this.dist = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))
	this.distactual = 0.5
	this.seno = disty/this.dist
	this.angulo = 180-(180*(Math.asin(this.seno)) / Math.PI)
	if (pxfin > pxini && pyfin <= pyini) this.angulo = (180*(Math.asin(this.seno)) / Math.PI)
	if (pxfin > pxini && pyfin > pyini) this.angulo = 270 + (270 - this.angulo)
	this.aumx = Math.cos(Math.PI*this.angulo/180)
	this.aumy = -Math.sin(Math.PI*this.angulo/180)
	this.acel = 0.3
	this.maxacel = this.acel
	this.primeravez = 1
	this.paso = 1
	this.swsecuencia = 1
}	

if (this.swsecuencia) {
if (!acel) {
	if (this.paso <= pasostotal) {
		
		this.posix = pxini+((pxfin-pxini) * this.paso) / pasostotal
		this.posiy = pyini+((pyfin-pyini) * this.paso) / pasostotal
		this.mover_a(this.posix, this.posiy);
		setTimeout(this.obj+".desplaza("+pxini+", "+pyini+", "+pxfin+", "+pyfin+", "+pasostotal+", "+acel+")",0);
		this.paso ++
		
	}else {
		this.primeravez = null
		this.swsecuencia = 0
		return
	}
} else if (acel==1) {

	if (this.distactual < (this.dist/2)) {
		this.acel = this.acel + 1
		this.maxacel = this.acel
	} else {
		this.acel = (this.dist-this.distactual)/3
		if (this.acel > this.maxacel) this.acel = this.maxacel
	}
	
	this.posix = this.posix + (this.aumx *this.acel)
	this.posiy = this.posiy + (this.aumy *this.acel)
	dx = this.posix - pxini
	dy = this.posiy - pyini
	this.distactual = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))

	if ((this.dist-this.distactual) > 1 && this.acel > 0) {
		this.mover_a(this.posix, this.posiy);
		setTimeout(this.obj+".desplaza("+pxini+", "+pyini+", "+pxfin+", "+pyfin+", "+pasostotal+", "+acel+")",0);
	} else {
		this.posix = pxfin
		this.posiy = pyfin
		this.mover_a(this.posix, this.posiy);
		this.primeravez = null
		this.swsecuencia = 0
		return
	}
} else if (acel>1) {

	dx = this.posix - pxini
	dy = this.posiy - pyini
	this.distactual = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))

	this.posix = this.posix + (pxfin - this.posix)/acel;
	this.posiy = this.posiy + (pyfin - this.posiy)/acel;


	if ((this.dist-this.distactual) > 0.7) {
		this.mover_a(this.posix, this.posiy);
		setTimeout(this.obj+".desplaza("+pxini+", "+pyini+", "+pxfin+", "+pyfin+", "+pasostotal+", "+acel+")",0);
	} else {
		this.posix = pxfin
		this.posiy = pyfin
		this.mover_a(this.posix, this.posiy);
		this.primeravez = null
		this.swsecuencia = 0
		return
	}
}
}

}










