//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*		Rutinas JavaScript de animacion de un Layer			*
//*										*
//*			Autor-Author: Sergio Cabrero				*
//*			Fecha-Date: 04/2001					*
//*			Archivo-File: scabreroLayer.js				*
//*			Lenguaje-Language: JavaScript 1.2			*
//*			URL: http://www.arrakis.es/~scabrero			*
//*			E-mail: scabrero@arrakis.es				*
//*										*
//*										*
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*				ESPECIFICACION					*
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* Objeto: scabreroLayer							*
//* Propiedades:								*
//*	css									*
//*	nocss									*
//*	id[]									*
//*	name									*
//*										*
//*	situacion[]								*
//*	destino[]								*
//*	puedemoverse: booleano							*
//*	velocidad								*
//*	aceleracion								*
//*	intervalo								*
//*	after									*
//*	m									*
//*	n									*
//*	destinofinal[]								*
//*										*
//*	contenido								*
//*	type_speed								*
//*										*
//* Métodos:									*
//*	mostrar									*
//*	esconder								*
//*										*
//*	movera									*
//*	moverpor								*
//*	deslizara								*
//*	deslizarpor								*
//*	mover									*
//*	deslizar								*
//*	deslizar_vertical							*
//*										*
//*	escribir								*
//*	animatext								*
//*	animatext_aux								*
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *		



function init_var(){
layers = (document.layers)? true:false;
all = (document.all)? true:false;
DOM = (document.getElementById)? true:false;

ie4 = eval(!DOM&&all&&!layers);
ie5 = eval(DOM&&all&&!layers);
ns4 = eval(!DOM&&!all&&layers);
ns6 = eval(DOM&&!all&&!layers);
other = eval(!DOM&&!all&&!layers);
ns = eval(ns4||ns6);

//dimensiones navegador
ancho = (ns)? window.innerWidth : document.body.offsetWidth-20
alto = (ns)? window.innerHeight : document.body.offsetHeight-4


}


//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*				IMPLEMENTACIÓN					*
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

function scabreroLayer(){
init_var();
var obj="";
arg = scabreroLayer.arguments;
if (ns4) {
	for (var i=arg.length-1; i > 0; i--) obj += 'document.'+arg[i]+'.';
	obj += 'document.'+arg[0];
} 
if (ie4) obj = document.all[arg[0]];
if (ns6||ie5)  obj = document.getElementById(arg[0]);

//Propiedades generales
this.name = arg[0]+"object";
eval(this.name + "=this")
this.id = arg;
this.nocss = eval(obj);
if (ns4) this.css = this.nocss
else this.css = this.nocss.style;

this.css.xpos = parseInt(this.css.left);
this.css.ypos = parseInt(this.css.top);

//Propiedades de movimiento
this.puedemoverse = "true";
this.situacion = [this.css.xpos,this.css.ypos];
this.destino = this.situacion
this.destinofinal = this.destino;
this.m = 1;
this.n = 0;
this.after = null;
this.velocidad = 5;
this.aceleracion = 0;
this.intervalo = 20;

//Propiedades de escritura
this.contenido = "";
this.type_speed = 30;

//Metodos visibilidad
this.mostrar = mostrar;
this.esconder = esconder;

//Metodos movimiento
this.mover = mover;
this.movera = movera;
this.moverpor = moverpor;
this.deslizarpor = deslizarpor;
this.deslizara = deslizara;
this.deslizar = deslizar;
this.deslizar_vertical = deslizar_vertical;


//Metodos escritura
this.escribir = escribir;
this.animatext = animatext;
this.animatext_aux = animatext_aux;

//Cambio Imagen
this.cambiarimg = cambiarimg;
}



function mostrar(){
if (ns4) this.css.visibility = 'show'
else this.css.visibility = 'visible';
}

function esconder(){
if (ns4) this.css.visibility = 'hide'
else this.css.visibility = 'hidden';

}

function mover(){
	this.css.xpos = this.destino[0];
	this.css.left = this.destino[0];
	this.css.ypos = this.destino[1];
	this.css.top = this.destino[1];
	this.situacion = [this.css.xpos,this.css.ypos];
}

