function prepareMap(b){var a=jQuery("#"+b).text("Karte wird geladen...")}function initMap(jsonMapData,rootDivId,style,teaserStyle){var mapDiv=jQuery("#"+rootDivId+" .map_content");var mapDivId=mapDiv.attr("id");var MapType=new Array(Microsoft.Maps.MapTypeId.road,Microsoft.Maps.MapTypeId.aerial,Microsoft.Maps.MapTypeId.hybrid);var selStyle=MapType[style];var disableUserInput=false;var showDashboard=true;var mapSearchVisibility=true;try{mapSearchVisibility=eval(rootDivId+"_suche")}catch(e){}if(teaserStyle!=null){disableUserInput=true;showDashboard=false}var mapOptions={credentials:"Ak_VmUJjQQL1c4aB5FQ0rsXOMaW3ttvFrlGX4JMkObnFUqiAarC9aLf8c3sGA-5Z",mapTypeId:selStyle,showScalebar:false,showCopyright:false,enableClickableLogo:false,showDashboard:showDashboard,disableUserInput:disableUserInput,enableSearchLogo:false};var globVeMap=new Microsoft.Maps.Map(document.getElementById(mapDivId),mapOptions);addMapData(jsonMapData,rootDivId,globVeMap,teaserStyle);if(teaserStyle==null){var timerDelay=500;var lastTime=new Date().getTime()-timerDelay;var timerId=0;var listHasRendered=false;Microsoft.Maps.Events.addHandler(globVeMap,"targetviewchanged",function(){if(!listHasRendered){renderList(rootDivId,jsonMapData,globVeMap,false);listHasRendered=true;return}var currentTime=new Date().getTime();if(currentTime-lastTime<timerDelay){clearTimeout(timerId)}timerId=setTimeout(function(){renderList(rootDivId,jsonMapData,globVeMap,true)},timerDelay);lastTime=currentTime});if(mapSearchVisibility){jQuery("#"+rootDivId+" .map_search").show();jQuery("#"+rootDivId+" .map_navi").after('<div class="searchResultBox"><div class="searchResult"></div></div>');jQuery("#"+rootDivId+" .map_search .map_search_label").text("Wo bin ich?");jQuery("#"+rootDivId+" .map_search .map_search_button").html("<img src='http://www.swr.de/static/wetter/img/nav/dosearch.gif' />");jQuery("#"+rootDivId+" .map_search .map_search_text").val("PLZ/Ort eingeben");jQuery("#"+rootDivId+" .map_search .map_search_text").toggleValue("PLZ/Ort eingeben");jQuery("#"+rootDivId+" .map_search .map_search_button").click(function(){mapSearch(globVeMap,rootDivId)});jQuery("#"+rootDivId+" .map_search .map_search_text").keydown(function(event){if(event.keyCode=="13"){mapSearch(globVeMap,rootDivId)}else{jQuery("#"+rootDivId+" .searchResult").fadeOut()}});jQuery("#"+rootDivId+" .map_search .map_search_text").click(function(){if(jQuery("#"+rootDivId+" .searchResult").has("p").length!=0){jQuery("#"+rootDivId+" .searchResult").fadeIn()}});jQuery("#"+rootDivId+" .map_search .map_search_text").mouseover(function(){if(jQuery("#"+rootDivId+" .searchResult").has("p").length!=0){jQuery("#"+rootDivId+" .searchResult").fadeIn()}})}jQuery("#"+rootDivId+" .map_region .map_region_combo").combobox();jQuery("#"+rootDivId+" .map_region .map_region_combo").change(function(){setCenterAndZoom(globVeMap,this.value)});jQuery(".ui-autocomplete-input").attr("readonly",true);var selectedGeoPos=jQuery("#"+rootDivId+" .map_region .map_region_combo option:selected").val();setCenterAndZoom(globVeMap,selectedGeoPos);jQuery("#"+rootDivId+" .map_list").hide();var showHideIcon="<img class='showHideIcon' src='/static/bing/assets/showIcon.gif' />";jQuery("#"+rootDivId+" .map_list_control").append(showHideIcon+" <span>öffnen</span>");jQuery("#"+rootDivId+" .map_list_control").click(function(){jQuery("#"+rootDivId+" .map_list").toggle();var iconClass="#"+rootDivId+" .map_list_control .showHideIcon";var iconSrc=jQuery(iconClass).attr("src");if(iconSrc.indexOf("close")!=-1){jQuery(iconClass).attr("src","/static/bing/assets/showIcon.gif");jQuery("#"+rootDivId+" .map_list").hide();jQuery("#"+rootDivId+" .map_list_control span").text("öffnen")}else{jQuery(iconClass).attr("src","/static/bing/assets/closeIcon.gif");jQuery("#"+rootDivId+" .map_list").show();jQuery("#"+rootDivId+" .map_list_control span").text("schließen")}})}else{jQuery("#"+rootDivId).click(function(){window.location.href=jQuery("#"+rootDivId).parent().find(".teaserlink")[0].href});var mainRegionGeoPos=jQuery("#"+rootDivId+" .map_region .map_region_combo option:first").val();setCenterAndZoom(globVeMap,mainRegionGeoPos)}try{var polyline=eval(rootDivId+"_polyline");if(polyline!=undefined){var liste=eval(polyline);if(liste!=undefined){var locations=[];for(var i=0;i<liste.length;i++){var element=liste[i];locations[i]=new Microsoft.Maps.Location(element[0],element[1])}globVeMap.entities.push(new Microsoft.Maps.Polyline(locations,null))}}}catch(e){}}function mapSearch(globVeMap,rootDivId){jQuery("#"+rootDivId+" .searchResult").html("");globVeMap.getCredentials(function(credentials){if(credentials!==null){var input=jQuery("#"+rootDivId+" .map_search .map_search_text").val();try{var countryRegion="&countryRegion="+eval(rootDivId+"_suche_lokalisierung")}catch(e){var countryRegion=""}if(isNumber(input)){var request="http://dev.virtualearth.net/REST/v1/Locations?postalCode="+input+"&jsonp=?&culture=de-de&key="+credentials+countryRegion}else{var request="http://dev.virtualearth.net/REST/v1/Locations?locality="+input+"&jsonp=?&culture=de-de&key="+credentials+countryRegion}jQuery.getJSON(request,{output:"json"},function(result){if(result&&result.resourceSets&&result.resourceSets.length>0&&result.resourceSets[0].resources&&result.resourceSets[0].resources.length>0){if(result.resourceSets[0].estimatedTotal>1){jQuery("#"+rootDivId+" .searchResult").fadeIn();jQuery.each(result.resourceSets[0].resources,function(indexItems,item){var name=item.name;var bbox=item.bbox;jQuery("#"+rootDivId+" .searchResult").append("<p>"+name+"</p>");jQuery("#"+rootDivId+" .searchResult p:last").click(function(){var viewBoundaries=Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(bbox[0],bbox[1]),new Microsoft.Maps.Location(bbox[2],bbox[3]));globVeMap.setView({bounds:viewBoundaries});jQuery("#"+rootDivId+" .searchResult").fadeOut()})})}var bbox=result.resourceSets[0].resources[0].bbox;var viewBoundaries=Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(bbox[0],bbox[1]),new Microsoft.Maps.Location(bbox[2],bbox[3]));globVeMap.setView({bounds:viewBoundaries})}})}})}function setCenterAndZoom(d,a){var b=a.split(",");var f=b[0];var g=b[1];var e=parseInt(b[2]);if(e<1){e=2}var c=d.getOptions();c.zoom=e;c.center=new Microsoft.Maps.Location(f,g);d.setView(c)}function renderList(n,b,p,g){if(!isIESupported(n)){jQuery("#"+n+" .map_list_control").hide();return}var o=p.getTargetBounds();var j=jQuery("#"+n+" .map_list .map_list_ul").children();var f=0;var e=0;var c="";jQuery.each(b,function(t,i){var s=false;var r=p.entities.get(t);if(!r.getVisible()){s=true}jQuery.each(b[t],function(x,w){if(!g){var v=w.link;var z=w.title;var u=w.icon_path;var y=w.theme;c=c+renderListItem(v,z,u,y,n,f);e++}else{if(isInCurrentView(o,w.latitude,w.longitude)&&(!s)){jQuery(j[f]).toggle(true);e++}else{jQuery(j[f]).toggle(false)}}f++})});if(!g){var m=jQuery("#"+n+" .map_list_ul");jQuery(m).html(c)}if(e==0){var k=o.getNorthwest();var a=o.getSoutheast();var d=k.latitude;var l=k.longitude;var h=a.latitude;var q=a.longitude;jQuery("#"+n+" .map_list_control").hide()}else{jQuery("#"+n+" .map_list_control").show()}}function renderListItem(d,h,e,b,g){var c="<img src='/static/bing/assets/plusLinkIcon.gif' />";var i=c+"<a href="+d+">"+h+"</a>";var j="<img src='"+e+"'/>";var f="<ul><li>"+j+" <span>"+b+"</span></li></ul>";var a='<li class="listItem">'+i+f+"</li>";return a}function isInCurrentView(b,c,d){var a=new Microsoft.Maps.Location(parseFloat(c),parseFloat(d));if(b.contains(a)){return true}return false}function addMapData(c,d,b,a){jQuery.each(c,function(i,h){var g=new Microsoft.Maps.EntityCollection();if(a==null){var f="#"+d+" .map_filter ";jQuery(f).append('<div id="'+d+"_"+i+'" />')}var e=new Array();jQuery.each(c[i],function(n,m){var l={icon:m.icon_path,height:56,width:42};var j=new Microsoft.Maps.Location(m.latitude,m.longitude);var o=new Microsoft.Maps.Pushpin(j,l);g.push(o);if(a==null){Microsoft.Maps.Events.addThrottledHandler(o,"mouseover",function(){jQuery(".infoboxText").hide();var r=new Microsoft.Maps.Infobox(j,{visible:false,offset:new Microsoft.Maps.Point(-10,180)});var q="<a href="+m.link+"><img src='"+m.thumbnail_link+"' /></a>";var p="<a href="+m.link+">"+m.title+" (mehr)</a>";g.push(r);r.setHtmlContent('<div class="infoboxText">'+q+" "+p+"</div>");l={icon:m.icon_mouseover_path,height:56,width:42};o.setOptions(l);r.setOptions({visible:true});var s;if(!Microsoft.Maps.Events.hasHandler(o,"mouseout")){Microsoft.Maps.Events.addHandler(o,"mouseout",function(){l={icon:m.icon_path,height:56,width:42};o.setOptions(l);s=setTimeout(function(){r.setOptions({visible:false})},1000)})}if(!Microsoft.Maps.Events.hasHandler(r,"mouseleave")){Microsoft.Maps.Events.addHandler(r,"mouseleave",function(){r.setOptions({visible:false})})}if(!Microsoft.Maps.Events.hasHandler(r,"mouseenter")){Microsoft.Maps.Events.addHandler(r,"mouseenter",function(){clearTimeout(s)})}},200);if(jQuery(f+"#"+d+"_"+i+" > input").size()==0){jQuery(f+"#"+d+"_"+i).append('<img class="mapFilterIcon" src="'+m.icon_path+'" /><input value="'+i+'" type="checkbox" checked=checked /><span>'+m.theme+"</span>");jQuery(f+"#"+d+"_"+i+" input:checkbox").click(function k(){var p=b.entities.get(this.value);if(p.getVisible()){p.setOptions({visible:false})}else{p.setOptions({visible:true})}jQuery(".infoboxText").hide();renderList(d,c,b,true)})}}});b.entities.push(g)})}function isIESupported(c){var b=(navigator.appVersion.indexOf("MSIE 6.")==-1)?false:true;var a=(navigator.appVersion.indexOf("MSIE 7.")==-1)?false:true;if(b||a){jQuery("#"+c+" .map_list").toggle(false);return false}return true}function isNumber(a){return !isNaN(a-0)}function mapSearchCallback(a){alert("Found location: "+a.resourceSets[0].resources[0].name);if(a&&a.resourceSets&&a.resourceSets.length>0&&a.resourceSets[0].resources&&a.resourceSets[0].resources.length>0){}}(function(a){a.widget("ui.combobox",{_create:function(){var d=this,b=this.element.hide(),e=b.children(":selected"),f=e.val()?e.text():"";var c=this.input=a("<input>").insertAfter(b).val(f).autocomplete({delay:0,minLength:0,source:function(h,g){var i=new RegExp(a.ui.autocomplete.escapeRegex(h.term),"i");g(b.children("option").map(function(){var j=a(this).text();selectClass=a(this).attr("class");if(this.value&&(!h.term||i.test(j))){return{label:j.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+a.ui.autocomplete.escapeRegex(h.term)+")(?![^<>]*>)(?![^&;]+;)","gi"),"<strong>$1</strong>"),value:j,highlightClass:selectClass,option:this}}}))},select:function(g,h){h.item.option.selected=true;d._trigger("selected",g,{item:h.item.option});a(h.item.option).parent().change()},change:function(h,i){if(!i.item){var j=new RegExp("^"+a.ui.autocomplete.escapeRegex(a(this).val())+"$","i"),g=false;b.children("option").each(function(){if(a(this).text().match(j)){this.selected=g=true;return false}});if(!g){a(this).val("");b.val("");c.data("autocomplete").term="";return false}}}}).addClass("ui-widget ui-widget-content ui-corner-left");c.data("autocomplete")._renderItem=function(g,h){return a("<li></li>").data("item.autocomplete",h).append("<a class="+h.highlightClass+">"+h.label+"</a>").appendTo(g)};this.button=a("<button type='button'>&nbsp;</button>").attr("tabIndex",-1).attr("title","Show All Items").insertAfter(c).button({icons:{primary:"ui-icon-triangle-1-s"},text:false}).removeClass("ui-corner-all").addClass("ui-corner-right ui-button-icon").click(function(){if(c.autocomplete("widget").is(":visible")){c.autocomplete("close");return}c.autocomplete("search","");c.focus()})},destroy:function(){this.input.remove();this.button.remove();this.element.show();a.Widget.prototype.destroy.call(this)}})})(jQuery);jQuery.fn.extend({toggleValue:function(a){return this.each(function(){jQuery(this).focus(function(){if(jQuery(this).val()==a){jQuery(this).val("")}jQuery(this).blur(function(){if(jQuery.trim($j(this).val())==""){jQuery(this).val(a)}})})})}});
