if(!LBS)var LBS={};LBS.STATESAVER={};
LBS.STATESAVER.State=function(p){var h=LBS.STATESAVER,l=h.Point.COORDINATE_SYSTEM,j=h.NamedLocation.TYPE;this.setParam=function(a,b){for(var c in e)if(e[c].name==a){e[c].value=b;return}e.push({name:a,value:b,type:h.State.PARAM_TYPE.VALUE})};this.getParam=function(a){for(var b in e)if(e[b].name==a)return e[b].value;return null};this.setArrayParam=function(a,b){for(var c in e)if(e[c].name==a){e[c].value=b;return}e.push({name:a,value:b,type:h.State.PARAM_TYPE.VALUE_ARRAY})};this.getArrayParam=function(a){var b=
null;for(var c in e)if(e[c].name==a)b=e[c].value;if(b==null)return null;return b};this.setLocation=function(a,b){q.setParam(a,m(b))};this.setLocationArray=function(a,b){for(var c=[],f=0;f<b.length;f++)c.push(m(b[f]));q.setArrayParam(a,c)};this.getLocation=function(a){a=q.getParam(a);if(a===null)return null;return d(a)};this.getLocationArray=function(a){a=q.getArrayParam(a);if(a==null)return null;var b=[];for(var c in a)b.push(d(a[c]));return b};this.getUrlHash=function(){var a="";for(var b in e)if(e[b].name!==
null&&e[b].value!==null&&e[b].type!==null){a+=encodeURIComponent(e[b].name)+"(";if(e[b].type===h.State.PARAM_TYPE.VALUE){var c=""+e[b].value;c=c.replace(/[\\]/g,"\\\\");c=c.replace(/[(]/g,"\\(");c=c.replace(/[)]/g,"\\)");a+=encodeURIComponent(c)}else if(e[b].type===h.State.PARAM_TYPE.VALUE_ARRAY){var f=e[b].value;for(var g in f){c=""+f[g];c=c.replace(/[\\]/g,"\\\\");c=c.replace(/[(]/g,"\\(");c=c.replace(/[)]/g,"\\)");a+="("+encodeURIComponent(c)+")"}}a+=")"}return a};var i=function(a){if(!(a.length<
5)){if(a.charAt(0)=="#")a=a.substring(1,a.length);for(var b="",c="",f=0;f<a.length;f++){var g=a.charAt(f);if(c=="\\")b+=g;else if(g=="("){var o=1,r="",s=false;c=g;for(f++;f<a.length;){g=a.charAt(f);if(c=="\\")r+=g;else if(g=="("){o++;s=true;r+=g}else if(g==")"){o--;if(o==0){if(s==false){c=n(r);q.setParam(decodeURIComponent(b),c)}else{c=k(r);q.setArrayParam(decodeURIComponent(b),c)}break}else r+=g}else r+=g;c=g;f++}b=""}else if(g!="\\")b+=g;c=a.charAt(f)}}},n=function(a){for(var b="",c="",f=0;f<a.length;f++){var g=
a.charAt(f);if(b=="\\"||g!="\\")c+=g;b=g}return decodeURIComponent(c)},k=function(a){for(var b="",c=[],f="",g=0;g<a.length;g++){var o=a.charAt(g);if(b=="\\")f+=o;else if(o==")"){c.push(n(f));f=""}else if(o!="(")f+=o;b=o}return c},m=function(a){if(a instanceof h.Location!=true)return"";var b="";if(a instanceof h.Point==true){if(a.getCoordinateSystem()===l.INTERNAL)b="point";else if(a.getCoordinateSystem()===l.KKJ3)b="kkj3";else if(a.getCoordinateSystem()===l.WGS84)b="wgs84";else return;return b+"*"+
a.getX()+"*"+a.getY()}else if(a instanceof h.NamedLocation==true){if(a.getType()===j.POI)b="poi";else if(a.getType()===j.ADDRESS)b="address";else if(a.getType()===j.STREET)b="street";else return;return b+"*"+a.getName()}},d=function(a){a=a.split("*");switch(a[0]){case "point":if(a.length!=3)return null;return new h.Point(a[1],a[2],l.INTERNAL);case "kkj3":if(a.length!=3)return null;return new h.Point(a[1],a[2],l.KKJ3);case "wgs84":if(a.length!=3)return null;return new h.Point(a[1],a[2],l.WGS84);case "poi":if(a.length!=
2)return null;return new h.NamedLocation(a[1],j.POI);case "address":if(a.length!=2)return null;return new h.NamedLocation(a[1],j.ADDRESS);case "street":if(a.length!=2)return null;return new h.NamedLocation(a[1],j.STREET);default:return null}},e=[],q=this;p&&i(p)};LBS.STATESAVER.State.PARAM_TYPE={VALUE:1,VALUE_ARRAY:2};
LBS.STATESAVER.UrlHandler=function(p){var h=LBS.STATESAVER;this.setParam=function(d,e){if(i.getParam(d)!==e){i.setParam(d,e);m=true}};this.setArrayParam=function(d,e){i.setArrayParam(d,e);m=true};this.getParam=function(d){return i.getParam(d)};this.getArrayParam=function(d){return i.getArrayParam(d)};this.setLocation=function(d,e){i.setLocation(d,e);m=true};this.setLocationArray=function(d,e){i.setLocationArray(d,e);m=true};this.getLocation=function(d){return i.getLocation(d)};this.getLocationArray=
function(d){return i.getLocationArray(d)};this.addHashChangeCBF=function(d){n.push(d)};this.getState=function(){l();return new h.State(k)};var l=function(){if(m){var d=i.getUrlHash();if(d.length<1)d="#";window.location.hash=d;k=window.location.hash;m=false}else if(window.location.hash!=k)for(d in n)n[d](j)},j=this,i=new h.State(window.location.hash),n=[],k=window.location.hash,m=false;window.setInterval(l,p)};LBS.STATESAVER.Location=function(){};
LBS.STATESAVER.Point=function(p,h,l){var j=LBS.STATESAVER,i=j.Point.COORDINATE_SYSTEM;j.Location.call();this.getX=function(){return n};this.setX=function(d){n=typeof d=="number"?d:parseFloat(d)};this.getY=function(){return k};this.setY=function(d){k=typeof d=="number"?d:parseFloat(d)};this.getCoordinateSystem=function(){return m};this.setCoordinateSystem=function(d){if(d===i.KKJ3||d===i.WGS84||d===i.INTERNAL)m=d};var n,k,m=i.INTERNAL;this.setX(p);this.setY(h);this.setCoordinateSystem(l)};
LBS.STATESAVER.Point.prototype=new LBS.STATESAVER.Location;LBS.STATESAVER.Point.prototype.constructor=LBS.STATESAVER.Point;LBS.STATESAVER.Point.COORDINATE_SYSTEM={INTERNAL:1,KKJ3:2,WGS84:3};LBS.STATESAVER.NamedLocation=function(p,h){var l=LBS.STATESAVER,j=l.NamedLocation.TYPE;l.Location.call();this.getName=function(){return i};this.setName=function(k){i=k};this.getType=function(){return n};this.setType=function(k){if(k===j.POI||k===j.ADDRESS||k===j.STREET||k===j.UNKNOWN)n=k};var i=p,n=j.UNKNOWN;this.setType(h)};
LBS.STATESAVER.NamedLocation.prototype=new LBS.STATESAVER.Location;LBS.STATESAVER.NamedLocation.prototype.constructor=LBS.STATESAVER.NamedLocation;LBS.STATESAVER.NamedLocation.TYPE={UNKNOWN:1,POI:2,ADDRESS:3,STREET:4};