function moverpor(x,y){
if (this.puedemoverse){
this.destino = [this.situacion[0]+x,this.situacion[1]+y]
this.mover();
}
}

function movera(x,y){
if (this.puedemoverse){
this.destino = [x,y];
this.mover();
}
}

//FUNCIONES DESPLAZAR MIAS
function deslizarpor(x,y,after){
if (this.puedemoverse){
this.puedemoverse = "false";
this.destino = [x+this.situacion[0],y+this.situacion[1]];
if (after) this.after = after;
this.destinofinal = this.destino;
this.m = (this.destino[1]-this.situacion[1])/(this.destino[0]-this.situacion[0]);
this.n = this.situacion[1]-this.m*this.situacion[0];
this.deslizar();
}
}


function deslizara(x,y,after){
if (this.puedemoverse){
this.puedemoverse = "false";
this.destino = [x,y];
if (after) this.after = after;
this.destinofinal = this.destino;
this.m = (this.destino[1]-this.situacion[1])/(this.destino[0]-this.situacion[0]);
this.n = this.situacion[1]-this.m*this.situacion[0];
this.deslizar();
}
}

function deslizar(){
if ((this.destinofinal[0]<this.situacion[0]+2*this.velocidad)&&(this.destinofinal[0]>this.situacion[0]-2*this.velocidad)) this.deslizar_vertical()

else{ 

if (this.velocidad<=0) this.velocidad = this.velocidad-2*this.aceleracion
else this.velocidad = this.velocidad+this.aceleracion;
if (this.situacion[0]<this.destinofinal[0]-this.velocidad){
	this.destino = [this.situacion[0]+this.velocidad,this.m*this.situacion[0]+this.n];
	this.mover();
	setTimeout(this.name+".deslizar()",this.intervalo);
}

else{ 
	if (this.situacion[0]>this.destinofinal[0]+this.velocidad){
		this.destino = [this.situacion[0]-this.velocidad,this.m*this.situacion[0]+this.n];
		this.mover();
		setTimeout(this.name+".deslizar()",this.intervalo);
	}
	else{
		this.destino = this.destinofinal;
		this.mover();
		this.puedemoverse = "true";
		eval(this.after);
	}
}
}
}
function deslizar_vertical(){

if (this.velocidad<=0) this.velocidad = this.velocidad-2*this.aceleracion
else this.velocidad = this.velocidad+this.aceleracion;
if (this.situacion[1]<this.destinofinal[1]-this.velocidad){
	this.destino = [this.situacion[0],this.situacion[1]+this.velocidad];
	this.mover();
	setTimeout(this.name+".deslizar_vertical()",this.intervalo);
}

else{ 
	if (this.situacion[1]>this.destinofinal[1]+this.velocidad){
		this.destino = [this.situacion[0],this.situacion[1]-this.velocidad];
		this.mover();
		setTimeout(this.name+".deslizar_vertical()",this.intervalo);
	}
	else{
		this.destino = this.destinofinal;
		this.mover();
		this.puedemoverse = "true";
		eval(this.after);
	}
		
}
}
//FUNCIONES DE ESCRIBIR
function escribir(x){
if (ns4) {
		this.nocss.document.open();
		this.nocss.document.write(x);
		this.nocss.document.close();
		}
	else this.nocss.innerHTML = x;
this.contenido = x;
}


function animatext(texto,vel,after){
if (vel) this.type_speed = vel;
if (after) this.after = after;
this.animatext_aux(texto,"",0)
}

function animatext_aux(texto,x,i){
if (texto != x){
	i++;
	if (texto.substring(i-1,i) == "<"){
		while ((texto.substring(i-1,i) != ">")&(texto.substring(i,i+1) != "<")){
			i++;
		}
	}
	x = texto.substring(0,i);
	this.escribir(x);
	setTimeout(this.name+".animatext_aux(\""+texto+"\",\""+x+"\","+i+")",this.type_speed);
}

else{
	i=0;
	eval(this.after);
}
}

//Cambio Imagen

function cambiarimg(iname, imgsrc) {
	if(document.images) {
			if (ns4) this.nocss.document[iname].src = eval(imgsrc).src
				else document[iname].src = eval(imgsrc).src
		}
	}
