//author: Oscar Olsson (oo@aderagroup.com)

var n = (document.layers) ? 1:0
var ie = (document.all) ? 1:0

function layerLight(divname) {
	if (n) {
		eval("this.ref = document." + divname)
	}
	if (ie) {
		eval("this.ref = " + divname + ".style")
	}
	//Variabler
 	this.divname=divname
	this.x = parseInt(this.ref.left)
	this.y = parseInt(this.ref.top)

	//Metoder
	this.show=show
	this.hide=hide
	this.moveTo=moveTo
	this.moveBy=moveBy
	this.clipMe=clipMe
	this.clipBottom=clipBottom
	this.changeHeight=changeHeight
	this.isVisible=isVisible
}


function layer(divname, width) {

	if (n) {
		eval("this.ref = document." + divname)
	}
	if (ie) {
		eval("this.ref = " + divname + ".style")
	}
	//Variabler
 	this.divname=divname
	this.x = parseInt(this.ref.left)
	this.y = parseInt(this.ref.top)
	this.scrollspeedx=0
	this.scrollspeedy=0
	this.width=width
	this.part=1

	//Metoder
	this.show=show
	this.hide=hide
	this.clipWith=clipWith
	this.moveTo=moveTo
	this.moveBy=moveBy
	this.startScroll=startScroll
	this.stopScroll=stopScroll
}

function changeHeight(i) {
	if (ie) this.ref.height = i
}

function startScroll(dx,dy) {
	this.scrollspeedx=dx
	this.scrollspeedy=dy
}

function stopScroll() {
	this.scrollspeedx=0
	this.scrollspeedy=0
}

function moveTo(x,y) {
	this.x = x; this.ref.left = this.x
	this.y = y; this.ref.top = this.y
}

function moveBy(dx,dy) {
	this.x = this.x+dx; this.ref.left = this.x
	this.y = this.y+dy; this.ref.top = this.y
}

function clipBottom(value) {
	this.clipMe(0,menuWidth,value,0)
}

function clipMe(top,right,bottom,left) {
	if (ie) {
		str = "rect(" + top + "," + right + "," + bottom + "," + left + ")"
		eval(this.divname + ".style.clip=\"" + str + "\"")
	} else {
		eval("document." + this.divname + ".clip.right=" + right)
		eval("document." + this.divname + ".clip.left=" + left)
		eval("document." + this.divname + ".clip.top=" + top)
		eval("document." + this.divname + ".clip.bottom=" + bottom)
	}		
}
	
function clipWith(obj) {
	var right, top, bottom, left, str
	this.clipwidthobj = obj
	if (obj.cliptype=="rectangle") {
		left = obj.x - this.x
		right = obj.x + obj.width - this.x
		top= obj.y - this.y
		bottom=obj.y+obj.height - this.y
		if (left<0) left=0
		if (right>this.width) {right=this.width;}
		if (top<0) top=0
		if (top>this.height) top=this.height
		if (ie) {
			str = "rect(" + top + "," + right + "," + bottom + "," + left + ")"
			eval(this.divname + ".style.clip=\"" + str + "\"")
		} else {
			eval("document." + this.divname + ".clip.right=" + right)
			eval("document." + this.divname + ".clip.left=" + left)
			eval("document." + this.divname + ".clip.top=" + top)
			eval("document." + this.divname + ".clip.bottom=" + bottom)
		}			
	}
}

function clipWindow(x, y, width, height) {
	this.x=x
	this.y=y
	this.width=width
	this.height=height
	this.cliptype="rectangle"
}

function show() {
	if (n) this.ref.visibility = "show"
	else if (ie) this.ref.visibility = "visible"
}
	
function hide() {
	if (n) this.ref.visibility = "hide"	
	else if (ie) this.ref.visibility = "hidden"
}

function showDIV(divname) {
	if (n) {
		eval("document."+divname+".visibility=\"show\"")
	} else if (ie) {
		eval(divname+".style.visibility=\"visible\"")
	}
}

function hideDIV(divname) {
	if (n) {
		eval("document."+divname+".visibility=\"hide\"")
	} else if (ie) {
		eval(divname+".style.visibility=\"hidden\"")
	}
}

function isVisible() {
	if (n) {
		if (this.ref.visibility=="hide") return(false)
		else if (this.ref.visibility=="show") return(true)
		else return(-1)
	} else if (ie) { 
		if (this.ref.visibility=="hidden") return(false)
		else if (this.ref.visibility=="visible") return(true)
		else return(-1)
	}
}