// Comprobación del Browser
function CompruebaBrowser() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}
br = new CompruebaBrowser()

// Librería para manejar capas

function ObjetoCapa(id,antref,frame) {
	if (!br.ns5 && !ObjetoCapa.activa && !frame) IniciaCapas()
	this.frame = frame || self
	if (br.ns) {
		if (br.ns4) {
			if (!frame) {
				if (!antref) var antref = ObjetoCapa.antRefArray[id]
				if (!ProbarCapa(id,antref)) return
				this.css = (antref)? eval("document."+antref+".document."+id) : document.layers[id]
			}
			else this.css = (antref)? eval("frame.document."+antref+".document."+id) : frame.document.layers[id]
			this.elm = this.event = this.css
			this.doc = this.css.document
		}
		else if (br.ns5) {
			this.elm = document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
		}
		this.x = this.css.left
		this.y = this.css.top
		this.w = this.css.clip.width
		this.h = this.css.clip.height
	}
	else if (br.ie) {
		this.elm = this.event = this.frame.document.all[id]
		this.css = this.frame.document.all[id].style
		this.doc = document
		this.x = this.elm.offsetLeft
		this.y = this.elm.offsetTop
		this.w = (br.ie4)? this.css.pixelWidth : this.elm.offsetWidth
		this.h = (br.ie4)? this.css.pixelHeight : this.elm.offsetHeight
	}
	this.posx=this.x
	this.posy=this.y
	this.id = id
	this.antref = antref
	this.obj = id + "ObjetoCapa"
	eval(this.obj + "=this")
// Funciones
this.inicializaDeslizar = CapaInicializaDeslizar
this.deslizarA = CapaDeslizarCapaA
this.deslizarDesde = CapaDeslizarCapaDesde
this.comenzarDeslizar = CapaComienzoDeslizar
this.deslizar = CapaDeslizar
this.enDeslizamiento = new Function()
this.enFinDeslizamiento = new Function()
this.moverA = CapaMoverA
this.moverDesde = CapaMoverDesde
this.mostrar = MostrarCapa
this.ocultar = OcultarCapa
this.clipInicializa = CapaClipInicializa
this.clipA = CapaClipA
this.clipDesde = CapaClipDesde
this.clipValores = CapaClipValores
this.escribe = EscribeCapa
this.clipAbajo = new Function;
this.clipArriba = new Function;
}
function CapaMoverA(x,y) {
	if (x!=null) {
		this.x = x
		if (br.ns) this.css.left = this.x
		else this.css.pixelLeft = this.x
	}
	if (y!=null) {
		this.y = y
		if (br.ns) this.css.top = this.y
		else this.css.pixelTop = this.y
	}
}
function CapaMoverDesde(x,y) {
	this.moverA(this.x+x,this.y+y)
}
function MostrarCapa() {
	this.css.visibility = (br.ns4)? "show" : "visible"
}
function OcultarCapa() {
	this.css.visibility = (br.ns4)? "hide" : "hidden"
}
ObjetoCapa.antRefArray = new Array()
ObjetoCapa.refArray = new Array()
ObjetoCapa.refArray.i = 0
ObjetoCapa.activa = false
ProbarCapa = new Function('return true')

// Inicializa Capas
function IniciaCapas(antref) {
	if (!ObjetoCapa.activa) ObjetoCapa.activa = true
	if (br.ns) {
		if (antref) ref = eval('document.'+antref+'.document')
		else {antref = ''; ref = document;}
		for (var i=0; i<ref.layers.length; i++) {
			var divname = ref.layers[i].name
			ObjetoCapa.antRefArray[divname] = antref
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new ObjetoCapa("'+divname+'","'+antref+'")')
			}
			if (ref.layers[i].document.layers.length > 0) {
				ObjetoCapa.refArray[ObjetoCapa.refArray.length] = (antref=='')? ref.layers[i].name : antref+'.document.'+ref.layers[i].name
			}
		}
		if (ObjetoCapa.refArray.i < ObjetoCapa.refArray.length) {
			IniciaCapas(ObjetoCapa.refArray[ObjetoCapa.refArray.i++])
		}
	}
	else if (br.ie) {
		for (var i=0; i<document.all.tags("DIV").length; i++) {
			var divname = document.all.tags("DIV")[i].id
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new ObjetoCapa("'+divname+'")')
			}
		}
	}
	return true
}


