objVisor.ie = document.all ? 1 : 0
objVisor.ns4 = document.layers ? 1 : 0
objVisor.dom = document.getElementById ? 1 : 0

objVisor.registro = []
objVisor.minRes = 10
objVisor.aniLen=400

function objVisor(id, strAncho, strAlto, intPosX, intPosY, intEfecto)
{
	if (!intPosX) intPosX = 0
	if (!intPosY) intPosY = 0
	if (objVisor.ie || objVisor.ns4 || objVisor.dom)
	{
		this.abierto = false
		this.id = id
		this.reloj = false
		this.lastTime = 0
		this.scrollY = intPosY
		this.scrollX = intPosX
		this.efecto=intEfecto
		this.gRef = "objVisor_"+id
		this.contenedor = objVisor.dom ? document.getElementById(id + '_con') : objVisor.ie ? document.all[id + '_con'] : document.layers[id + '_con']
		this.contenido = objVisor.dom ? document.getElementById(id + '_cnt') : objVisor.ie ? document.all[id + '_cnt'] : document.layers[id + '_cnt']
		this.clipX=strAncho?strAncho:0 
		this.clipY=strAlto?strAlto:0
		eval(this.gRef+"=this")
		s='<style type="text/css">'
		s+='#' + this.id + '_con { overflow:hidden; width:' + ((this.clipX)?this.clipX+'px':'100%') +'; height:' + this.clipY + 'px; rect(0 ' + this.clipX + ' ' + this.clipY + ' 0)}'
		s+='#' + this.id + '_cnt { position:relative; left:' + (-intPosX) + 'px; top:' + (-intPosY) + 'px; }'
		s+='</style>'
		document.write(s)
		objVisor.registro[id] = this
	}
}

objVisor.prototype.abre = function()
{
	this.clipX=this.contenedor.offsetWidth
	this.clipY=this.contenedor.offsetHeight
	this.contenedor.style.clip='rect(0 ' + this.clipX + ' ' + this.clipY + ' 0)'
	this.docW = Math.max(objVisor.ns4 ? this.contenido.document.width : this.contenido.offsetWidth, this.clipX)
	this.docH = Math.max(objVisor.ns4 ? this.contenido.document.height : this.contenido.offsetHeight, this.clipY)
	this.scrollW = this.docW - this.clipX
	this.scrollH = this.docH - this.clipY
	this.abierto = true
	this.scrollX = Math.max(Math.min(this.scrollX, this.scrollW),0)
	this.scrollY = Math.max(Math.min(this.scrollY, this.scrollH),0)
	this.mueve(this.scrollX, this.scrollY)
}

objVisor.prototype.scroll = function()
{
	this.reloj = window.setTimeout(this.gRef + ".scroll()", objVisor.minRes)
	var nt = (new Date()).getTime()
	var d = Math.round((nt - this.lastTime) / 1000 * this.speed)
	if (d > 0)
	{
		var intPosX = d * this.fx + this.scrollX
		var intPosY = d * this.fy + this.scrollY
		var xOut = (intPosX >= this.scrollX && intPosX >= this.stopH) || (intPosX <= this.scrollX && intPosX <= this.stopH)
		var yOut = (intPosY >= this.scrollY && intPosY >= this.stopV) || (intPosY <= this.scrollY && intPosY <= this.stopV)
		if (nt - this.lastTime != 0 && ((this.fx == 0 && this.fy == 0) || (this.fy == 0 && xOut) || (this.fx == 0 && yOut) || (this.fx != 0 && this.fy != 0 && xOut && yOut)))
		{
				this.mueve(this.stopH, this.stopV)
				this.endScroll()
		}
		else
		{
			this.mueve(intPosX, intPosY)
			this.lastTime = nt
		}
	}
}

objVisor.prototype.endScroll = function()
{
	if (this.abierto)
	{
		window.clearTimeout(this.reloj)
		this.reloj = 0;
		this.speed = 0
	}
}

objVisor.prototype.mueve = function(intPosX, ny)
{ 
	intPosX = Math.min(Math.max(intPosX, 0), this.scrollW)
	ny = Math.min(Math.max(ny, 0), this.scrollH)
	this.scrollX = intPosX
	this.scrollY = ny
	if (objVisor.ns4)this.contenido.moveTo(-intPosX, -ny)
	else
	{
		this.contenido.style.left = -intPosX + "px"
		this.contenido.style.top = -ny + "px"
	}
}

objVisor.mueve = function(id, stopH, stopV)
{
	var obj = objVisor.registro[id]

	if (!obj.abierto) obj.abre()
	switch(obj.efecto)
	{
		case 0:
			obj.mueve(stopH, stopV)

		case 1:
			if (stopH != obj.scrollX || stopV != obj.scrollY)
			{
				if (obj.reloj) window.clearTimeout(obj.reloj)
				obj.lastTime = (new Date()).getTime()
				var dx = Math.abs(stopH - obj.scrollX)
				var dy = Math.abs(stopV - obj.scrollY)
				var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))
				obj.fx = (stopH - obj.scrollX) / (dx + dy)
				obj.fy = (stopV - obj.scrollY) / (dx + dy)
				obj.stopH = stopH
				obj.stopV = stopV
				obj.speed = d / objVisor.aniLen * 1000
				window.setTimeout(obj.gRef + ".scroll()", objVisor.minRes)
			}
	}
		
}

/*objVisor.mueveDir = function(id, intDirX, intDirY)
{
	var obj = objVisor.registro[id]

	alert(obj.contenedor.offsetWidth)
	obj.mueve(obj.scrollX-, obj.scrollY)
}*/