////////////////////////////
// FUNCTION DEFINITIONS
function echo(n) {document.write(n)}
function obj(n)  {return document.getElementById(n)}
function int(n)  {return parseInt(n)}
function floor(n){return Math.floor(n)}
function round(n){return Math.round(n)}
function ceil(n) {return Math.ceil(n)}
function abs(n)  {return Math.abs(n)}
function sin(n)  {return Math.sin(n)}
function cos(n)  {return Math.cos(n)}
function sqrt(n) {return Math.sqrt(n)}
function pow(n,m) {return Math.pow(n,m)}
function random(){return Math.random()}

function rand(n,m) {
    return floor(((m - n) * random() ) + n);
}

function dist(x1, y1, x2, y2) {
    return round(sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)));
}

function getheight(n) {
    if(n.height) return n.height;
    if(n.style && n.style.height)
        return n.style.height;
    if(n.clientHeight) return n.clientHeight;
    if(n.innerHeight)  return n.innerHeight;
    if(n == window && document.body.clientHeight)
        return document.body.clientHeight;
    return false;
}
function getwidth(n) {
    if(n.width) return n.width;
    if(n.style && n.style.width)
        return n.style.width;
    if(n.clientWidth) return n.clientWidth;
    if(n.innerWidth)  return n.innerWidth;
    if(n == window && document.body.clientWidth)
        return document.body.clientWidth;
    return false;
}

function topof(n) {
    if(n.style && n.style.top)
        return int(n.style.top);
    else return false;
}

function leftof(n) {
    if(n.style && n.style.left)
        return int(n.style.left);
    else return false;
}

function scrollTop(n) {
    if(!n) n = document.body;
    return n.scrollTop;
}

function scrollLeft(n) {
    if(!n) n = document.body;
    return n.scrollLeft;
}

/////////////////////////////////
// USE these functions to get
// the width and height of an OBJECT
function heightof(n){return int(getheight(n))}
function  widthof(n){return int( getwidth(n))}

function move(n,x,y) {
    if(n == window) window.moveTo(x,y);
    if(n.style) {
        if(n.style.position != 'absolute')
            n.style.position = 'absolute';
        with(n.style) {
            left = x;
            top  = y;
        }
        return true;
    }
    return false;
}

function size(n,w,h) {
    if(n == window) window.resizeTo(w,h);
    else if(n.width) n = n;
    else if(n.style) n = n.style;
    else return false;
    
    if(w > -1) n.width = w;
    if(h > -1) n.height= h;
    return true;
}

function hide(n) {
    if(n.style) n.style.display = 'none';
    else return false; return true;
}

function show(n) {
    if(n.style) n.style.display = '';
    else return false; return true;
}

function block(n) {
    if(n.style) n.style.display = 'block';
    else return false; return true;
}

function inline(n) {
    if(n.style) n.style.display = 'inline';
    else return false; return true;
}

//////////////////
// browser functions
function ie() {
    return (navigator.appName.indexOf('Explorer') > -1) ? true: false;
}

function firefox() {
    return (navigator.appName.indexOf('Netscape') > -1) ? true: false;
}
//////////////////
// Event functions

function targetof(e) {
    if(e.target) return e.target;
    if(e.srcElement) return e.srcElement;
    return false;
}

function mousex(e) {
    if(e.x>=0) return e.x + scrollLeft();
    if(e.pageX>=0) return e.pageX;
    return false;
}

function mousey(e) {
    if(e.y>=0) return e.y + scrollTop();
    if(e.pageY>=0) return e.pageY;
    return false;
}

////////////////////////////////////////////////
// Dragging Handling Data and Functions
dragging = false; // something is being dragged
dragoff  = [0,0];
var dragobj; // object dragging

function isdraggable(n){return (n.getAttribute('draggable')) ? true: false;}
function  enabledrag(n){n.setAttribute('draggable',true);}
function disabledrag(n){n.setAttribute('draggable',false);}

function dragstart(e) {
    dragging = true;
    dragobj  = targetof(e);
    if(dragobj.style.position != 'absolute')
        dragoff  = [floor(widthof(dragobj)/2), floor(heightof(dragobj)/2)];
    else dragoff  = [mousex(e) - leftof(dragobj), mousey(e) - topof(dragobj)];
}

function dragmove(e) {
    move(dragobj, mousex(e) - dragoff[0], mousey(e) - dragoff[1]);
}

function dragstop() {
    dragging = false;
}

/*
///////////////////////////
// EVENT Handlers
function mousedown(e)
{
    target = targetof(e);
    if( isdraggable(target) )
        dragstart(e);
}

function mouseup(e)
{
    target = targetof(e);
    if(dragging) dragstop();
}

function mousemove(e)
{
    target = targetof(e);
    
    if(dragging) dragmove(e);
}

function mouseout(e)
{
    target = targetof(e);
}
//*/