//var windowWidth;
//var windowHeight;
//var origWidth;
//var origHeight;
//var xcenter;
//var ycenter;
var prefix;
var suffix;
var leftRef;
var topRef;
var is;
function BrowserCheck() {
	//var ag = navigator.userAgent;
	//alert(ag);
        var b = navigator.appName
        if (b=="Netscape") this.b = "ns"
        else if (b=="Microsoft Internet Explorer") this.b = "ie"
        else this.b = b
        this.v = parseFloat(navigator.appVersion)
        this.ns = (this.b=="ns" && this.v>=4)
        this.ns4 = (this.b=="ns" && this.v>=4 && this.v<5)
        this.ns6 = (this.b=="ns" && this.v>=5)
        this.ie = (this.b=="ie" && this.v>=4)
        this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
        this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
        this.opera = (navigator.userAgent.toLowerCase().indexOf('opera')!=-1)
		if (this.opera) this.ie = true
        if (this.ie5) this.v = 5
        this.min = (this.ns||this.ie)
	if (this.ns4) {
//		windowWidth=window.innerWidth
//		windowHeight=window.innerHeight
		prefix = 'document.'
		suffix = ''
		leftRef = '.pageX'
		topRef = '.pageY'
	}
	if (this.ns6 || this.opera) {
//		windowWidth=window.innerWidth
//		windowHeight=window.innerHeight
		prefix = 'document.getElementById("'
		suffix = '").style'
		leftRef = '.left'
		topRef = '.top'
	}
	if (this.ie) {
//		windowWidth = document.body.clientWidth
//		windowHeight = document.body.clientHeight
		prefix = 'document.all.'
		suffix = '.style'
		leftRef = '.pixelLeft'
		topRef = '.pixelTop'
	}	
}

// FUNCTIONS BEGIN HERE

// position()
// getX()
// setX()
// getY()
// setY()
// getZ()
// setZ()
// swapZ()
// show()
// hide()
// getWidth()
// getHeight()
// clip()
// changeImage()

// void position(string id, int x, int y);
function position(id, x, y){
	//alert('position: thing is '+id);
	setX(id, x);
	setY(id, y);
}

// int getX(string id);
function getX(id){
	eval("x = "+prefix+id+suffix+leftRef);
	x = parseInt(x);
	return x;
}

// void setX(string id, int x);
function setX(id, x){
	x = parseInt(x);
	eval (prefix+id+suffix+leftRef+" = "+x);// alert (prefix+id+suffix+leftRef+" = "+x);
}

// int getY(string id);
function getY(id){
	eval("y = "+prefix+id+suffix+topRef);
	y = parseInt(y);
	return y;
}

// void setY(string id, int y);
function setY(id, y){
	eval (prefix+id+suffix+topRef+" = "+y);// alert (prefix+id+suffix+topRef+" = "+y);
}

// int getZ(string id);
function getZ(id){
	eval ("zindex = "+prefix+id+suffix+".zIndex");
	return zindex;
}

// void setZ(string id, int zindex);
function setZ(id, zindex){
	eval (prefix+id+suffix+".zIndex = "+zindex);
}

// void swapZ(string id1, string id2);
function swapZ(id1, id2){
}

// void show(string id);
function show(id){
	eval(prefix+id+suffix+'.visibility = "visible"');
}

// void hide(string id);
function hide(id){
	eval(prefix+id+suffix+'.visibility = "hidden"');
}

// string getVisibility(string id)
function getVisibility(id){
	eval("visibility = "+prefix+id+suffix+".visibility");
	if (visibility == "show"){
		visibility = "visible";
	}
	if (visibility == "hide"){
		visibility = "hidden";
	}
	return visibility;
}

// int getWidth(string id);
function getWidth(id){
	if (is.ns4){
		width = document.layers[id].clip.width;
		}
	else if (is.ns6 || is.opera) { 
		width = document.getElementById(id).offsetWidth;
	} 
	else{
		eval ("width = "+id+".offsetWidth");
		}
	return width;
}

// int getHeight(string id);
function getHeight(id){
	if (is.ns4) {
		eval ("height = document.layers."+id+".clip.height");
	} 
	else if (is.ns6 || is.opera) { 
		height = document.getElementById(id).offsetHeight;
	} 
	else {
		eval ("height = "+id+".offsetHeight");
	}
	return height;
}

// void clip(string id, int top, int right, int bottom, int left);
function clip(id, top, right, bottom, left){
	if (is.ie || is.ns6 || is.opera) {
		eval(prefix+id+suffix+".clip = 'rect("+top+"px "+right+"px "+bottom+"px "+left+"px)'");
	} 
	else { // ns4
		eval (prefix+id+suffix+".clip.top = "+top);
		eval (prefix+id+suffix+".clip.bottom = "+bottom);
		eval (prefix+id+suffix+".clip.right = "+right);
		eval (prefix+id+suffix+".clip.left = "+left);
	}
}

// void changeImage(string id, string imgname, string imgobj);
function changeImage(id, imgname, imgobj){
	if (is.ns4){
		eval ("document.layers."+id+".document."+imgname+".src = "+imgobj+".src");
	}
	else{
		eval ("document."+imgname+".src = "+imgobj+".src");
	}
}

// void positionandshow(string layerName, int x-coord, int y-coord);
function positionandshow(layerName,xcoord,ycoord) {
	//alert('positionandshow: thing is '+layerName);
	position(layerName,xcoord,ycoord);
	show(layerName);
//alert('xcoord '+xcoord+' ycoord '+ycoord+' layerName '+layerName);
}
	
// void slide(string thing, int finalx, int finaly, int velocidad, int intervalo, string fn) {
function slide(thing,finalx,finaly,velocidad,intervalo,fn) {
	//alert('slide is called');
	if (finalx==null) finalx=getX(thing);  //sets target x to the current x (i.e. stays the same)
	if (finaly==null) finaly=getY(thing);  //sets target y to the current y
	frenadoloop(thing,finalx,finaly,velocidad,intervalo,fn);
}
var testcounter = 0;
function frenadoloop(thing,finalx,finaly,velocidad,intervalo,fn) {
	//alert('frenadoloop is called');
	current_x = getX(thing);
	var target_x=Math.round((finalx+velocidad*current_x)/(velocidad+1));
	current_y = getY(thing);
	target_y=Math.round((finaly+velocidad*current_y)/(velocidad+1));
	position(thing,target_x,target_y);
	testcounter++;
	if ( (current_x==target_x&&current_y==target_y) || testcounter>100) {
	//if ((Math.abs(finaly-target_y)<1) && (Math.abs(finalx-target_x)<1) ) {
		position(thing,finalx,finaly);
		if (fn!=null) eval(fn);
		testcounter=0;
	}
	else setTimeout("frenadoloop('"+thing+"',"+finalx+","+finaly+","+velocidad+","+intervalo+",'"+fn+"')",intervalo);
}


