core = {
	isOpera:(navigator.userAgent.toLowerCase().indexOf('opera') != -1),
	isIE:(!this.isOpera && (navigator.userAgent.toLowerCase().indexOf('msie') != -1)),
	isFF:(navigator.userAgent.toLowerCase().indexOf('firefox') != -1),
	getCoord:function(obj, c, side){
		var coord = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				coord += obj["offset"+side];
				obj = obj.offsetParent;
			}
		}
		if (obj[c])
			coord += obj[c];
		return coord;
	},
	getX:function(obj){return this.getCoord(obj,"x","Left");},
	getY:function(obj){return this.getCoord(obj,"y","Top");},
	
	getMousePos:function(e, c, side){
		var pos = 0;
		if (!e) var e = window.event;
		var bodyScrl = document.body["scroll"+side] || 0;
		var docScrl = document.documentElement["scroll"+side] || 0;
		pos = e["page"+c] || (e["client"+c] + bodyScrl || docScrl) || 0;
		return pos;
	},
	getMouseX:function(e){
		return this.getMousePos(e, "X", "Left");
	},
	getMouseY:function(e){
		return this.getMousePos(e, "Y", "Top");
	},
	addScript:function(src){
		var head = document.getElementsByTagName("head")[0];
		var scr = document.createElement("script");
		scr.src = src;
		head.appendChild(scr);
	},
	require:function(src){
		var scrs = document.getElementsByTagName("script");
		for(i in scrs){
			if(scrs[i].src==src)return;
		}
		this.addScript(src);
	}
};

// ---- for compatibility ----

var _isIE = core.isIE;
var _isOpera = core.isOpera;
var _isFF = core.isFF;

var ge = function(name) {
	return document.getElementById(name);
}

var findX = function(obj) {
  return core.getX(obj);
}

var findY = function(obj) {
  return core.getY(obj);
}

var mousePosX = function(e) {
  return core.getMouseX(e);
}

var mousePosY = function(e) {
  return core.getMouseY(e);
}

// -------------

Function.prototype.bind = function(object) {
    var method = this
    return function() {
        return method.apply(object, arguments) 
    }
}

// To be moved to css.js
 
css = {

	pushStyles: function(obj, styles) {
		for(i in styles) {
			obj["_style"+ i] = obj.style[i] || "";
			obj.style[i] = styles[i];
		}
	},

	popStyles: function(obj, styles) {
		for(i = 0; i < styles.length; i++)
			obj.style[styles[i]] = obj["_style"+ styles[i]];
	},

	getStyle: function(obj, style, int, intradix) {
		var dv = document.defaultView;
		if (dv && dv.getComputedStyle) {
		var value = dv.getComputedStyle(obj, '').getPropertyValue(style.replace(/[A-Z]/g, 
				function(match, char) { 
					return "-" + match.toLowerCase(); 
				} ) 
			);
		} else if (obj.currentStyle) 
			var value = obj.currentStyle[style];
		else
			var value = obj.style[style] || "";
		return int ? parseInt(value, intradix || 10) : value;
	},
	
	getPureWidth: function(obj) {
		var gs = this.getStyle;
		return obj.offsetWidth - gs(obj, "borderLeftWidth", 1) - gs(obj, "paddingLeft", 1) - gs(obj, "paddingRight", 1) - gs(obj, "borderRightWidth", 1);
	}
}