//preload pictures
function preload(imgObject,imgSource) {
	if (document.images) {
		eval(imgObject+' = new Image()')
		eval(imgObject+'.src = "'+imgSource+'"')
	}
}

function stat(text) {
	window.status = text;
}

//rollover picture
function change(obj,imgName,imgObject) {

	if (document.images) {
		if (document.layers && obj!=null) 
			eval('document.'+obj+'.document.images["'+imgName+'"].src = '+imgObject+'.src')
		else
			eval('document.images["'+imgName+'"].src = '+imgObject+'.src')
	}
	window.status=''
}

//open popup
function openPopup(href,name,left,top,width,height) {
	eval('win'+ name +'=window.open("' + href + '", "win' + name + '", "left=' + left + ',top=' + top + ',height=' + height + ',width=' + width + '");');
	eval('win'+ name +'.focus()')	
}

function openPopupResizable(href,name,left,top,width,height) {
	eval('win'+ name +'=window.open("' + href + '", "win' + name + '", "left=' + left + ',top=' + top + ',height=' + height + ',width=' + width + ',scrollbars,resizable");');
	eval('win'+ name +'.focus()')	
}

function show(id) {
	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.visibility = "visible"
}

function hide(id) {
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.visibility = "hidden"
}




function initObj(id) {

	this.frame = self
	if (is.ns4) {
		this.elm = this.event = this.css
		this.css = document.layers[id]
		this.doc = this.css.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 (is.ie || is.ns5) {
		if (is.ie)
			this.elm = this.event = this.frame.document.all[id]
		else 
			this.elm = this.event = this.frame.document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
			this.x = this.elm.offsetLeft
			this.y = this.elm.offsetTop
			this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth
			this.h = (is.ie4)? this.css.pixelHeight : this.elm.offsetHeight
	}
	this.id = id
	this.obj = id + "eLayer"
	eval(this.obj + "=this")

	this.write = ObjWrite
	this.moveBy = ObjMoveBy
	this.moveTo = ObjMoveTo
	this.show = ObjShow
	this.hide = ObjHide
	this.slideInit = ObjSlideInit
	this.slideTo = ObjSlideTo
	this.slideBy = ObjSlideBy
	this.slideStart = ObjSlideStart
	this.slide = ObjSlide
	this.onSlide = new Function()
	this.onSlideEnd = new Function()

}


//div write
function ObjWrite(html) {
	if (is.ns4) {
		this.doc.open()
		this.doc.write(html)
		this.doc.close()
	}
	else if (is.ie||is.ns5) {
		this.event.innerHTML = html
	}
}

function ObjMoveTo(x,y) {
	if (x!=null) {
		this.x = x
		if (is.ns4) this.css.left = this.x
		else if (is.ie) this.css.pixelLeft = this.x
		else if (is.ns5) this.css.left = Math.floor(this.x) + 'px'
	}
	if (y!=null) {
		this.y = y
		if (is.ns4) this.css.top = this.y
		else if (is.ie) this.css.pixelTop = this.y
		else if (is.ns5) this.css.top = Math.floor(this.y) + 'px'
	}
}

function ObjMoveBy(x,y) {
	this.moveTo(this.x+x,this.y+y)
}

function bObjSlide(xy,direction,step,speed) {
	
	if (this.slideActive) return	
	switch(direction) {
	case 'l':
		if (this.x > xy) this.x -= step
		break;
	case 'r':
		if (this.x < xy) this.x += step
		break;
	case 't':
		if (this.y > xy) this.y -= step
		break;
	case 'b':
		if (this.y < xy) this.y += step
		break;
	}
	this.css.left = this.x
	this.css.top = this.y
	setTimeout(this.obj+".slide("+xy+",'"+direction+"',"+step+","+speed+")",speed)
}


// Slide Methods
function ObjSlideTo(endx,endy,inc,speed,fn) {
	if (endx==null) endx = this.x
	if (endy==null) endy = this.y
	var distx = endx-this.x
	var disty = endy-this.y
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function ObjSlideBy(distx,disty,inc,speed,fn) {
	var endx = this.x + distx
	var endy = this.y + disty
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function ObjSlideStart(endx,endy,distx,disty,inc,speed,fn) {
	if (this.slideActive) return
	if (!inc) inc = 10
	if (!speed) speed = 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.slideActive = true
	this.slide(dx,dy,endx,endy,num,1,speed,fn)
}
function ObjSlide(dx,dy,endx,endy,num,i,speed,fn) {
	if (!this.slideActive) return
	if (i++ < num) {
		this.moveBy(dx,dy)
		this.onSlide()
		if (this.slideActive) setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed)
		else this.onSlideEnd()
	}
	else {
		this.slideActive = false
		this.moveTo(endx,endy)
		this.onSlide()
		this.onSlideEnd()
		eval(fn)
	}
}
function ObjSlideInit() {}

function ObjShow() {
	this.css.visibility = (is.ns4)? "show" : "visible"
}

function ObjHide(obj) {
	this.css.visibility = (is.ns4)? "hide" : "hidden"
}


// BrowserCheck Object
function BrowserCheck() {
	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.ns = (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)
}
is = new BrowserCheck()
