drag = false


function exist(obj) {
	if (typeof(obj)!='undefined') return true
	else return false
}

function objInit(nestRef,id) {
	// define methods
	this.getClip = objGetClip
	this.setClip = objSetClip
	this.moveTo = objMoveTo
	this.moveBy = objMoveBy
	this.resizeTo = objResizeTo
	this.inside = objInside
	this.toggle = objToggle
	
	// define values
	this.id = id
	this.active = false

	if (is.dom) {
		this.obj = document.getElementById(id)
		this.css = this.obj.style
		this.x = parseInt(this.obj.offsetLeft)
		this.y = parseInt(this.obj.offsetTop)
		this.w = parseInt(this.obj.offsetWidth)
		this.h = parseInt(this.obj.offsetHeight)
	} else {
		this.obj = (is.ns4)? eval(nestRef).layers[id] : document.all[id]
		this.css = (is.ns4)? this.obj : this.obj.style
		this.x = parseInt(this.css.left)
		this.y = parseInt(this.css.top)
		this.w = (is.ns4)? parseInt(this.obj.document.width) : parseInt(this.obj.style.pixelWidth)
		this.h = (is.ns4)? parseInt(this.obj.document.height) : parseInt(this.obj.scrollHeight)
	}
	this.orgX = this.x
	this.orgY = this.y
	
	this.objRef = id + "Object"
	eval(this.objRef + "=this")

	
	this.clipT = this.getClip(0)
	this.clipR = this.getClip(1)
	this.clipB = this.getClip(2)
	this.clipL = this.getClip(3)
	this.clipH = this.clipB - this.clipT
	this.clipW = this.clipR - this.clipL
}
	
function objGetClip(which) {
	if (which=='t') which = 0
	if (which=='r') which = 1
	if (which=='b') which = 2
	if (which=='l') which = 3
	
	if (is.ns4) {
		strClip = new Array(this.obj.clip.top,this.obj.clip.right,this.obj.clip.bottom,this.obj.clip.left)
	} else {
		strClip = this.obj.style.clip
		strClip = strClip.substring(strClip.indexOf('(')+1, strClip.indexOf(')')).split(' ')
	}
	return parseInt(strClip[which])
}

function objSetClip(t,r,b,l) {
	if (is.ns4) {
		this.obj.clip.top = t
		this.obj.clip.right = r
		this.obj.clip.bottom = b
		this.obj.clip.left = l
	} else {
		strClip = 'rect('+ t +'px '+ r +'px '+ b +'px '+ l +'px)'
		this.obj.style.clip = strClip
	}
}

function objMoveTo(x,y) {
	this.x = x
	this.y = y
	this.css.left = this.x
	this.css.top = this.y
}

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

function objResizeTo(w,h) {
	
	this.w = w
	this.h = h
	this.css.width = this.w
	this.css.height = this.h
	this.setClip(0,w,h,0)
	
}

function objInside(x,y,fuzz) {
	if (!fuzz) fuzz=0
	l = this.x + parseValue(this.getClip('l'))
	clipW = parseValue(this.getClip('r')) - parseValue(this.getClip('l'))
	r = l + ((clipW!=0)? clipW : this.w)
	t = this.y + parseValue(this.getClip('t'))
	clipH = parseValue(this.getClip('b'))-parseValue(this.getClip('t'))
	b = t + ((clipH!=0)? clipH : this.h)
	return (inside(t,r,b,l,x,y,fuzz))? true:false
}

function inside(t,r,b,l,x,y,fuzz) {
	if (!fuzz) fuzz=0
	if (x>l-fuzz && x<r+fuzz && y>t-fuzz && y<b+fuzz) return true
	else return false
}


function objToggle(which) {
	if (!which) which = (this.css.visibility=='show'||this.css.visibility=='visible')? 'hide':'show'
	this.css.visibility = (is.ns4)? ((which=='show')?'show':'hide') : ((which=='show')?'visible':'hidden')
}

function parseValue(n) {
	if (n.toString()=='NaN') return 0
	else return parseInt(n)
}