function GPXParser(a,b){this.xmlDoc=a;this.map=b;this.trackcolour="#ff00ff";this.trackwidth=5;this.mintrackpointdelta=1.0E-4}
GPXParser.prototype.ParseTime=function(a){a=a.match(new RegExp("([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"));var b=0,c=new Date(a[1],0,1);a[3]&&c.setMonth(a[3]-1);a[5]&&c.setDate(a[5]);a[7]&&c.setHours(a[7]);a[8]&&c.setMinutes(a[8]);a[10]&&c.setSeconds(a[10]);a[12]&&c.setMilliseconds(Number("0."+a[12])*1E3);if(a[14]){b=Number(a[16])*60+Number(a[17]);b*=a[15]=="-"?1:-1}b-=c.getTimezoneOffset();time=Number(c)+b*60*1E3;
c.setTime(Number(time));return c};GPXParser.prototype.SetTrackColour=function(a){this.trackcolour=a};GPXParser.prototype.SetTrackWidth=function(a){this.trackwidth=a};GPXParser.prototype.SetMinTrackPointDelta=function(a){this.mintrackpointdelta=a};GPXParser.prototype.TranslateName=function(a){if(a=="wpt")return"Waypoint";else if(a=="trkpt")return"Track Point"};
GPXParser.prototype.CreateMarker=function(a){var b=parseFloat(a.getAttribute("lon")),c=parseFloat(a.getAttribute("lat")),d="";if(a.getElementsByTagName("html").length>0)for(i=0;i<a.getElementsByTagName("html").item(0).childNodes.length;i++)d+=a.getElementsByTagName("html").item(0).childNodes[i].nodeValue;else{d="<b>"+this.TranslateName(a.nodeName)+"</b><br>";var e=a.attributes,j=e.length;for(i=0;i<j;i++)d+=e.item(i).name+" = "+e.item(i).nodeValue+"<br>";if(a.hasChildNodes){a=a.childNodes;e=a.length;
for(i=0;i<e;i++)if(a[i].nodeType==1)d+=a[i].nodeName+" = "+a[i].firstChild.nodeValue+"<br>"}}var f=new GMarker(new GLatLng(c,b));GEvent.addListener(f,"click",function(){f.openInfoWindowHtml(d)});this.map.addOverlay(f)};
GPXParser.prototype.AddTrackSegmentToMap=function(a,b,c){a=a.getElementsByTagName("trkpt");if(a.length!=0){var d=[],e=parseFloat(a[0].getAttribute("lon")),j=parseFloat(a[0].getAttribute("lat")),f=new GLatLng(j,e);d.push(f);previousTime=0;for(var g=1;g<a.length;g++){f=parseFloat(a[g].getAttribute("lon"));var h=parseFloat(a[g].getAttribute("lat")),k=h-j,l=f-e;if(Math.sqrt(k*k+l*l)>this.mintrackpointdelta){e=f;j=h;f=new GLatLng(h,f);d.push(f);timeElement=a[g].getElementsByTagName("time")[0];timeString=
timeElement.childNodes[0].nodeValue;newDate=this.ParseTime(timeString);newTime=newDate.getTime();if(newTime-previousTime>6E5){this.CreateMarker(a[g]);previousTime=newTime}}}this.map.addOverlay(new GPolyline(d,b,c))}};GPXParser.prototype.AddTrackToMap=function(a,b,c){a=a.getElementsByTagName("trkseg");for(var d=0;d<a.length;d++)this.AddTrackSegmentToMap(a[d],b,c)};
GPXParser.prototype.CenterAndZoom=function(a,b){for(var c=new Array("trkpt","wpt"),d=0,e=0,j=0,f=0,g=0;g<c.length;g++){var h=a.getElementsByTagName(c[g]);if(h.length>0&&d==e&&d==0){d=parseFloat(h[0].getAttribute("lat"));e=parseFloat(h[0].getAttribute("lat"));j=parseFloat(h[0].getAttribute("lon"));f=parseFloat(h[0].getAttribute("lon"))}for(var k=0;k<h.length;k++){var l=parseFloat(h[k].getAttribute("lon")),m=parseFloat(h[k].getAttribute("lat"));if(l<j)j=l;if(l>f)f=l;if(m<d)d=m;if(m>e)e=m}}if(d==e&&
(d=0))this.map.setCenter(new GLatLng(49.327667,-122.942333),14);else{c=(f+j)/2;g=(e+d)/2;d=new GLatLngBounds(new GLatLng(d,j),new GLatLng(e,f));this.map.setCenter(new GLatLng(g,c),this.map.getBoundsZoomLevel(d),b)}};
GPXParser.prototype.CenterAndZoomToLatLngBounds=function(a){for(var b=new GLatLngBounds,c=0;c<a.length;c++)if(!a[c].isEmpty()){b.extend(a[c].getSouthWest());b.extend(a[c].getNorthEast())}a=(b.getNorthEast().lat()+b.getSouthWest().lat())/2;c=(b.getNorthEast().lng()+b.getSouthWest().lng())/2;this.map.setCenter(new GLatLng(a,c),this.map.getBoundsZoomLevel(b))};
GPXParser.prototype.AddTrackpointsToMap=function(){for(var a=this.xmlDoc.documentElement.getElementsByTagName("trk"),b=0;b<a.length;b++)this.AddTrackToMap(a[b],this.trackcolour,this.trackwidth)};GPXParser.prototype.AddWaypointsToMap=function(){for(var a=this.xmlDoc.documentElement.getElementsByTagName("wpt"),b=0;b<a.length;b++)this.CreateMarker(a[b])};

