if (!wmp)
	var wmp = {
		provide: function(packName) {
			if (packName.indexOf(".") != -1) {
				var parentPackName = packName.substring(0, packName.lastIndexOf("."));
				wmp.provide(parentPackName);
			}
			eval("var pack = " + packName + ";");
			if(!pack)
				eval(packName + " = {}");

		}
	}
	
wmp.provide("wmp.config");

/*
if (!console) {
	var console = {
		log: function (obj) {
			if (!console.container) {
				console.container = new Element("div", {"style":"overflow: auto;height: 200px;"});
				console.container.injectBottom(document.body);
			}
			var div = new Element("div").inject(console.container, 'top');
			if ($type(obj))
				div.set('text', obj);
		}
	}
}*/

//from prototype
String.implement({
  escapeHTML: function() {
    var div = document.createElement('div');
    var text = document.createTextNode(this);
    div.appendChild(text);
    return div.innerHTML;
  },
  stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  }
});

wmp.encodeRegex = function(s) {
	return s.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$0');
}

wmp.url = {
	//http://blog.stevenlevithan.com/archives/parseuri
	type: function(url, base) {
		if (url.test("^[a-z0-9]{2,8}:", "i"))
			return "abs";
		if (url.substring(0,1) == "/")
			return "reldomain";
		return "rel";
	},
	/*toDomainAbs: function(url) {
		//todo:does not really work, try the a.href method (a.href always returns the absolute url)
		var h, p, f, i;
		if (/^\w+:/.test(url)) {
			return url;
		}
		var hash = url.substring(url.lastIndexOf('#'));
		url = url.substring(0, url.lastIndexOf('#'));
		
		h = location.protocol + '//' + location.host;
		if (url.indexOf('/') == 0) {
			return url + hash;
		}
		
		p = location.pathname.replace(/\/[^\/]*$/, '');
		f = url.match(/\.\.\//g);
		if (f) {
			url = url.substring(f.length * 3);
			for (i = f.length; i--;) {
				p = p.substring(0, p.lastIndexOf('/'));
			}
		}
		return p + '/' + url + hash;
	},*/
	toRel: function(url, base) {
		var l = window.location;
		if (!base)
			var base = wmp.config.base || (l.protocol+"//"+l.host+l.pathname);
		//try stripping whole path
		var url = url.replace(new RegExp(base.escapeRegExp(), "i"), "");
		//try stripping just the domain
		var base = l.protocol+"//"+l.host;
		var url = url.replace(new RegExp(base.escapeRegExp(), "i"), "");
		return url;
	}
}


wmp.debug = {
	node: function(node, str) {
		var str = " ty: '" + $type(node) + "'";
		if ($type(node) == "element") {
			str += " na: '" + node.nodeName + "'";
			str += " te: '" + $(node).get('text').substring(0,10) + "'";
		}
		else if ($type(node) == "textnode")
			str += "t: '" + node.nodeName + "'";
		console.log(node, str);
	}
}


Class.prototype.getStatic = function(name) {
	//console.log("getStatic", name);
	if (this[name])
		return this[name];
	if (this.prototype[name])
		return this.prototype[name];
	var m=this;
	while (m = m.prototype.Extends) {
		//console.log("Extends");
		if (m.prototype[name])
			return m.prototype[name];
	}
	return null;
}
