/* parseURL . . . for http://test/somedir/somefile.html?one=1&two=2#myanchor
root=http://test/
self=somedir/somefile.html
file=http://test/somedir/somefile.html
abspath=http://test/somedir/
relpath=somedir/
base=somefile.html
anchor=myanchor
query=[an associative array of variable/value pairs]
*/
function parseURL() {
	var b,h;
	b=location.href.match(/^(http(?:s)?:\/\/[_a-z0-9\.-]+\/)([_a-z0-9\/\.-]+)(?:(?:#([^?]*))(?:\?([^#]*))?|(?:\?([^#]*))(?:#([^?]*))?)?$/i);
	h={root:b[1],self:b[2],file:b[1]+b[2],hash:(b[3]?b[3]:(b[6]?b[6]:'')),querystring:(b[4]?b[4]:(b[5]?b[5]:''))};
	h.base=h.file.slice(h.file.lastIndexOf('/')+1);
	h.relpath=h.self.replace(h.base, '');
	h.abspath=h.root+h.relpath;
	h.queryToJSON=function(h) {
		if (!h) return {};
		var i,m,h=h.split('&'),a={};
		for (i=0;i<h.length;i++) {
			m=h[i].match(/^([ a-z0-9_-]+)(\[([ a-z0-9_-]*)\])?=([ a-z0-9_-]+)?$/i);
			if (typeof m[2]=='undefined'||m[2]=='') a[m[1]]=m[4];
			else {
				if (typeof a[m[1]]!='object') a[m[1]]=m[3]&&!m[3].match(/^\d+$/)?{}:[];
				if (typeof a[m[1]]=='object') {
					if (m[3]) a[m[1]][m[3]]=m[4];
					else if (m[2]&&a[m[1]] instanceof Array) a[m[1]].push(m[4]);
				}
			}
		}
		return a;
	};
	h.query=h.queryToJSON(h.querystring);
	return h;
}


// GLOBAL REFERENCE
var _page=parseURL();