// Movimiento de capas
function CapaDeslizarCapaA(endx,endy,inc,vel,fn) {
	if (endx==null) endx = this.x
	if (endy==null) endy = this.y
	var distx = endx-this.x
	var disty = endy-this.y
	this.comenzarDeslizar(endx,endy,distx,disty,inc,vel,fn)
}
function CapaDeslizarCapaDesde(distx,disty,inc,vel,fn) {
	var endx = this.x + distx
	var endy = this.y + disty
	this.comenzarDeslizar(endx,endy,distx,disty,inc,vel,fn)
}
function CapaComienzoDeslizar(endx,endy,distx,disty,inc,vel,fn) {
	if (this.deslizamientoActivo) return
	if (!inc) inc = 10
	if (!vel) vel = 20
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc
	if (num==0) return
	var dx = distx/num
	var dy = disty/num
	if (!fn) fn = null
	this.deslizamientoActivo = true
	this.deslizar(dx,dy,endx,endy,num,1,vel,fn)
}
function CapaDeslizar(dx,dy,endx,endy,num,i,vel,fn) {
	if (!this.deslizamientoActivo) return
	if (i++ < num) {
		this.moverDesde(dx,dy)
		this.enDeslizamiento()
		if (this.deslizamientoActivo) setTimeout(this.obj+".deslizar("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+vel+",\""+fn+"\")",vel)
		else this.enFinDeslizamiento()
	}
	else {
		this.deslizamientoActivo = false
		this.moverA(endx,endy)
		this.enDeslizamiento()
		this.enFinDeslizamiento()
		eval(fn)
	}
}
function CapaInicializaDeslizar() {}


// Ocultamos parte de la capa
function CapaClipInicializa(clipTop,clipRight,clipBottom,clipLeft) {
	if (br.ie) {
		if (arguments.length==4) this.clipTo(clipTop,clipRight,clipBottom,clipLeft)
		else if (br.ie4) this.clipTo(0,this.css.pixelWidth,this.css.pixelHeight,0)
	}
}
function CapaClipA(t,r,b,l) {
	if (t==null) t = this.clipValues('t')
	if (r==null) r = this.clipValues('r')
	if (b==null) b = this.clipValues('b')
	if (l==null) l = this.clipValues('l')
	if (br.ns) {
		this.css.clip.top = t
		this.css.clip.right = r
		this.css.clip.bottom = b
		this.css.clip.left = l
	}
	else if (br.ie) this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}
function CapaClipDesde(t,r,b,l) {
	this.clipA(this.clipValores('t')+t,this.clipValores('r')+r,this.clipValores('b')+b,this.clipValores('l')+l)
}
function CapaClipValores(which) {
	if (br.ie) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="t") return (br.ns)? this.css.clip.top : Number(clipv[0])
	if (which=="r") return (br.ns)? this.css.clip.right : Number(clipv[1])
	if (which=="b") return (br.ns)? this.css.clip.bottom : Number(clipv[2])
	if (which=="l") return (br.ns)? this.css.clip.left : Number(clipv[3])
}

// Escritura en capas
function EscribeCapa(texto) {
	if (br.ns) {
		this.doc.open()
		this.doc.write(texto)
		this.doc.close()
	}
	else if (br.ie) {
		this.event.innerHTML = texto
	}
}

// Funcion CSS para escribir estilos con una funcion
function css(id,left,top,width,height,color,vis,z,other) {
	if (id=="START") return '<STYLE TYPE="text/css">\n'
	else if (id=="END") return '</STYLE>'
	var texto = (left!=null && top!=null)? '#'+id+' {position:absolute; left:'+left+'px; top:'+top+'px;' : '#'+id+' {position:relative;'
	if (arguments.length>=4 && width!=null) texto += ' width:'+width+'px;'
	if (arguments.length>=5 && height!=null) {
		texto += ' height:'+height+'px;'
		if (arguments.length<9 || other.indexOf('clip')==-1) texto += ' clip:rect(0px '+width+'px '+height+'px 0px);'
	}
	if (arguments.length>=6 && color!=null) texto += (br.ns)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'
	if (arguments.length>=7 && vis!=null) texto += ' visibility:'+vis+';'
	if (arguments.length>=8 && z!=null) texto += ' z-index:'+z+';'
	if (arguments.length==9 && other!=null) texto += ' '+other
	texto += '}\n'
	return texto
}
function escribeCSS(texto,muestraAlert) {
	texto = css('START')+texto+css('END')
	document.write(texto)
	if (muestraAlert) alert(texto)
}

function DesplegarMenu(tdesp,rdesp,bdesp,ldesp,tini,rini,bini,lini,tfin,rfin,bfin,lfin,velocidad) {
if ((bini>bfin && bdesp>0) || (bini<bfin && bdesp <0)) {return}
tini+=tdesp;
rini+=rdesp;
bini+=bdesp;
lini+=ldesp;
this.clipA(tini,rini,bini,lini);
setTimeout(this.obj+".clipAbajo("+tdesp+","+rdesp+","+bdesp+","+ldesp+","+tini+","+rini+","+bini+","+lini+","+tfin+","+rfin+","+bfin+","+lfin+","+velocidad+");",velocidad);
}