MTK.ElevationProfile=MTK.ElevationProfile2=function(c){function G(b){return c.i18n[b]||K[b]||b}var B=this,a={},h,s,r,w,I=false,o,x=0,E=false,A=false,t,p;MTK.ElevationProfile.profiles[c.js]=this;setTimeout(function(){jQuery.getScript(c.js)},100);c.unit=c.unit||"km";c.position=c.position||c.positionBar||{};var C={km:["hm","km","m",1],miles:["ft","mi","ft",3.2808399]};c.i18n=c.i18n||{};var K={clickAndDrag:"Click and drag to select section",title:"Elevation Profile",reverse:"Show reverse profile"},i=
c.js.match(/(.+?)\/(\d+\/)?(([\w-]+)\.([^\/]+\.)?([\w-]+))$/);if(i){var j=i[1];i=i[3];var k=MTK.ElevationProfile.profiles;k[j+"/"+i]=this;k[j+"/0/"+i]=this;k[j+"/1/"+i]=this;k[j+"/2/"+i]=this;k[j+"/3/"+i]=this;k[j+"/4/"+i]=this;k[j+"/5/"+i]=this;k[j+"/6/"+i]=this;k[j+"/7/"+i]=this;k[j+"/8/"+i]=this;k[j+"/9/"+i]=this;j=j.replace("http://static.toursprung.com","http://mtk2.toursprung.com/static");j=j.replace("http://static-dev.toursprung.com","http://mtk2.toursprung.com/static");k[j+"/"+i]=this;k[j+
"/0/"+i]=this;k[j+"/1/"+i]=this;k[j+"/2/"+i]=this;k[j+"/3/"+i]=this;k[j+"/4/"+i]=this;k[j+"/5/"+i]=this;k[j+"/6/"+i]=this;k[j+"/7/"+i]=this;k[j+"/8/"+i]=this;k[j+"/9/"+i]=this;MTK.ElevationProfile.profiles=k;MTK.ElevationProfile2.profiles=k;MapToolkit.ElevationProfile2.profiles=k}var D=new MTK.Marker({position:$P(0,0),icon:c.icon,shadow:c.shadow});B.init=function(b){a=b;a.vertices=jQuery.map(a.vertices,function(e){return $P(e)});h=document.createElement("div");h.className="mtk-elevation-container";
h.style.width=a.width+45+"px";h.style.height=a.height+(c.header?30:10)+"px";h.style.zIndex=1100;h.style.position="absolute";jQuery(h).css("opacity",c.opacity||0.8).css(c.style||{});bg=document.createElement("img");bg.src="http://static.toursprung.com/images/white.png";bg.className="mtk-elevation-container-bg";bg.style.width=a.width+43+"px";bg.style.height=a.height+(c.header?45:25)+"px";h.appendChild(bg);if(c.header){b=document.createElement("div");b.style.width=a.width+35+"px";b.className="mtk-elevation-header";
b.innerHTML=G("title");h.appendChild(b);if(jQuery.draggable){b.style.cursor="move";jQuery(h).draggable()}}imgBg=document.createElement("img");imgBg.className="mtk-elevation-img-bg";imgBg.src="http://static.toursprung.com/images/black.png";imgBg.style.width=a.width+"px";imgBg.style.height=a.height+"px";s=document.createElement("img");s.className="mtk-elevation-img";s.src=a.img_src.forward;s.style.width=a.width+"px";s.style.height=a.height+"px";var g=0,f=[],y=a.width/10,m=10;b=a.axis[c.unit];if(b.x[1]){m=
b.x[1][1]%3==0?3:b.x[1][1]%5==0?5:4;y=b.x[1][0]/m}for(var z=0;z<b.x.length*m;z++)f.push(parseInt(g+=y));g=jQuery.map(b.y,function(e){return e[0]});y=b.x[b.x.length-1][0]/((b.x.length-1)*m)*f.length;m=document.createElement("div");m.className="mtk-elevation-grid";m.style.width=s.style.width;m.style.height=s.style.height;m.style.overflow="hidden";m.appendChild(L(f,g,y));jQuery.browser.msie||jQuery(m).css("opacity",0.2);p=document.createElement("div");p.className="mtk-elevation-position";p.style.top=
(c.header?27:7)+"px";p.style.height=a.height+"px";p.style.width=(c.position.width||"1")+"px";p.style.backgroundColor=c.position.color||"#ff6666";jQuery(p).css("opacity",0.5);o=document.createElement("div");o.className="mtk-elevation-area";o.style.top=(c.header?27:7)+"px";o.style.height=a.height+"px";o.style.backgroundColor=c.position.color||"#ff6666";jQuery(o).css("opacity",0.2);t=document.createElement("div");t.className="mtk-elevation-details";t.style.top=(c.header?23:3)+"px";t.innerHTML="&nbsp;";
r=document.createElement("div");r.className="mtk-elevation-tt";r.style.width=a.width+"px";r.innerHTML=G("clickAndDrag");f=document.createElement("div");f.innerHTML=C[c.unit][1];f.className="mtk-elevation-label";f.style.bottom="3px";f.style.right="10px";h.appendChild(f);f=document.createElement("div");f.innerHTML=C[c.unit][0];f.className="mtk-elevation-label";f.style.top=c.header?"23px":"3px";f.style.right=a.width+14+"px";h.appendChild(f);jQuery.map(b.x,function(e){var d=document.createElement("div");
d.innerHTML=e[1];d.className="mtk-elevation-label";d.style.bottom="3px";d.style.left=e[0]+13+"px";d.style.width="40px";h.appendChild(d)});jQuery.map(b.y,function(e){var d=document.createElement("div");d.innerHTML=e[1];d.className="mtk-elevation-label";d.style.bottom=e[0]+14+"px";d.style.right=a.width+14+"px";h.appendChild(d)});b=document.createElement("div");b.className="mtk-elevation-axis";h.appendChild(b);b=document.createElement("img");b.className="mtk-elevation-mouse";b.src=MTK.staticHost+"/images/t.gif";
b.style.top=(c.header?27:7)+"px";b.style.width=a.width+"px";b.style.height=a.height+"px";b.onmouseover=function(){if(!A)r.style.display="block";c.onmouseover&&c.onmouseover()};b.onmousedown=function(e){e=e||window.event;var d=J(e);if(d){if(A){A=false;r.style.display="block";w&&w.setMap(null)}else{r.style.display="none";H();o.style.width="1px";A=E=true;x=d[0];o.style.display="block";o.style.left=d[2]+"px"}e.preventDefault&&e.preventDefault();e.stopPropagation&&e.stopPropagation();return e.returnValue=
false}};b.onmouseup=function(){E=false};b.onmousemove=function(e){e=e||window.event;var d=J(e);if(A){d=d?d[0]-x:a.elevation_per_pixel.length-x;if(d<0)d=0;if(E){o.style.width=d+"px";var n=a.elevation_per_5m||a.elevation_per_100m,l=Math.floor(x/a.width*n.length),u=Math.floor((x+d)/a.width*n.length),v=[];for(l=l;l<u;l++)v.push(n[l]);v=M(v);n=0;u=v[0];for(l=1;l<v.length;l++){var F=v[l];if(F>u)n+=F-u;u=F}t.innerHTML=parseInt(n*C[c.unit][3])+" "+C[c.unit][0];w&&w.setMap(null);if(a.vertices&&d){v=[$P(a.elevation_per_pixel[x])];
n=0;u=a.vertices[0];F=a.distance/a.elevation_per_pixel.length*x;var N=a.distance/a.elevation_per_pixel.length*(x+d);for(l=1;l<a.vertices.length;l++){n+=u.distanceFrom(a.vertices[l]);n>F&&n<N&&v.push(a.vertices[l]);u=a.vertices[l]}v.push($P(a.elevation_per_pixel[x+d-1]));w=new MTK.Polyline({path:v,strokeColor:c.position.color||"#ff6666",map:c.map})}}}else{o.style.display="none";clearTimeout(I);if(!d)return;D.getMap()||D.setMap(c.map);p.style.left=d[2]+"px";p.style.display="block";D.setPosition($P(d[1]));
Math.round(a.distance/a.elevation_per_pixel.length*d[0]);t.innerHTML=parseInt(d[1][2]*C[c.unit][3])+" "+C[c.unit][2]}e.preventDefault&&e.preventDefault();e.stopPropagation&&e.stopPropagation();return e.returnValue=false};b.onmouseout=function(){I=setTimeout(H,10);r.style.display="none";c.onmouseout&&c.onmouseout()};if(c.reverse){var q=document.createElement("div");q.className="mtk-elevation-reverse";q.style.top=(c.header?20:3)+"px";f=document.createElement("input");f.type="checkbox";f.id="mtk-elevation-checkbox-"+
Math.floor(Math.random()*1E3);f.onclick=function(){try{B.reverse(this.checked);c.onreverse&&c.onreverse(this.checked)}catch(e){}};q.appendChild(f);g=document.createElement("label");g.setAttribute("for",f.id);g.appendChild(document.createTextNode(" "+G("reverse")));q.appendChild(g)}h.appendChild(imgBg);h.appendChild(s);h.appendChild(m);h.appendChild(r);h.appendChild(t);h.appendChild(p);h.appendChild(o);h.appendChild(b);c.reverse&&h.appendChild(q);if(c.visible==false)h.style.display="none";c.map.map.viewPortDiv.appendChild(h);
c.map.elevationProfile=B};var L=function(b,g,f){var y=g[1]-g[0],m=document.createElement("table"),z=document.createElement("tbody");m.appendChild(z);m.width=f;m.style.width=f+"px";for(var q=g.length;q>=0;q--){var e=0,d=document.createElement("tr");jQuery.map(b,function(n){var l=document.createElement("td");l.width=n-e;e=n;l.height=(q==0?g[0]:y)-1;l.innerHTML="&nbsp;";d.appendChild(l)});z.appendChild(d)}return m},J=function(b){var g=b.offsetX||b.layerX;if(g<=0||g>a.elevation_per_pixel.length)H();else if(a.elevation_per_pixel[g])return[g,
a.elevation_per_pixel[g],(b.offsetX||b.layerX)+35]},H=function(){if(!A){t.innerHTML="&nbsp";D.setMap(null);p.style.display="none"}},M=function(b){for(var g=0,f=b.length-1,y=[b[g]],m=[f];m.length;){for(var z=0,q=f,e=g+1;e<f;e++){var d=e-g,n=b[e]-b[g],l=f-g,u=b[f]-b[g];l=Math.atan2(n,d)-Math.atan2(u,l);d=Math.abs(Math.sqrt(d*d+n*n)*Math.sin(l));if(d>z){z=d;q=e}}if(z<=(c.tolerance||20)){y.push(b[m.pop()]);g=f;f=m[m.length-1]}else{f=q;m.push(f)}}return y};B.reverse=function(){E=A=false;r.style.display=
"block";t.innerHTML="";o.style.display="none";p.style.display="none";D.setMap(null);w&&w.setMap(null);a.elevation_per_pixel=a.elevation_per_pixel.reverse();a.elevation_per_100m=a.elevation_per_100m&&a.elevation_per_100m.reverse();a.elevation_per_5m=a.elevation_per_5m&&a.elevation_per_5m.reverse();a.vertices=a.vertices.reverse();s.src=s.src==a.img_src.backward?a.img_src.forward:a.img_src.backward};B.hide=function(b,g){jQuery(h).fadeOut(b||200,function(){E=A=false;r.style.display="none";t.innerHTML=
"";o.style.display="none";p.style.display="none";D.setMap(null);w&&w.setMap(null);g&&g()})};B.isVisible=function(){return jQuery(h).is(":visible")}};MTK.ElevationProfile.profiles={};MTK.ElevationProfile.I18n={en:{clickAndDrag:"Click and drag to select section",title:"Elevation Profile",reverse:"Show reverse profile"},de:{clickAndDrag:"Klicken und ziehen um Abschnitt zu zeigen",title:"H\u00f6henprofil",reverse:"R\u00fcckweg zeigen"}};
MTK.ElevationProfile.Options={map:null,visible:null,reverse:null,unit:null,icon:null,shadow:null,opacity:null,position:null,js:null,i18n:null,onmouseover:null,onmouseout:null,onreverse:null,header:null};

