var URI=new Class({Implements:Options,options:{},regex:/^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,parts:["scheme","user","password","host","port","directory","file","query","fragment"],schemes:{http:80,https:443,ftp:21,rtsp:554,mms:1755,file:0},initialize:function(b,a){this.setOptions(a);var c=this.options.base||URI.base;if(!b){b=c}if(b&&b.parsed){this.parsed=$unlink(b.parsed)}else{this.set("value",b.href||b.toString(),c?new URI(c):false)}},parse:function(c,b){var a=c.match(this.regex);if(!a){return false}a.shift();return this.merge(a.associate(this.parts),b)},merge:function(b,a){if((!b||!b.scheme)&&(!a||!a.scheme)){return false}if(a){this.parts.every(function(c){if(b[c]){return false}b[c]=a[c]||"";return true})}b.port=b.port||this.schemes[b.scheme.toLowerCase()];b.directory=b.directory?this.parseDirectory(b.directory,a?a.directory:""):"/";return b},parseDirectory:function(b,c){b=(b.substr(0,1)=="/"?"":(c||"/"))+b;if(!b.test(URI.regs.directoryDot)){return b}var a=[];b.replace(URI.regs.endSlash,"").split("/").each(function(d){if(d==".."&&a.length>0){a.pop()}else{if(d!="."){a.push(d)}}});return a.join("/")+"/"},combine:function(a){return a.value||a.scheme+"://"+(a.user?a.user+(a.password?":"+a.password:"")+"@":"")+(a.host||"")+(a.port&&a.port!=this.schemes[a.scheme]?":"+a.port:"")+(a.directory||"/")+(a.file||"")+(a.query?"?"+a.query:"")+(a.fragment?"#"+a.fragment:"")},set:function(b,d,c){if(b=="value"){var a=d.match(URI.regs.scheme);if(a){a=a[1]}if(a&&!$defined(this.schemes[a.toLowerCase()])){this.parsed={scheme:a,value:d}}else{this.parsed=this.parse(d,(c||this).parsed)||(a?{scheme:a,value:d}:{value:d})}}else{if(b=="data"){this.setData(d)}else{this.parsed[b]=d}}return this},get:function(a,b){switch(a){case"value":return this.combine(this.parsed,b?b.parsed:false);case"data":return this.getData()}return this.parsed[a]||""},go:function(){document.location.href=this.toString()},toURI:function(){return this},getData:function(c,b){var a=this.get(b||"query");if(!$chk(a)){return c?null:{}}var d=a.parseQueryString();return c?d[c]:d},setData:function(a,c,b){if(typeof a=="string"){data=this.getData();data[arguments[0]]=arguments[1];a=data}else{if(c){a=$merge(this.getData(),a)}}return this.set(b||"query",Hash.toQueryString(a))},clearData:function(a){return this.set(a||"query","")}});URI.prototype.toString=URI.prototype.valueOf=function(){return this.get("value")};URI.regs={endSlash:/\/$/,scheme:/^(\w+):/,directoryDot:/\.\/|\.$/};URI.base=new URI(document.getElements("base[href]",true).getLast(),{base:document.location});String.implement({toURI:function(a){return new URI(this,a)}});