function URL(str) {
	if (str == undefined)
		str = window.location;

	this.dir = this.hash = this.base = this.query = null;
	this.vars = {};

	this.get = function(key) {
		if (this.vars[key] != undefined)
			return this.vars[key];
		return null;
	}

	this.clear = function(key) {
		if (key != undefined) {
			if (this.vars[key] != undefined)
				delete this.vars[key];
		} else {
			this.vars = [];
		}
		return this;
	}

	this.append = function(key, value) {
		if (this.vars[key] == undefined) 
			this.vars[key] = [];
		this.vars[key].push(value);
		return this;
	}

	this.construct = function() {
		var str = '';
		if (this.dir != null)
			str += this.dir + '/';
		str += this.base;
		var tmp = [];
		for (var i in this.vars) {
			for (var n=0; n<this.vars[i].length; n++) {
				tmp.push(i + '=' + this.vars[i][n]);
			}
		}
		if (tmp.length > 0)
			str += '?' + tmp.join('&');
		return str;
	}

	this.navigate = function() {
		window.location.href = this.construct();
	}

	this.parse = function(s) {
		if (s.indexOf('#')>-1) {
			this.hash = s.substr(s.indexOf('#')+1);
			s = s.substr(0, s.indexOf('#'));
		}
		if (s.indexOf('?')>-1) {
			this.query = s.substr(s.indexOf('?')+1);
			s = s.substr(0, s.indexOf('?'));
			var tmp = this.query.split('&');
			for (var n = 0; n < tmp.length; n++) {
				var tmp2 = tmp[n].split('=');
				if (this.vars[tmp2[0]] == undefined) 
					this.vars[tmp2[0]] = [];
				this.vars[tmp2[0]].push(tmp2[1]);
			}
		}
		if (s.indexOf('/')>-1) {
			this.base = s.substr(s.lastIndexOf('/')+1);
			this.dir = s.substr(0, s.lastIndexOf('/'));
		} else {
			this.base = s;
		}
	}

	this.parse(str);
	return this;
}


