//»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
//--------------------------------------------------------------------------
// JavaScript Drag Constructor for Objects in Dynamic Html.
//
// Usage:
// Use with Mouse Event Functions:
// drag.mouseDown(x,y)
// Methods:
// add() external: makes object dragable
// remove() external: makes object no longer dragable
// mouseDown(x,y) internal: if object, this.obj = object, this.active = true, set offsets
// mouseMove(x,y) internal: if this.active, this.obj.moveTo(x-offset,y-offset)
// mouseUp() internal: this.active = false
// within() internal: checks if mouse is pointing at object
// Bugs:
// None?
// Notes:
// drag is initialized as new Drag() and is an object of of
// type "Drag". Use add() to add objects to the drag object.
// Use remove() to remove objects from the drag object.
// "drag = new Drag()", this initiaizes drag for use in mouse
// constructor as drag.object.
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
ns4 = (document.layers)?1:0
ie4 = (document.all)?1:0
function Drag() {
this.obj = null
this.array = new Array()
this.active = false
this.offsetX = 0
this.offsetY = 0
this.zIndex = 0
this.resort = true
this.add = drag_add
this.remove = drag_remove
this.mouseDown = mouse_down
this.mouseMove = mouse_move
this.mouseUp = mouse_up
}
drag = new Drag()
function drag_add() {
for (var i=0; i=0;i--) {
var layer = this.array[i]
if (within(x,y,layer.x,layer.x+layer.w,layer.y,layer.y+layer.h)) {
this.obj = this.array[i]
this.offsetX = x-this.obj.x
this.offsetY = y-this.obj.y
this.active = true
break
}
}
if (this.active && this.resort) {
this.obj.css.zIndex = this.zIndex++
for (var j=i;j<=this.array.length-2;j++)
this.array[j] = this.array[j+1]
this.array[this.array.length-1] = this.obj
}
}
function mouse_move(x,y) {
if (this.active)
this.obj.moveTo(x-this.offsetX,y-this.offsetY)
}
function mouse_up() {
this.active = false
}
function within(x,y,lf,rt,tp,bt) {
if (x>=lf && x