/* 
 * TimeMap Copyright 2008 Nick Rabinowitz.
 * Licensed under the MIT License (see LICENSE.txt)
 */
function TimeMap(a,d,b){this.mElement=d;this.tElement=a;this.datasets={};this.filters={};this.mapBounds=new GLatLngBounds();this.opts=b||{};if(typeof(b.mapType)=="string"){b.mapType=TimeMap.mapTypes[b.mapType]}this.opts.mapCenter=b.mapCenter||new GLatLng(0,0);this.opts.mapZoom=b.mapZoom||0;this.opts.mapType=b.mapType||G_PHYSICAL_MAP;this.opts.mapTypes=b.mapTypes||[G_NORMAL_MAP,G_SATELLITE_MAP,G_PHYSICAL_MAP];this.opts.syncBands=("syncBands" in b)?b.syncBands:true;this.opts.showMapTypeCtrl=("showMapTypeCtrl" in b)?b.showMapTypeCtrl:true;this.opts.showMapCtrl=("showMapCtrl" in b)?b.showMapCtrl:true;this.opts.hidePastFuture=("hidePastFuture" in b)?b.hidePastFuture:true;this.opts.showMomentOnly=("showMomentOnly" in b)?b.showMomentOnly:false;this.opts.centerMapOnItems=("centerMapOnItems" in b)?b.centerMapOnItems:true;if(GBrowserIsCompatible()){this.map=new GMap2(this.mElement);if(this.opts.showMapCtrl){this.map.addControl(new GLargeMapControl())}if(this.opts.showMapTypeCtrl){this.map.addControl(new GMapTypeControl())}for(var c=G_DEFAULT_MAP_TYPES.length-1;c>0;c--){this.map.removeMapType(G_DEFAULT_MAP_TYPES[c])}this.map.addMapType(this.opts.mapTypes[0]);this.map.removeMapType(G_DEFAULT_MAP_TYPES[0]);for(var c=1;c<this.opts.mapTypes.length;c++){this.map.addMapType(this.opts.mapTypes[c])}this.map.enableDoubleClickZoom();this.map.enableScrollWheelZoom();this.map.enableContinuousZoom();this.map.setCenter(this.opts.mapCenter,this.opts.mapZoom);this.map.setMapType(this.opts.mapType)}}TimeMap.version="1.4";TimeMap.init=function(d){if(!("mapId" in d)||!d.mapId){alert("TimeMap init: No map id was specified!");return}if(!("timelineId" in d)||!d.timelineId){alert("TimeMap init: No timeline id was specified!");return}d=d||{};d.options=d.options||{};d.datasets=d.datasets||[];d.bandInfo=d.bandInfo||false;d.scrollTo=d.scrollTo||"earliest";if(!d.bandInfo){var i=d.bandIntervals||d.options["bandIntervals"]||[Timeline.DateTime.WEEK,Timeline.DateTime.MONTH];if(typeof(i)=="string"){i=TimeMap.intervals[i]}d.options["bandIntervals"]=i;d.bandInfo=[{width:"80%",intervalUnit:i[0],intervalPixels:70},{width:"20%",intervalUnit:i[1],intervalPixels:100,showEventText:false,overview:true,trackHeight:0.4,trackGap:0.2}]}var l=new TimeMap(document.getElementById(d.timelineId),document.getElementById(d.mapId),d.options);var h=[];for(var k=0;k<d.datasets.length;k++){var c=d.datasets[k];var f=c.options||{};f.title=c.title||"";f.theme=c.theme||undefined;if(c.dateParser){f.dateParser=c.dateParser}var b=c.id||"ds"+k;h[k]=l.createDataset(b,f);if(k>0){h[k].eventSource=h[0].eventSource}}var g=[];var e=(h[0]&&h[0]["eventSource"])||new Timeline.DefaultEventSource();for(var k=0;k<d.bandInfo.length;k++){var j=d.bandInfo[k];if(!(("eventSource" in j)&&j.eventSource==null)){j.eventSource=e}else{j.eventSource=null}g[k]=Timeline.createBandInfo(j);if(k>0&&TimeMap.TimelineVersion()=="1.2"){g[k].eventPainter.setLayout(g[0].eventPainter.getLayout())}}l.initTimeline(g);var a={};a.count=0;a.loadTarget=d.datasets.length;a.ifLoadedFunction=function(){if(d.dataLoadedFunction){d.dataLoadedFunction(l)}else{var m=new Date();if(e.getCount()>0){if(d.scrollTo=="earliest"){m=e.getEarliestDate()}else{if(d.scrollTo!="now"&&d.scrollTo!=null){m=e.getLatestDate()}}l.timeline.getBand(0).setCenterVisibleDate(m)}l.timeline.layout();if(d.dataDisplayedFunction){d.dataDisplayedFunction(l)}}};a.ifLoaded=function(){this.count++;if(this.count==this.loadTarget){this.ifLoadedFunction()}};for(var k=0;k<d.datasets.length;k++){(function(m){var s=d.datasets[m]["data"];var r=h[m];var t=function(u){return u};var p=d.datasets[m]["preloadFunction"]||t;var o=d.datasets[m]["transformFunction"]||t;switch(s.type){case"basic":var n=p(s.value);r.loadItems(n,o);a.ifLoaded();break;case"json":JSONLoader.read(s.url,function(u){var v=p(u);r.loadItems(v,o);a.ifLoaded()});break;case"kml":case"georss":var q=s.type=="kml"?TimeMapDataset.parseKML:TimeMapDataset.parseGeoRSS;GDownloadUrl(s.url,function(u){var v=q(u);v=p(v);r.loadItems(v,o);a.ifLoaded()});break;case"metaweb":Metaweb.read(s.query,function(u){var v=p(u);r.loadItems(u,o);a.ifLoaded()});break}})(k)}return l};var timemapInit=TimeMap.init;TimeMap.intervals={sec:[Timeline.DateTime.SECOND,Timeline.DateTime.MINUTE],min:[Timeline.DateTime.MINUTE,Timeline.DateTime.HOUR],hr:[Timeline.DateTime.HOUR,Timeline.DateTime.DAY],day:[Timeline.DateTime.DAY,Timeline.DateTime.WEEK],wk:[Timeline.DateTime.WEEK,Timeline.DateTime.MONTH],mon:[Timeline.DateTime.MONTH,Timeline.DateTime.YEAR],yr:[Timeline.DateTime.YEAR,Timeline.DateTime.DECADE],dec:[Timeline.DateTime.DECADE,Timeline.DateTime.CENTURY]};TimeMap.mapTypes={normal:G_NORMAL_MAP,satellite:G_SATELLITE_MAP,hybrid:G_HYBRID_MAP,physical:G_PHYSICAL_MAP,moon:G_MOON_VISIBLE_MAP,sky:G_SKY_VISIBLE_MAP};TimeMap.prototype.createDataset=function(d,b){b=b||{};if(!("title" in b)){b.title=d}var c=new TimeMapDataset(this,b);this.datasets[d]=c;if(this.opts.centerMapOnItems){var a=this;GEvent.addListener(c,"itemsloaded",function(){a.map.setZoom(a.map.getBoundsZoomLevel(a.mapBounds));a.map.setCenter(a.mapBounds.getCenter())})}return c};TimeMap.prototype.each=function(a){for(id in this.datasets){a(this.datasets[id])}};TimeMap.prototype.initTimeline=function(e){for(var a=1;a<e.length;a++){if(this.opts.syncBands){e[a].syncWith=(a-1)}e[a].highlight=true}this.timeline=Timeline.create(this.tElement,e);var c=this;this.timeline.getBand(0).addOnScrollListener(function(){c.filter("map")});GEvent.addListener(c.map,"moveend",function(){c.filter("timeline")});var b=this.timeline.getBand(0).getEventPainter().constructor;b.prototype._showBubble=function(f,h,g){g.item.openInfoWindow()};this.addFilterChain("map",function(f){f.showPlacemark()},function(f){f.hidePlacemark()});this.addFilter("map",function(f){return f.dataset.visible});if(this.opts.hidePastFuture){this.addFilter("map",TimeMap.hidePastFuture)}else{if(this.opts.showMomentOnly){this.addFilter("map",TimeMap.showMomentOnly)}}resizeTimerID=null;var d=this.timeline;window.onresize=function(){if(resizeTimerID==null){resizeTimerID=window.setTimeout(function(){resizeTimerID=null;d.layout()},500)}}};TimeMap.prototype.filter=function(b){var a=this.filters[b];if(!a||!a.chain||a.chain.length==0){return}this.each(function(c){c.each(function(e){F_LOOP:{for(var d=a.chain.length-1;d>=0;d--){if(!a.chain[d](e)){a.off(e);break F_LOOP}}a.on(e)}})})};TimeMap.prototype.addFilterChain=function(c,b,a){this.filters[c]={chain:[],on:b,off:a}};TimeMap.prototype.removeFilterChain=function(c,a,b){this.filters[c]=null};TimeMap.prototype.addFilter=function(b,a){if(this.filters[b]&&this.filters[b].chain){this.filters[b].chain.push(a)}};TimeMap.prototype.removeFilter=function(a){if(this.filters[a]&&this.filters[a].chain){this.filters[a].chain.pop()}};TimeMap.hidePastFuture=function(d){var f=d.dataset.timemap.timeline.getBand(0);var b=f.getMaxVisibleDate().getTime();var c=f.getMinVisibleDate().getTime();if(d.event!=null){var a=d.event.getStart().getTime();var e=d.event.getEnd().getTime();if(a>b){return false}else{if(e<c||(d.event.isInstant()&&a<c)){return false}}}return true};TimeMap.showMomentOnly=function(b){var d=b.dataset.timemap.timeline.getBand(0);var e=d.getCenterVisibleDate().getTime();if(b.event!=null){var a=b.event.getStart().getTime();var c=b.event.getEnd().getTime();if(a>e){return false}else{if(c<e||(b.event.isInstant()&&a<e)){return false}}}return true};function TimeMapDataset(a,b){this.timemap=a;this.eventSource=new Timeline.DefaultEventSource();this.items=[];this.visible=true;this.opts=b||{};this.opts.title=b.title||"";if(typeof(b.theme)=="string"){b.theme=TimeMapDataset.themes[b.theme]}this.opts.theme=b.theme||this.timemap.opts.theme||new TimeMapDatasetTheme({});this.opts.theme.eventIconPath=b.eventIconPath||this.timemap.opts.eventIconPath||this.opts.theme.eventIconPath;this.opts.theme.eventIcon=b.eventIconPath+this.opts.theme.eventIconImage;if(typeof(b.dateParser)=="string"){b.dateParser=TimeMapDataset.dateParsers[b.dateParser]}this.opts.dateParser=b.dateParser||TimeMapDataset.hybridParser;this.getItems=function(){return this.items};this.getTitle=function(){return this.opts.title}}TimeMapDataset.hybridParser=function(a){var b=Timeline.DateTime.parseIso8601DateTime(a);if(!b){b=Timeline.DateTime.parseGregorianDateTime(a)}return b};TimeMapDataset.dateParsers={hybrid:TimeMapDataset.hybridParser,iso8601:Timeline.DateTime.parseIso8601DateTime,gregorian:Timeline.DateTime.parseGregorianDateTime};TimeMapDataset.prototype.each=function(b){for(var a=0;a<this.items.length;a++){b(this.items[a])}};TimeMapDataset.prototype.loadItems=function(c,b){for(var a=0;a<c.length;a++){this.loadItem(c[a],b)}GEvent.trigger(this,"itemsloaded")};TimeMapDataset.prototype.loadItem=function(v,k){if(k!=undefined){v=k(v)}if(v==null){return}var e=v.options||{};if(typeof(e.theme)=="string"){e.theme=TimeMapDataset.themes[e.theme]}var u=e.theme||this.opts.theme;u.eventIconPath=e.eventIconPath||this.opts.theme.eventIconPath;u.eventIcon=u.eventIconPath+u.eventIconImage;var d=this.timemap;var h=(v.start==undefined||v.start=="")?null:this.opts.dateParser(v.start);var g=(v.end==undefined||v.end=="")?null:this.opts.dateParser(v.end);var c=(v.end==undefined);var b=u.eventIcon;var w=v.title;if(h!=null){if(TimeMap.TimelineVersion()=="1.2"){var q=new Timeline.DefaultEventSource.Event(h,g,null,null,c,w,null,null,null,b,u.eventColor,null)}else{var q=new Timeline.DefaultEventSource.Event({start:h,end:g,instant:c,text:w,icon:b,color:u.eventColor})}}else{var q=null}var m=function(z){var y=null,A="",C=null;if("point" in z){C=new GLatLng(parseFloat(z.point.lat),parseFloat(z.point.lon));if(d.opts.centerMapOnItems){d.mapBounds.extend(C)}markerIcon=("icon" in z)?z.icon:u.icon;y=new GMarker(C,{icon:markerIcon});A="marker";C=y.getLatLng()}else{if("polyline" in z||"polygon" in z){var E=[];if("polyline" in z){var F=z.polyline}else{var F=z.polygon}for(var B=0;B<F.length;B++){C=new GLatLng(parseFloat(F[B]["lat"]),parseFloat(F[B]["lon"]));E.push(C);if(d.opts.centerMapOnItems){d.mapBounds.extend(C)}}if("polyline" in z){y=new GPolyline(E,u.lineColor,u.lineWeight,u.lineOpacity);A="polyline";C=y.getVertex(Math.floor(y.getVertexCount()/2))}else{y=new GPolygon(E,u.polygonLineColor,u.polygonLineWeight,u.polygonLineOpacity,u.fillColor,u.fillOpacity);A="polygon";C=y.getBounds().getCenter()}}else{if("overlay" in z){var D=new GLatLng(parseFloat(z.overlay.south),parseFloat(z.overlay.west));var p=new GLatLng(parseFloat(z.overlay.north),parseFloat(z.overlay.east));if(d.opts.centerMapOnItems){d.mapBounds.extend(D);d.mapBounds.extend(p)}var i=new GLatLngBounds(D,p);y=new GGroundOverlay(z.overlay.image,i);A="overlay";C=i.getCenter()}}}return{placemark:y,type:A,point:C}};var t=[],n=[],a=null,f="",o=null;if("placemarks" in v){n=v.placemarks}else{var j=["point","polyline","polygon","overlay"];for(var r=0;r<j.length;r++){if(j[r] in v){a={};a[j[r]]=v[j[r]];n.push(a)}}}if(n){for(var r=0;r<n.length;r++){var l=m(n[r]);if(!o){o=l.point}if(!f){f=l.type}t.push(l.placemark)}}if(t.length>1){f="array"}e.title=w;e.type=f||"none";e.theme=u;if(e.infoPoint){e.infoPoint=new GLatLng(parseFloat(e.infoPoint.lat),parseFloat(e.infoPoint.lon))}else{e.infoPoint=o}var s=new TimeMapItem(t,q,this,e);if(q!=null){q.item=s;this.eventSource.add(q)}if(t.length>0){for(var r=0;r<t.length;r++){t[r].item=s;GEvent.addListener(t[r],"click",function(){s.openInfoWindow()});d.map.addOverlay(t[r]);t[r].hide()}}this.items.push(s);return s};function TimeMapDatasetTheme(b){b=b||{};if(!b.icon){var a=new GIcon(G_DEFAULT_ICON);this.iconImage=b.iconImage||"http://www.google.com/intl/en_us/mapfiles/ms/icons/red-dot.png";a.image=this.iconImage;a.iconSize=new GSize(32,32);a.shadow="http://www.google.com/intl/en_us/mapfiles/ms/icons/msmarker.shadow.png";a.shadowSize=new GSize(59,32)}this.icon=b.icon||a;this.color=b.color||"#FE766A";this.lineColor=b.lineColor||this.color;this.polygonLineColor=b.polygonLineColor||this.lineColor;this.lineOpacity=b.lineOpacity||1;this.polgonLineOpacity=b.polgonLineOpacity||this.lineOpacity;this.lineWeight=b.lineWeight||2;this.polygonLineWeight=b.polygonLineWeight||this.lineWeight;this.fillColor=b.fillColor||this.color;this.fillOpacity=b.fillOpacity||0.25;this.eventColor=b.eventColor||this.color;this.eventIconPath=b.eventIconPath||"timemap/images/";this.eventIconImage=b.eventIconImage||"red-circle.png";this.eventIcon=b.eventIcon||this.eventIconPath+this.eventIconImage}TimeMapDataset.redTheme=function(a){return new TimeMapDatasetTheme(a)};TimeMapDataset.blueTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png";a.color="#5A7ACF";a.eventIconImage="blue-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.greenTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/green-dot.png";a.color="#19CF54";a.eventIconImage="green-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.ltblueTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/ltblue-dot.png";a.color="#5ACFCF";a.eventIconImage="ltblue-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.purpleTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/purple-dot.png";a.color="#8E67FD";a.eventIconImage="purple-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.orangeTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/orange-dot.png";a.color="#FF9900";a.eventIconImage="orange-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.yellowTheme=function(a){a=a||{};a.iconImage="http://www.google.com/intl/en_us/mapfiles/ms/icons/yellow-dot.png";a.color="#ECE64A";a.eventIconImage="yellow-circle.png";return new TimeMapDatasetTheme(a)};TimeMapDataset.themes={red:TimeMapDataset.redTheme(),blue:TimeMapDataset.blueTheme(),green:TimeMapDataset.greenTheme(),ltblue:TimeMapDataset.ltblueTheme(),orange:TimeMapDataset.orangeTheme(),yellow:TimeMapDataset.yellowTheme(),purple:TimeMapDataset.purpleTheme()};function TimeMapItem(b,c,d,a){this.event=c;this.dataset=d;this.map=d.timemap.map;if(b&&TimeMap.isArray(b)&&b.length==0){b=null}if(b&&b.length==1){b=b[0]}this.placemark=b;this.opts=a||{};this.opts.type=a.type||"";this.opts.title=a.title||"";this.opts.description=a.description||"";this.opts.infoPoint=a.infoPoint||null;this.opts.infoHtml=a.infoHtml||"";this.opts.infoUrl=a.infoUrl||"";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=false;this.showPlacemark=function(){if(this.placemark){if(this.getType()=="array"){for(var e=0;e<this.placemark.length;e++){this.placemark[e].show()}}else{this.placemark.show()}this.visible=true}};this.hidePlacemark=function(){if(this.placemark){if(this.getType()=="array"){for(var e=0;e<this.placemark.length;e++){this.placemark[e].hide()}}else{this.placemark.hide()}this.visible=false}this.closeInfoWindow()};this.openInfoWindow=a.openInfoWindow||d.opts.openInfoWindow||d.timemap.opts.openInfoWindow||false;if(!this.openInfoWindow){if(this.opts.infoUrl!=""){this.openInfoWindow=TimeMapItem.openInfoWindowAjax}else{this.openInfoWindow=TimeMapItem.openInfoWindowBasic}}this.closeInfoWindow=a.closeInfoWindow||TimeMapItem.closeInfoWindowBasic}TimeMapItem.openInfoWindowBasic=function(){var a=this.opts.infoHtml;if(a==""){a='<div class="infotitle">'+this.opts.title+"</div>";if(this.opts.description!=""){a+='<div class="infodescription">'+this.opts.description+"</div>"}}if(this.placemark&&!this.visible&&this.event){var b=this.dataset.timemap.timeline.getBand(0);b.setCenterVisibleDate(this.event.getStart())}if(this.getType()=="marker"){this.placemark.openInfoWindowHtml(a)}else{this.map.openInfoWindowHtml(this.getInfoPoint(),a)}};TimeMapItem.openInfoWindowAjax=function(){if(this.opts.infoHtml!=""){this.openInfoWindow=TimeMapItem.openInfoWindowBasic;this.openInfoWindow()}else{if(this.opts.infoUrl!=""){var a=this;GDownloadUrl(this.opts.infoUrl,function(b){a.opts.infoHtml=b;a.openInfoWindow()})}else{this.openInfoWindow=TimeMapItem.openInfoWindowBasic;this.openInfoWindow()}}};TimeMapItem.closeInfoWindowBasic=function(){if(this.getType()=="marker"){this.placemark.closeInfoWindow()}else{var a=this.map.getInfoWindow();if(a.getPoint()==this.getInfoPoint()&&!a.isHidden()){this.map.closeInfoWindow()}}};TimeMap.trim=function(a){a=a&&String(a)||"";return a.replace(/^\s\s*/,"").replace(/\s\s*$/,"")};TimeMap.isArray=function(a){return a&&!(a.propertyIsEnumerable("length"))&&typeof a==="object"&&typeof a.length==="number"};TimeMap.getTagValue=function(e,a,c){var d="";var b=TimeMap.getNodeList(e,a,c);if(b.length>0){var e=b[0].firstChild;while(e!=null){d+=e.nodeValue;e=e.nextSibling}}return d};TimeMap.nsMap={};TimeMap.getNodeList=function(c,a,b){if(b==undefined){return c.getElementsByTagName(a)}if(c.getElementsByTagNameNS&&TimeMap.nsMap[b]){return c.getElementsByTagNameNS(TimeMap.nsMap[b],a)}return c.getElementsByTagName(b+":"+a)};TimeMap.makePoint=function(b){var a;if(b.lat&&b.lng){a=[b.lat(),b.lng()]}if(TimeMap.isArray(b)){a=b}else{if(b.indexOf(",")>-1){a=b.split(",")}else{a=b.split(/[\r\n\f ]+/)}}return{lat:TimeMap.trim(a[0]),lon:TimeMap.trim(a[1])}};TimeMap.formatDate=function(h,b){b=b||3;var g="";if(h){if(h.toISOString){return h.toISOString()}var i=h.getUTCFullYear(),f=h.getUTCMonth(),a=h.getUTCDate();g+=i+"-"+((f<9)?"0":"")+(f+1)+"-"+((a<10)?"0":"")+a;if(b>1){var e=h.getUTCHours(),f=h.getUTCMinutes(),c=h.getUTCSeconds();g+="T"+((e<10)?"0":"")+e+":"+((f<10)?"0":"")+f;if(b>2){g+=((c<10)?"0":"")+c}g+="Z"}}return g};TimeMap.TimelineVersion=function(){if(Timeline.DurationEventPainter){return"1.2"}else{return"2.2.0"}};