﻿(function(b){"use strict";var d=Microsoft.Maps,e,a,o=false,f,k,m,j,c,g,u,q,v,w,s,i;function h(a){c.setView({bounds:d.LocationRect.fromLocations(k),padding:a})}function l(g,d){if(!f){b("#mapExpandBtn").text("Restore -");e.css("border","2px solid black");e.animate({height:a.height,width:a.width},1e3,function(){h(0);b(".MicrosoftNav").show();g&&c.setView({center:d})})}else{b("#mapExpandBtn").text("Expand +");e.animate({height:a.miniHeight,width:a.miniWidth},1e3,function(){b("#ibTop").hide(500);h(0);b(".MicrosoftNav").hide();e.css("border","0px");c.setView({zoom:a.initialZoom})})}f=!f}function r(d){if(d.targetType==="pushpin"){if(a.miniMap&&!f)l(true,d.target.getLocation());else c.setView({center:d.target.getLocation()});g.clear();var e=new Microsoft.Maps.Infobox(d.target.getLocation(),{zIndex:4200,offset:new Microsoft.Maps.Point(5,5),visible:true,htmlContent:a.infoboxHtml});g.push(e);b("#ibTitle").append("<div id='ibTitleContent'>"+d.target.Metadata.title+"</div>");d.target.Metadata.link&&b("#ibTitleContent").wrap("<a href='"+d.target.Metadata.link+"' target='_blank'>");b("#ibDescription").append(d.target.Metadata.description);b("#ibClose").css("cursor","pointer");b("#ibTop").show(500);b("#ibClose").click(function(){b("#ibTop").hide(500)})}}function n(c){var a=c.eventName==="mouseover"?"pointer":"url(http://ecn.dev.virtualearth.net/mapcontrol/v7.0/cursors/grab.cur), move";b(".MicrosoftMap").css("cursor",a)}function t(){if(!o){e.width()<=400&&b(".MicrosoftNav").hide();h(0);c.setView({zoom:a.initialZoom})}o=true}function p(a){b.each(a.data.d,function(){var e=new d.Location(this.latitude,this.longitude),b=new d.Pushpin(e,{text:(i+1).toString()});if(a.showInfobox){b.Metadata={title:u,description:q,icon:v,link:w};b.Metadata.title=this.title;b.Metadata.description=this.description;b.Metadata.link=this.link;d.Events.addHandler(b,"click",r);d.Events.addHandler(b,"mouseover",n);d.Events.addHandler(b,"mouseout",n);d.Events.addHandler(c,"tiledownloadcomplete",t)}c.entities.push(b);k[i]=e;i+=1})}b.fn.jBingMap=function(n){k=[];m={d:[{title:"Microsoft Reston Office",description:"Microsoft office located at 12012 Sunset Hills Road in Reston, VA.",state:"VA",link:"http://www.microsoft.com/",latitude:"38.9549457424139",longitude:"-77.3581556338633"},{title:"Montgomery College - Rockville",description:"Rockville Campus of Montgomery College",state:"MD",link:"",latitude:"39.0954359034519",longitude:"-77.1585501855589"},{title:"Microsoft Malvern Office",description:"Microsoft office located at 45 Liberty Blvd. in Malvern, PA.",state:"PA",link:"http://www.microsoft.com/",latitude:"40.05589710947304",longitude:"-75.52118700000001"}]};a={mapCreds:"",miniMap:false,width:"640px",height:"480px",position:"relative",initialZoom:5,showInfobox:true,showGroupBox:false,infoboxHtml:'<div id="ibTop" style="display: none; width: 200px; height: auto; padding: 5px; border: 1px solid black; background-color: #ffffff;"><div id="ibTitle" style="font-weight:bold; font-size: 1.2em;  padding-bottom: 5px;"><span id="ibClose" style="top: 5px; float: right; padding: 2px">X</span></div><div id="ibDescription"></div></div>',data:m};return this.each(function(){n&&b.extend(a,n);e=b(this);j={credentials:a.mapCreds};c=new d.Map(this,j);g=new d.EntityCollection;s=false;i=0;d.Pushpin.prototype.Metadata=null;if(a.miniMap)j.enableSearchLogo=false;c.entities.clear();c.entities.push(g);p(a);if(a.miniMap){f=false;e.css("width",a.miniWidth).css("height",a.miniHeight).css("position",a.position);e.before("<div id='mapExpandBtn' style='cursor: pointer;'>Expand +</div>");b(".MicrosoftNav").hide();b("#mapExpandBtn").click(function(){l()})}else{e.css("width",a.width).css("height",a.height).css("position",a.position);h()}})}})(jQuery)
