//sugar functions, copied from http://javascript.crockford.com/inheritance.html

Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

Function.method('inherits', function (parent) {
    var d = {}, p = (this.prototype = new parent());
    this.method('uber', function uber(name) {
        if (!(name in d)) {
            d[name] = 0;
        }        
        var f, r, t = d[name], v = parent.prototype;
        if (t) {
            while (t) {
                v = v.constructor.prototype;
                t -= 1;
            }
            f = v[name];
        } else {
            f = p[name];
            if (f == this[name]) {
                f = v[name];
            }
        }
        d[name] += 1;
        r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
        d[name] -= 1;
        return r;
    });
    return this;
});

Function.method('swiss', function (parent) {
    for (var i = 1; i < arguments.length; i += 1) {
        var name = arguments[i];
        this.prototype[name] = parent.prototype[name];
    }
    return this;
});

Object.method('setValue', function (name,value) {
    this.name = value;
    return this;
});

var NETSCAPE;
var IEXPLORE;
if (navigator.appName == 'Netscape') {
    IEXPLORE = false;
    NETSCAPE = true;
}
else {
    IEXPLORE = true;
    NETSCAPE = false;
}

mouse = {
    x:0, y:0,
    drag:false,
    dragElement: ""
};
    document.onmousemove = function(e) {
    	if (!e) {
            var e = window.event;
        }
        mouse.x = e.clientX;
        mouse.y = e.clientY;
    }
    document.onmouseup = function() {
        mouse.onmouseup();
    }
    document.onmousedown = function() {
        mouse.onmousedown();
    }
    document.onmousewheel = function(e) {
    	if (!e) {
            var e = window.event;
        }
        mouse.onmousewheel(e);
    }
    mouse.onmouseup = function() {
        if(this.dragElement) {
            this.dragElement.mouseup();
            this.dragElement = "";
        }
        this.drag = false;
    }
    mouse.onmousedown = function() {
    }

    mouse.addDrag = function(o) {
        this.dragElement = o;
        this.drag = true;
    }
    
    mouse.addScroll = function(o) {
        this.scrollElement = o;
        this.onmousewheel = function(e) {
        	if (!e) {
                var e = window.event;
            }
            this.scrollElement.onScroll(e);
        }
    }
    mouse.onmousewheel = function(e) {
    	if (!e) {
            var e = window.event;
        }
    }
//finish initialise mouse.
/*
280-780: 500; c=530
60-560:  500; c=310;           
*/
