/* 
 * Timemap.js Copyright 2008 Nick Rabinowitz.
 * Licensed under the MIT License (see LICENSE.txt)
 */
(function(){var i=this,f,g=i.Timeline,h=g.DateTime,d=i.G_DEFAULT_MAP_TYPES,k=i.G_NORMAL_MAP,q=i.G_PHYSICAL_MAP,p=i.G_SATELLITE_MAP,n=i.GLatLng,c=i.GLatLngBounds,b=i.GEvent,j="http://www.google.com/intl/en_us/mapfiles/ms/icons/",l,o,m,e;l=function(s,u,t){this.mElement=u;this.tElement=s;this.datasets={};this.chains={};this.mapBounds=new c();var v={mapCenter:new n(0,0),mapZoom:0,mapType:q,mapTypes:[k,p,q],showMapTypeCtrl:true,showMapCtrl:true,syncBands:true,mapFilter:"hidePastFuture",centerOnItems:true,theme:"red"};this.opts=t=a.merge(t,v);t.mergeOnly=["mergeOnly","theme","eventIconPath","openInfoWindow","closeInfoWindow","noPlacemarkLoad","noEventLoad"];t.mapType=a.lookup(t.mapType,l.mapTypes);t.mapFilter=a.lookup(t.mapFilter,l.filters);t.theme=m.create(t.theme,t);this.initMap()};l.prototype.initMap=function(){var s=this.opts,u,t;if(GBrowserIsCompatible()){this.map=u=new GMap2(this.mElement);if(s.showMapCtrl){u.addControl(new GLargeMapControl())}if(s.showMapTypeCtrl){u.addControl(new GMapTypeControl())}for(t=d.length-1;t>0;t--){u.removeMapType(d[t])}u.addMapType(s.mapTypes[0]);u.removeMapType(d[0]);for(t=1;t<s.mapTypes.length;t++){u.addMapType(s.mapTypes[t])}u.enableDoubleClickZoom();u.enableScrollWheelZoom();u.enableContinuousZoom();u.setCenter(s.mapCenter,s.mapZoom);u.setMapType(s.mapType)}};l.version="1.6pre";var a=l.util={};l.init=function(u){var B="TimeMap.init: No id for ";if(!("mapId" in u)||!u.mapId){throw B+"map"}if(!("timelineId" in u)||!u.timelineId){throw B+"timeline"}var A={options:{},datasets:[],bands:false,bandInfo:false,bandIntervals:"wk",scrollTo:"earliest"};u=a.merge(u,A);if(!u.bandInfo&&!u.bands){var E=a.lookup(u.bandIntervals,l.intervals);u.bandInfo=[{width:"80%",intervalUnit:E[0],intervalPixels:70},{width:"20%",intervalUnit:E[1],intervalPixels:100,showEventText:false,overview:true,trackHeight:0.4,trackGap:0.2}]}var H=new l(document.getElementById(u.timelineId),document.getElementById(u.mapId),u.options);var C=[],G,t,w,z,s;for(G=0;G<u.datasets.length;G++){t=u.datasets[G];z={title:t.title,theme:t.theme,dateParser:t.dateParser};w=a.merge(t.options,z);s=t.id||"ds"+G;C[G]=H.createDataset(s,w);if(G>0){C[G].eventSource=C[0].eventSource}}H.eventSource=C[0].eventSource;var y=[];var v=(C[0]&&C[0].eventSource)||new g.DefaultEventSource();if(u.bands){y=u.bands;for(G=0;G<y.length;G++){if(y[G].eventSource!==null){y[G].eventSource=v}}}else{for(G=0;G<u.bandInfo.length;G++){var F=u.bandInfo[G];if(!(("eventSource" in F)&&!F.eventSource)){F.eventSource=v}else{F.eventSource=null}y[G]=g.createBandInfo(F);if(G>0&&a.TimelineVersion()=="1.2"){y[G].eventPainter.setLayout(y[0].eventPainter.getLayout())}}}H.initTimeline(y);var D=l.loadManager;D.init(H,u.datasets.length,u);for(G=0;G<u.datasets.length;G++){(function(J){var N=u.datasets[J],K,M,O,L,I;K=N.data||N.options||{};M=N.type||K.type;O=function(){D.increment()};L=(typeof(M)=="string")?l.loaders[M]:M;I=new L(K);I.load(C[J],O)})(G)}return H};var r=l.init;l.loadManager=new function(){this.init=function(s,u,t){this.count=0;this.tm=s;this.target=u;this.opts=t||{}};this.increment=function(){this.count++;if(this.count>=this.target){this.complete()}};this.complete=function(){var s=this.tm;var u=this.opts.dataLoadedFunction;if(u){u(s)}else{var w=new Date();var v=this.tm.eventSource;var t=this.opts.scrollTo;if(t&&v.getCount()>0){switch(t){case"now":break;case"earliest":w=v.getEarliestDate();break;case"latest":w=v.getLatestDate();break;default:if(typeof(t)=="string"){t=o.hybridParser(t)}if(t.constructor==Date){w=t}}s.timeline.getBand(0).setCenterVisibleDate(w)}s.timeline.layout();u=this.opts.dataDisplayedFunction;if(u){u(s)}}}};l.loaders={};l.loaders.basic=function(s){l.loaders.mixin(this,s);this.data=s.items||s.value||[]};l.loaders.basic.prototype.load=function(t,u){var s=this.preload(this.data);t.loadItems(s,this.transform);u()};l.loaders.remote=function(s){l.loaders.mixin(this,s);this.url=s.url};l.loaders.remote.prototype.load=function(t,u){var s=this;GDownloadUrl(this.url,function(v){var w=s.parse(v);w=s.preload(w);t.loadItems(w,s.transform);u()})};l.loaders.mixin=function(s,t){var u=function(v){return v};s.parse=t.parserFunction||u;s.preload=t.preloadFunction||u;s.transform=t.transformFunction||u};l.prototype.createDataset=function(w,s){var v=new o(this,s);this.datasets[w]=v;if(this.opts.centerOnItems){var u=this.map,t=this.mapBounds;b.addListener(v,"itemsloaded",function(){u.setCenter(t.getCenter(),u.getBoundsZoomLevel(t))})}return v};l.prototype.each=function(s){for(var t in this.datasets){if(this.datasets.hasOwnProperty(t)){s(this.datasets[t])}}};l.prototype.eachItem=function(s){this.each(function(t){t.each(function(u){s(u)})})};l.prototype.getItems=function(t){var s=[];this.eachItem(function(u){s.push(u)});return s};l.prototype.initTimeline=function(w){for(var s=1;s<w.length;s++){if(this.opts.syncBands){w[s].syncWith=(s-1)}w[s].highlight=true}this.timeline=g.create(this.tElement,w);var u=this;this.timeline.getBand(0).addOnScrollListener(function(){u.filter("map")});var t=this.timeline.getBand(0).getEventPainter().constructor;t.prototype._showBubble=function(z,B,A){A.item.openInfoWindow()};this.addFilterChain("map",function(x){x.showPlacemark()},function(x){x.hidePlacemark()});this.addFilter("map",function(x){return x.visible});this.addFilter("map",function(x){return x.dataset.visible});this.addFilter("map",this.opts.mapFilter);this.addFilterChain("timeline",function(x){x.showEvent()},function(x){x.hideEvent()},null,function(x){x.eventSource._events._index();x.timeline.layout()});this.addFilter("timeline",function(x){return x.visible});this.addFilter("timeline",function(x){return x.dataset.visible});var y=null;var v=this.timeline;i.onresize=function(){if(y===null){y=i.setTimeout(function(){y=null;v.layout()},500)}}};l.prototype.filter=function(u){var t=this.chains[u],s;if(!t){return}s=t.chain;if(!s||s.length===0){return}if(t.pre){t.pre(this)}this.each(function(v){v.each(function(y){var w=false;F_LOOP:while(!w){for(var x=s.length-1;x>=0;x--){if(!s[x](y)){t.off(y);break F_LOOP}}t.on(y);w=true}})});if(t.post){t.post(this)}};l.prototype.addFilterChain=function(w,t,s,v,u){this.chains[w]={chain:[],on:t,off:s,pre:v,post:u}};l.prototype.removeFilterChain=function(s){this.chains[s]=null};l.prototype.addFilter=function(u,t){var s=this.chains[u];if(s&&s.chain){s.chain.push(t)}};l.prototype.removeFilter=function(w,v){var u=this.chains[w];if(u&&u.chain){var t=u.chain;if(!v){t.pop()}else{for(var s=0;s<t.length;s++){if(t[s]==v){t.splice(s,1)}}}}};l.filters={};l.filters.hidePastFuture=function(v){var x=v.dataset.timemap.timeline.getBand(0);var t=x.getMaxVisibleDate().getTime();var u=x.getMinVisibleDate().getTime();if(v.event){var s=v.event.getStart().getTime();var w=v.event.getEnd().getTime();if(s>t){return false}else{if(w<u||(v.event.isInstant()&&s<u)){return false}}}return true};l.filters.showMomentOnly=function(t){var v=t.dataset.timemap.timeline.getBand(0);var w=v.getCenterVisibleDate().getTime();if(t.event){var s=t.event.getStart().getTime();var u=t.event.getEnd().getTime();if(s>w){return false}else{if(u<w||(t.event.isInstant()&&s<w)){return false}}}return true};o=function(s,t){this.timemap=s;this.eventSource=new g.DefaultEventSource();this.items=[];this.visible=true;var u={title:"Untitled",dateParser:o.hybridParser};this.opts=t=a.merge(t,u,s.opts);t.dateParser=a.lookup(t.dateParser,l.dateParsers);t.theme=m.create(t.theme,t);this.getItems=function(v){if(v!==f){if(v<this.items.length){return this.items[v]}else{return null}}return this.items};this.getTitle=function(){return this.opts.title}};o.gregorianParser=function(u){if(!u){return null}else{if(u instanceof Date){return u}}var v=Boolean(u.match(/b\.?c\.?/i));var t=parseInt(u,10);if(!isNaN(t)){if(v){t=1-t}var w=new Date(0);w.setUTCFullYear(t);return w}else{return null}};o.hybridParser=function(t){var v=new Date(Date.parse(t));if(isNaN(v)){if(typeof(t)=="string"){if(t.match(/^-?\d{1,6} ?(a\.?d\.?|b\.?c\.?e?\.?|c\.?e\.?)?$/i)){v=o.gregorianParser(t)}else{try{v=h.parseIso8601DateTime(t)}catch(u){v=null}}}else{return null}}return v};o.prototype.each=function(t){for(var s=0;s<this.items.length;s++){t(this.items[s])}};o.prototype.loadItems=function(u,t){for(var s=0;s<u.length;s++){this.loadItem(u[s],t)}b.trigger(this,"itemsloaded")};o.prototype.loadItem=function(P,F){if(F!==f){P=F(P)}if(!P){return}options=a.merge(P.options,this.opts);var O=options.theme=m.create(options.theme,options);var w=this.opts.dateParser,B=P.start,z=P.end,v;B=B?w(B):null;z=z?w(z):null;v=!z;var u=O.eventIcon,Q=P.title,K=null;if(B!==null){var D=g.DefaultEventSource.Event;if(a.TimelineVersion()=="1.2"){K=new D(B,z,null,null,v,Q,null,null,null,u,O.eventColor,O.eventTextColor)}else{var A=O.eventTextColor;if(!A){A=(O.classicTape&&!v)?"#FFFFFF":"#000000"}K=new D({start:B,end:z,instant:v,text:Q,icon:u,color:O.eventColor,textColor:A})}}var s=O.icon,x=this.timemap,C=x.mapBounds;var H=function(V){var U=null,X="",aa=null;if(V.point){var W=V.point.lat,S=V.point.lon;if(W===f||S===f){return null}aa=new n(parseFloat(V.point.lat),parseFloat(V.point.lon));if(x.opts.centerOnItems){C.extend(aa)}U=new GMarker(aa,{icon:s,title:V.title});X="marker";aa=U.getLatLng()}else{if(V.polyline||V.polygon){var ab=[],ac;if(V.polyline){ac=V.polyline}else{ac=V.polygon}if(ac&&ac.length){for(var Y=0;Y<ac.length;Y++){aa=new n(parseFloat(ac[Y].lat),parseFloat(ac[Y].lon));ab.push(aa);if(x.opts.centerOnItems){C.extend(aa)}}if("polyline" in V){U=new GPolyline(ab,O.lineColor,O.lineWeight,O.lineOpacity);X="polyline";aa=U.getVertex(Math.floor(U.getVertexCount()/2))}else{U=new GPolygon(ab,O.polygonLineColor,O.polygonLineWeight,O.polygonLineOpacity,O.fillColor,O.fillOpacity);X="polygon";aa=U.getBounds().getCenter()}}}else{if("overlay" in V){var Z=new n(parseFloat(V.overlay.south),parseFloat(V.overlay.west));var T=new n(parseFloat(V.overlay.north),parseFloat(V.overlay.east));if(x.opts.centerOnItems){C.extend(Z);C.extend(T)}var R=new c(Z,T);U=new GGroundOverlay(V.overlay.image,R);X="overlay";aa=R.getCenter()}}}return{placemark:U,type:X,point:aa}};var N=[],I=[],t=null,y="",J=null,L;if("placemarks" in P){I=P.placemarks}else{var E=["point","polyline","polygon","overlay"];for(L=0;L<E.length;L++){if(E[L] in P){t={title:Q};t[E[L]]=P[E[L]];I.push(t)}}}if(I){for(L=0;L<I.length;L++){var G=H(I[L]);if(G&&G.placemark){J=J||G.point;y=y||G.type;N.push(G.placemark)}}}if(N.length>1){y="array"}options.title=Q;options.type=y;if(options.infoPoint){options.infoPoint=new n(parseFloat(options.infoPoint.lat),parseFloat(options.infoPoint.lon))}else{options.infoPoint=J}var M=new e(N,K,this,options);if(K!==null){K.item=M;if(!this.opts.noEventLoad){this.eventSource.add(K)}}if(N.length>0){for(L=0;L<N.length;L++){N[L].item=M;b.addListener(N[L],"click",function(){M.openInfoWindow()});if(!this.opts.noPlacemarkLoad){x.map.addOverlay(N[L])}N[L].hide()}}this.items.push(M);return M};m=function(t){var v={color:"#FE766A",lineOpacity:1,lineWeight:2,fillOpacity:0.25,eventTextColor:null,eventIconPath:"timemap/images/",eventIconImage:"red-circle.png",classicTape:false,iconImage:j+"red-dot.png"};var u=a.merge(t,v);delete u.mergeOnly;if(!u.icon){var s=new GIcon(G_DEFAULT_ICON);s.image=u.iconImage;s.iconSize=new GSize(32,32);s.shadow=j+"msmarker.shadow.png";s.shadowSize=new GSize(59,32);s.iconAnchor=new GPoint(16,33);s.infoWindowAnchor=new GPoint(18,3);u.icon=s}v={lineColor:u.color,polygonLineColor:u.color,polgonLineOpacity:u.lineOpacity,polygonLineWeight:u.lineWeight,fillColor:u.color,eventColor:u.color,eventIcon:u.eventIconPath+u.eventIconImage};u=a.merge(u,v);return u};m.create=function(u,s){if(u){u=l.util.lookup(u,l.themes)}else{return new m(s)}var v=false,t;for(t in s){if(u.hasOwnProperty(t)){v={};break}}if(v){for(t in u){if(u.hasOwnProperty(t)){v[t]=s[t]||u[t]}}v.eventIcon=s.eventIcon||v.eventIconPath+v.eventIconImage;return v}else{return u}};e=function(t,u,w,s){this.event=u;this.dataset=w;this.map=w.timemap.map;if(t&&a.isArray(t)&&t.length===0){t=null}if(t&&t.length==1){t=t[0]}this.placemark=t;var v={type:"none",title:"Untitled",description:"",infoPoint:null,infoHtml:"",infoUrl:"",closeInfoWindow:e.closeInfoWindowBasic};this.opts=s=a.merge(s,v,w.opts);if(!s.openInfoWindow){if(s.infoUrl!==""){s.openInfoWindow=e.openInfoWindowAjax}else{s.openInfoWindow=e.openInfoWindowBasic}}this.getType=function(){return this.opts.type};this.getTitle=function(){return this.opts.title};this.getInfoPoint=function(){return this.opts.infoPoint||this.map.getCenter()};this.visible=true;this.placemarkVisible=false;this.eventVisible=true;this.openInfoWindow=s.openInfoWindow;this.closeInfoWindow=s.closeInfoWindow};e.prototype.showPlacemark=function(){if(this.placemark){if(this.getType()=="array"){for(var s=0;s<this.placemark.length;s++){this.placemark[s].show()}}else{this.placemark.show()}this.placemarkVisible=true}};e.prototype.hidePlacemark=function(){if(this.placemark){if(this.getType()=="array"){for(var s=0;s<this.placemark.length;s++){this.placemark[s].hide()}}else{this.placemark.hide()}this.placemarkVisible=false}this.closeInfoWindow()};e.prototype.showEvent=function(){if(this.event){if(this.eventVisible===false){this.dataset.timemap.timeline.getBand(0).getEventSource()._events._events.add(this.event)}this.eventVisible=true}};e.prototype.hideEvent=function(){if(this.event){if(this.eventVisible){this.dataset.timemap.timeline.getBand(0).getEventSource()._events._events.remove(this.event)}this.eventVisible=false}};e.openInfoWindowBasic=function(){var s=this.opts.infoHtml;if(s===""){s='<div class="infotitle">'+this.opts.title+"</div>";if(this.opts.description!==""){s+='<div class="infodescription">'+this.opts.description+"</div>"}}if(this.placemark&&!this.visible&&this.event){var t=this.dataset.timemap.timeline.getBand(0);t.setCenterVisibleDate(this.event.getStart())}if(this.getType()=="marker"){this.placemark.openInfoWindowHtml(s)}else{this.map.openInfoWindowHtml(this.getInfoPoint(),s)}this.selected=true};e.openInfoWindowAjax=function(){if(this.opts.infoHtml!==""){this.openInfoWindow=e.openInfoWindowBasic;this.openInfoWindow()}else{if(this.opts.infoUrl!==""){var s=this;GDownloadUrl(this.opts.infoUrl,function(t){s.opts.infoHtml=t;s.openInfoWindow()})}else{this.openInfoWindow=e.openInfoWindowBasic;this.openInfoWindow()}}};e.closeInfoWindowBasic=function(){if(this.getType()=="marker"){this.placemark.closeInfoWindow()}else{var s=this.map.getInfoWindow();if(s.getPoint()==this.getInfoPoint()&&!s.isHidden()){this.map.closeInfoWindow()}}this.selected=false};l.util.trim=function(s){s=s&&String(s)||"";return s.replace(/^\s\s*/,"").replace(/\s\s*$/,"")};l.util.isArray=function(s){return s&&!(s.propertyIsEnumerable("length"))&&typeof s==="object"&&typeof s.length==="number"};l.util.getTagValue=function(w,s,u){var v="";var t=l.util.getNodeList(w,s,u);if(t.length>0){w=t[0].firstChild;while(w!==null){v+=w.nodeValue;w=w.nextSibling}}return v};l.util.nsMap={};l.util.getNodeList=function(v,t,u){var s=l.util.nsMap;if(u===f){return v.getElementsByTagName(t)}if(v.getElementsByTagNameNS&&s[u]){return v.getElementsByTagNameNS(s[u],t)}return v.getElementsByTagName(u+":"+t)};l.util.makePoint=function(u,v){var t=null,s=l.util.trim;if(u.lat&&u.lng){t=[u.lat(),u.lng()]}if(l.util.isArray(u)){t=u}if(!t){u=s(u);if(u.indexOf(",")>-1){t=u.split(",")}else{t=u.split(/[\r\n\f ]+/)}}if(t.length>2){t=t.slice(0,2)}if(v){t.reverse()}return{lat:s(t[0]),lon:s(t[1])}};l.util.makePoly=function(v,y){var u=[],t;var w=l.util.trim(v).split(/[\r\n\f ]+/);if(w.length===0){return[]}for(var s=0;s<w.length;s++){t=(w[s].indexOf(",")>0)?w[s].split(","):[w[s],w[++s]];if(t.length>2){t=t.slice(0,2)}if(y){t.reverse()}u.push({lat:t[0],lon:t[1]})}return u};l.util.formatDate=function(y,x){x=x||3;var z="";if(y){if(y.toISOString&&x==3){return y.toISOString()}var s=function(C){return((C<10)?"0":"")+C};var w=y.getUTCFullYear(),t=y.getUTCMonth(),A=y.getUTCDate();z+=w+"-"+s(t+1)+"-"+s(A);if(x>1){var u=y.getUTCHours(),v=y.getUTCMinutes(),B=y.getUTCSeconds();z+="T"+s(u)+":"+s(v);if(x>2){z+=s(B)}z+="Z"}}return z};l.util.TimelineVersion=function(){if(g.version){return g.version}if(g.DurationEventPainter){return"1.2"}else{return"2.2.0"}};l.util.getPlacemarkType=function(s){if("getIcon" in s){return"marker"}if("getVertex" in s){return"setFillStyle" in s?"polygon":"polyline"}return false};l.util.merge=function(){var v={},t=arguments,z,u,s,A;var w=function(B,y,x){if(B.hasOwnProperty(x)&&y[x]===f){y[x]=B[x]}};for(s=0;s<t.length;s++){z=t[s];if(z){if(s>0&&"mergeOnly" in z){for(A=0;A<z.mergeOnly.length;A++){u=z.mergeOnly[A];w(z,v,u)}}else{for(u in z){w(z,v,u)}}}}return v};l.util.lookup=function(s,t){if(typeof(s)=="string"){return t[s]}else{return s}};l.intervals={sec:[h.SECOND,h.MINUTE],min:[h.MINUTE,h.HOUR],hr:[h.HOUR,h.DAY],day:[h.DAY,h.WEEK],wk:[h.WEEK,h.MONTH],mon:[h.MONTH,h.YEAR],yr:[h.YEAR,h.DECADE],dec:[h.DECADE,h.CENTURY]};l.mapTypes={normal:k,satellite:p,hybrid:G_HYBRID_MAP,physical:q,moon:G_MOON_VISIBLE_MAP,sky:G_SKY_VISIBLE_MAP};l.dateParsers={hybrid:o.hybridParser,iso8601:h.parseIso8601DateTime,gregorian:o.gregorianParser};l.themes={red:new m(),blue:new m({iconImage:j+"blue-dot.png",color:"#5A7ACF",eventIconImage:"blue-circle.png"}),green:new m({iconImage:j+"green-dot.png",color:"#19CF54",eventIconImage:"green-circle.png"}),ltblue:new m({iconImage:j+"ltblue-dot.png",color:"#5ACFCF",eventIconImage:"ltblue-circle.png"}),purple:new m({iconImage:j+"purple-dot.png",color:"#8E67FD",eventIconImage:"purple-circle.png"}),orange:new m({iconImage:j+"orange-dot.png",color:"#FF9900",eventIconImage:"orange-circle.png"}),yellow:new m({iconImage:j+"yellow-dot.png",color:"#ECE64A",eventIconImage:"yellow-circle.png"})};i.TimeMap=l;i.TimeMapDataset=o;i.TimeMapTheme=m;i.TimeMapItem=e})();if(!this.JSON){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z"};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];if(typeof c==="string"){return c}return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(typeof value.length==="number"&&!value.propertyIsEnumerable("length")){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}})();TimeMap.prototype.toJSON=function(){var a={options:this.makeOptionData,datasets:this.datasets};a=this.addExportData(a);return a};TimeMap.prototype.makeOptionData=function(){var f={},g=TimeMap.util;var a=this.opts;for(var e in a){if(a.hasOwnProperty(e)){f[e]=a[e]}}if(f.mapCenter){f.mapCenter=g.makePoint(f.mapCenter)}if(f.mapType){f.mapType=g.revHash(TimeMap.mapTypes,f.mapType)}if(f.mapTypes){var d=[],b;for(var i=0;i<f.mapTypes.length;i++){b=g.revHash(TimeMap.mapTypes,f.mapTypes[i]);if(b){d.push(b)}}f.mapTypes=d}if(f.bandIntervals){f.bandIntervals=g.revHash(TimeMap.intervals,f.bandIntervals)}var h=[],j,c;for(c in this.datasets){if(this.datasets.hasOwnProperty(c)){j=g.revHash(TimeMapDataset.themes,this.datasets[c].opts.theme);if(j){h.push(j)}}}f.themes=j;return f};TimeMap.prototype.addExportData=function(a){a.options=a.options||{};a.options.saveOpts=this.opts.saveOpts;return a};TimeMapDataset.prototype.toJSON=function(){var a={title:this.getTitle(),theme:TimeMap.util.revHash(TimeMapDataset.themes,this.opts.theme),data:{type:"basic",value:this.getItems()}};a=this.addExportData(a);return a};TimeMapDataset.prototype.addExportData=function(a){a.options=a.options||{};a.options.saveOpts=this.opts.saveOpts;return a};TimeMapItem.prototype.toJSON=function(){var d={title:this.getTitle(),options:{description:this.opts.description}};if(this.event){d.start=this.event.getStart();if(!this.event.isInstant()){d.end=this.event.getEnd()}}if(this.placemark){var a=TimeMap.util;var c=function(h,g,i){h=h||a.getPlacemarkType(g);switch(h){case"marker":i.point=a.makePoint(g.getLatLng());break;case"polyline":case"polygon":var f=[];for(var e=0;e<g.getVertexCount();e++){f.push(a.makePoint(g.getVertex(e)))}i[h]=f;break}return i};if(this.getType()=="array"){d.placemarks=[];for(var b=0;b<this.placemark.length;b++){d.placemarks.push(c(false,this.placemark[b],{}))}}else{d=c(this.getType(),this.placemark,d)}}d=this.addExportData(d);return d};TimeMapItem.prototype.addExportData=function(a){a.options=a.options||{};a.options.saveOpts=this.opts.saveOpts;return a};TimeMap.util.revHash=function(b,c){for(var a in b){if(b[a]==c){return a}}return null};TimeMap.prototype.clear=function(){this.eachItem(function(a){a.event=a.placemark=null});this.map.clearOverlays();this.eventSource.clear();this.datasets=[]};TimeMap.prototype.deleteDataset=function(a){this.datasets[a].clear();delete this.datasets[a]};TimeMap.prototype.hideDataset=function(a){if(a in this.datasets){this.datasets[a].hide()}};TimeMap.prototype.hideDatasets=function(){this.each(function(a){a.visible=false});this.filter("map");this.filter("timeline");this.timeline.layout()};TimeMap.prototype.showDataset=function(a){if(a in this.datasets){this.datasets[a].show()}};TimeMap.prototype.showDatasets=function(){this.each(function(a){a.visible=true});this.filter("map");this.filter("timeline");this.timeline.layout()};TimeMap.prototype.changeMapType=function(a){if(a==this.opts.mapType){return}if(typeof(a)=="string"){a=TimeMap.mapTypes[a]}if(!a){return}this.opts.mapType=a;this.map.setMapType(a)};TimeMap.prototype.refreshTimeline=function(){var b=this.timeline.getBand(0);var a=b.getCenterVisibleDate();if(TimeMap.util.TimelineVersion()=="1.2"){b.getEventPainter().getLayout()._laidout=false}this.timeline.layout();b.setCenterVisibleDate(a)};TimeMap.prototype.changeTimeIntervals=function(c){if(c==this.opts.bandIntervals){return}if(typeof(c)=="string"){c=TimeMap.intervals[c]}if(!c){return}this.opts.bandIntervals=c;var d=function(g,f){g.getEther()._interval=Timeline.DateTime.gregorianUnitLengths[f];g.getEtherPainter()._unit=f};var e=this.timeline.getBand(0);var b=e.getCenterVisibleDate();for(var a=0;a<this.timeline.getBandCount();a++){d(this.timeline.getBand(a),c[a])}e.getEventPainter().getLayout()._laidout=false;this.timeline.layout();e.setCenterVisibleDate(b)};TimeMap.prototype.scrollTimeline=function(b){var d=this.timeline.getBand(0);var a=d.getCenterVisibleDate();var c=a.getFullYear()+parseFloat(b);a.setFullYear(c);d.setCenterVisibleDate(a)};TimeMapDataset.prototype.clear=function(){this.each(function(a){a.clear()});this.items=[];this.timemap.timeline.layout()};TimeMapDataset.prototype.deleteItem=function(b){for(var a=0;a<this.items.length;a++){if(this.items[a]==b){b.clear();this.items.splice(a,1);break}}this.timemap.timeline.layout()};TimeMapDataset.prototype.show=function(){if(!this.visible){this.visible=true;this.timemap.filter("map");this.timemap.filter("timeline");this.timemap.timeline.layout()}};TimeMapDataset.prototype.hide=function(){if(this.visible){this.visible=false;this.timemap.filter("map");this.timemap.filter("timeline");this.timemap.timeline.layout()}};TimeMapDataset.prototype.changeTheme=function(a){this.opts.theme=a;this.each(function(b){b.changeTheme(a)});this.timemap.timeline.layout()};TimeMapItem.prototype.show=function(){this.showEvent();this.showPlacemark();this.visible=true};TimeMapItem.prototype.hide=function(){this.hideEvent();this.hidePlacemark();this.visible=false};TimeMapItem.prototype.clear=function(){if(this.event){this.dataset.timemap.timeline.getBand(0).getEventSource()._events._events.remove(this.event)}if(this.placemark){this.hidePlacemark();var b=function(d){try{this.map.removeOverlay(d)}catch(c){}};if(this.getType()=="array"){for(var a=0;a<this.placemark.length;a++){b(this.placemark[a])}}else{b(this.placemark)}}this.event=this.placemark=null};TimeMapItem.prototype.createEvent=function(b,d){var a=(d===undefined);var f=this.getTitle();var c=new Timeline.DefaultEventSource.Event(b,d,null,null,a,f,null,null,null,this.opts.theme.eventIcon,this.opts.theme.eventColor,null);c.item=this;this.event=c;this.dataset.eventSource.add(c)};TimeMapItem.prototype.changeTheme=function(c){this.opts.theme=c;if(this.placemark){var b=function(d,e,f){e=e||TimeMap.util.getPlacemarkType(d);switch(e){case"marker":d.setImage(f.icon.image);break;case"polygon":d.setFillStyle({color:c.fillColor,opacity:c.fillOpacity});case"polyline":d.setStrokeStyle({color:c.lineColor,weight:c.lineWeight,opacity:c.lineOpacity});break}};if(this.getType()=="array"){for(var a=0;a<this.placemark.length;a++){b(this.placemark[a],false,c)}}else{b(this.placemark,this.getType(),c)}}if(this.event){this.event._color=c.eventColor;this.event._icon=c.eventIcon}};TimeMapItem.prototype.getNextPrev=function(a,b){if(!this.event){return}var e=this.dataset.timemap.timeline.getBand(0).getEventSource();var c=a?e.getEventReverseIterator(new Date(e.getEarliestDate().getTime()-1),this.event.getStart()):e.getEventIterator(this.event.getStart(),new Date(e.getLatestDate().getTime()+1));var d=null;while(d===null){if(c.hasNext()){d=c.next().item;if(b&&d.dataset!=this.dataset){d=null}}else{break}}return d};TimeMapItem.prototype.getNext=function(a){return this.getNextPrev(false,a)};TimeMapItem.prototype.getPrev=function(a){return this.getNextPrev(true,a)};TimeMap.loaders.flickr=function(b){var a=new TimeMap.loaders.jsonp(b);a.preload=function(c){return c.items};a.transform=function(d){var c={title:d.title,start:d.date_taken,point:{lat:d.latitude,lon:d.longitude},options:{description:d.description.replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&quot;/g,'"')}};if(b.transformFunction){c=b.transformFunction(c)}return c};return a};TimeMap.loaders.georss=function(b){var a=new TimeMap.loaders.remote(b);a.parse=TimeMap.loaders.georss.parse;return a};TimeMap.loaders.georss.parse=function(n){var j=[],w,l,f,r;l=GXml.parse(n);var a=TimeMap.util;var c=a.getTagValue,s=a.getNodeList,p=a.makePoint,b=a.makePoly,g=a.formatDate,e=a.nsMap;e.georss="http://www.georss.org/georss";e.gml="http://www.opengis.net/gml";e.geo="http://www.w3.org/2003/01/geo/wgs84_pos#";e.kml="http://www.opengis.net/kml/2.2";var u=(l.firstChild.tagName=="rss")?"rss":"atom";var q=(u=="rss"?"item":"entry");f=s(l,q);for(var o=0;o<f.length;o++){r=f[o];w={options:{}};w.title=c(r,"title");q=(u=="rss"?"description":"summary");w.options.description=c(r,q);var v=s(r,"TimeStamp","kml");if(v.length>0){w.start=c(v[0],"when","kml")}if(!w.start){v=s(r,"TimeSpan","kml");if(v.length>0){w.start=c(v[0],"begin","kml");w.end=c(v[0],"end","kml")||g(new Date())}}if(!w.start){if(u=="rss"){var t=new Date(Date.parse(c(r,"pubDate")));w.start=g(t)}else{w.start=c(r,"updated")}}var h=false;PLACEMARK:while(!h){var m,k;m=c(r,"point","georss");if(m){w.point=p(m);break PLACEMARK}v=s(r,"Point","gml");if(v.length>0){m=c(v[0],"pos","gml");if(!m){m=c(v[0],"coordinates","gml")}if(m){w.point=p(m);break PLACEMARK}}if(c(r,"lat","geo")){m=[c(r,"lat","geo"),c(r,"long","geo")];w.point=p(m);break PLACEMARK}m=c(r,"line","georss");if(m){w.polyline=b(m);break PLACEMARK}m=c(r,"polygon","georss");if(m){w.polygon=b(m);break PLACEMARK}v=s(r,"LineString","gml");if(v.length>0){k="polyline"}else{v=s(r,"Polygon","gml");if(v.length>0){k="polygon"}}if(v.length>0){m=c(v[0],"posList","gml");if(!m){m=c(v[0],"coordinates","gml")}if(m){w[k]=b(m);break PLACEMARK}}h=true}j.push(w)}l=null;f=null;r=null;v=null;return j};TimeMap.loaders.gss=function(b){var a=new TimeMap.loaders.jsonp(b);if(!a.url){a.url="http://spreadsheets.google.com/feeds/list/"+b.key+"/1/public/values?alt=json-in-script&callback="}a.map=b.map;a.preload=function(c){return c.feed.entry};a.transform=function(g){var e=a.map||TimeMap.loaders.gss.map;var d=function(h){if(h in e&&e[h]){return g["gsx$"+e[h]].$t}else{return false}};var f={title:d("title"),start:d("start"),end:d("end"),point:{lat:d("lat"),lon:d("lon")},options:{description:d("description")}};var c=b.transformFunction;if(c){f=c(f)}return f};return a};TimeMap.loaders.gss.map={title:"title",description:"description",start:"start",end:"end",lat:"lat",lon:"lon"};TimeMap.loaders.jsonp=function(a){TimeMap.loaders.mixin(this,a);this.url=a.url};TimeMap.loaders.jsonp.prototype.load=function(b,c){var a=this;TimeMap.loaders.jsonp.read(this.url,function(d){var e=a.preload(d);b.loadItems(e,a.transform);c()})};TimeMap.loaders.jsonp.counter=0;TimeMap.loaders.jsonp.read=function(b,c){var d="_"+TimeMap.loaders.jsonp.counter++;TimeMap.loaders.jsonp[d]=function(e){c(e);delete TimeMap.loaders.jsonp[d]};var a=document.createElement("script");a.src=b+"TimeMap.loaders.jsonp."+d;document.body.appendChild(a)};TimeMap.loaders.jsonp.cancelAll=function(){var b=TimeMap.loaders.jsonp;for(var a in b){if(a.substr(0,1)=="_"){b[a]=function(){delete b[a]}}}};TimeMap.loaders.json_string=function(b){var a=new TimeMap.loaders.remote(b);a.parse=JSON.parse;return a};TimeMap.loaders.json=TimeMap.loaders.jsonp;TimeMap.loaders.kml=function(b){var a=new TimeMap.loaders.remote(b);a.parse=TimeMap.loaders.kml.parse;return a};TimeMap.loaders.kml.parse=function(t){var g=[],s,n,e,o,l,h;n=GXml.parse(t);var a=TimeMap.util;var c=a.getTagValue,q=a.getNodeList,m=a.makePoint,b=a.makePoly,f=a.formatDate;var d=function(w,v){var i=false;var u=q(w,"TimeStamp");if(u.length>0){v.start=c(u[0],"when");i=true}else{u=q(w,"TimeSpan");if(u.length>0){v.start=c(u[0],"begin");v.end=c(u[0],"end")||f(new Date());i=true}}if(!i){var j=w.parentNode;if(j.nodeName=="Folder"||j.nodeName=="Document"){d(j,v)}j=null}};e=q(n,"Placemark");for(l=0;l<e.length;l++){o=e[l];s={options:{}};s.title=c(o,"name");s.options.description=c(o,"description");d(o,s);var r,k,p;s.placemarks=[];r=q(o,"Point");for(h=0;h<r.length;h++){p={point:{}};k=c(r[h],"coordinates");p.point=m(k,1);s.placemarks.push(p)}r=q(o,"LineString");for(h=0;h<r.length;h++){p={polyline:[]};k=c(r[h],"coordinates");p.polyline=b(k,1);s.placemarks.push(p)}r=q(o,"Polygon");for(h=0;h<r.length;h++){p={polygon:[]};k=c(r[h],"coordinates");p.polygon=b(k,1);s.placemarks.push(p)}g.push(s)}e=q(n,"GroundOverlay");for(l=0;l<e.length;l++){o=e[l];s={options:{},overlay:{}};s.title=c(o,"name");s.options.description=c(o,"description");d(o,s);r=q(o,"Icon");s.overlay.image=c(r[0],"href");r=q(o,"LatLonBox");s.overlay.north=c(r[0],"north");s.overlay.south=c(r[0],"south");s.overlay.east=c(r[0],"east");s.overlay.west=c(r[0],"west");g.push(s)}n=null;e=null;o=null;r=null;return g};TimeMap.loaders.metaweb=function(b){var a=new TimeMap.loaders.jsonp(b);a.HOST=b.host||"http://www.freebase.com";a.QUERY_SERVICE=b.service||"/api/service/mqlread";a.preload=function(f){var g=f.qname;if(g.code.indexOf("/api/status/ok")!==0){return[]}var e=g.result;return e};var d=b.query||{};var c=encodeURIComponent(JSON.stringify({qname:{query:d}}));a.url=a.HOST+a.QUERY_SERVICE+"?queries="+c+"&callback=";return a};TimeMap.loaders.progressive=function(o){var l=o.loader,j=o.type;if(!l){var e=(typeof(j)=="string")?TimeMap.loaders[j]:j;l=new e(o)}function b(p){if(typeof(p)=="string"){p=TimeMapDataset.hybridParser(p)}return p}var h=l.url,i=l.load,d=o.interval,n=o.formatDate||TimeMap.util.formatDate,k=o.formatUrl,m=b(o.start),f=b(o.dataMinDate),c=b(o.dataMaxDate),g={};if(!k){k=function(q,r,p){return q.replace("[start]",n(r)).replace("[end]",n(p))}}var a=function(p){var q=p.timemap.timeline.getBand(0);q.addOnScrollListener(function(){var s=q.getCenterVisibleDate(),t=Math.floor((s.getTime()-m.getTime())/d),r=m.getTime()+(d*t);nextBlockTime=r+d,prevBlockTime=r-d,callback=function(){p.timemap.timeline.layout()};if((!c||r<c.getTime())&&(!f||r>f.getTime())&&!g[t]){l.load(p,callback,new Date(r),t)}if(nextBlockTime<q.getMaxDate().getTime()&&(!c||nextBlockTime<c.getTime())&&!g[t+1]){l.load(p,callback,new Date(nextBlockTime),t+1)}if(prevBlockTime>q.getMinDate().getTime()&&(!f||prevBlockTime>f.getTime())&&!g[t-1]){l.load(p,callback,new Date(prevBlockTime),t-1)}});a=false};l.load=function(r,t,s,q){s=b(s)||m;q=q||0;var p=new Date(s.getTime()+d);g[q]=true;l.url=k(h,s,p);i.call(l,r,function(){if(a){a(r)}t()})};return l};
