var IW= 0;
var IH= 0;
var IMGW= 100;
var IMGH= 60;
var LSAFETY= 20;
var TSAFETY= 20;
var PX= 0;
var PY= 0;
var ns4;
var ie4;

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function DynLayer(id,nestref) {
	if (ns4) {
		this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
		this.x = this.css.left
		this.y = this.css.top
	}
	else if (ie4) {
		this.css = document.all[id].style
		this.x = this.css.pixelLeft
		this.y = this.css.pixelTop
	}
	
	this.moveTo = DynLayerMoveTo
	this.moveBy = DynLayerMoveBy
	this.show = DynLayerShow
	this.hide = DynLayerHide
	this.addon = DynLayerAddon
	this.addon(id,nestref)
}
function DynLayerMoveTo(x,y) {
	if (x!=null) {
		this.x = x
		this.css.left = this.x
	}
	if (y!=null) {
		this.y = y
		this.css.top = this.y
	}
}
function DynLayerMoveBy(x,y) {
	this.moveTo(this.x+x,this.y+y)
}
function DynLayerShow() {
	this.css.visibility = (ns4)? "show" : "visible"
}
function DynLayerHide() {
	this.css.visibility = (ns4)? "hide" : "hidden"
}
function DynLayerAddon(id,nestref) {
	this.obj = id + "DynLayer"
	eval(this.obj + "=this")
}
function Path(dynlayer,name,arrayX,arrayY) {
	this.dynlayer = dynlayer.obj
	this.name = name
	this.arrayX = arrayX
	this.arrayY = arrayY
	this.loop = false
	this.speed = 30
	this.fn = null
	this.play = PathPlay
	this.slide = PathSlide
	this.pause = PathPause
	this.stop = PathStop
}
function PathPlay(loop,speed,fn) {
	if (this.active) return
	this.loop = (loop)? loop : false
	this.speed = (speed)? speed : 30
	this.fn = (fn)? fn : null
	if (!this.paused) this.i = 0
	this.active = true
	this.paused = false
	eval(this.dynlayer+"."+this.name+".slide()")
}
function PathSlide() {
	if (this.active && this.i < this.arrayX.length) {
		eval(this.dynlayer+".moveTo("+this.arrayX[this.i]+","+this.arrayY[this.i]+")")
		this.i += 1
		setTimeout(this.dynlayer+"."+this.name+".slide()",this.speed)
	}
	else if (!this.paused) {
		this.i = 0
		if (this.loop && this.active) setTimeout(this.dynlayer+"."+this.name+".slide()",this.speed)
		else {
			this.active = false
			eval(this.fn)
		}
	}
}
function PathPause() {
	if (this.active) {
		this.active = false
		this.paused = true
	}
}
function PathStop() {
	this.active = false
	this.paused = false
}

function posicion(){

if (ie4) {		
	IH= document.body.clientHeight;
	 IW= document.body.clientWidth;
	 PX= document.body.scrollLeft;
	 PY= document.body.scrollTop;
}	
if (ns4) {
          
	  IH= window.innerHeight
	  IW= window.innerWidth
	  PY= window.pageYOffset
	  PX= window.pageXOffset
	}
}

function init() {
	
	posicion();
	square = new DynLayer("squareDiv")
	square.path1 = new Path(square,"path1",
	// x values
	new Array(IW+PX-(IMGW+LSAFETY),IW+PX-(IMGW+LSAFETY)),
	// y values
	new Array(IH+PY-(IMGH+TSAFETY),IH+PY-(IMGH+TSAFETY)))
	square.path1.play(false,30)
	

}
