
var ssMaps={};function ssBaseMap(opts){this.smallMapLimit=275;this.oColor=new ss.parseColor();this.removeEditor=null;this.editable=false;this.itemList='';this.elementID="map";this.center={x:42,y:-71};this.zoom=6;this.icons=Object();jQuery.extend(this,opts);ssMaps[this.elementID]=this;this.zoom=this.adjustZoom(this.zoom);this.mapItems=new ssMapItems(this);};ssBaseMap.prototype.getLatLongs=function(xyArray){var latLngs=[];for(var i in xyArray){latLngs.push(this.getLatLong(xyArray[i]));};return latLngs;};ssBaseMap.prototype.getColor=function(sColor){this.oColor.parse(sColor);return this.oColor.toHex();};ssBaseMap.prototype.imageUrl=function(imageName){return'mimages/'+imageName;};ssBaseMap.prototype.iconFileName=function(iconName){iconName=iconName.toLowerCase().replace(/ /g,'-');return'mapicon-'+iconName+'.png';};ssBaseMap.prototype.adjustZoom=function(zoom){return zoom;};ssBaseMap.prototype.itemClick=function(itemKey){this.mapItems.itemClick(itemKey);};ssBaseMap.prototype.moveTo=function(mapItem,latLong){};ssBaseMap.prototype.getShapeCenter=function(mapItem){var nPoints=mapItem.points.length;var totalX=0.0,totalY=0.0;for(var iPoint=0;iPoint<nPoints;iPoint++){totalX+=parseFloat(mapItem.points[iPoint].x);totalY+=parseFloat(mapItem.points[iPoint].y);};return this.getLatLong({x:totalX/nPoints,y:totalY/nPoints});};function ssYahooMap(opts){ssYahooMap.baseConstructor.call(this,opts);var mapElement=document.getElementById(this.elementID);this.map=new YMap(this.elementID);this.map.addTypeControl();if(mapElement.offsetWidth<this.smallMapLimit||mapElement.offsetHeight<this.smallMapLimit){this.map.addZoomShort();}else{this.map.addZoomLong();};this.map.addPanControl();this.map.drawZoomAndCenter(this.getLatLong(this.center),this.zoom);var mapTypes={Road:YAHOO_MAP_REG,Aerial:YAHOO_MAP_SAT,Hybrid:YAHOO_MAP_HYB,Terrain:YAHOO_MAP_REG};this.map.setMapType(mapTypes[this.mapType]);};ss.extend(ssBaseMap,ssYahooMap);ssYahooMap.prototype.getLatLong=function(xyObject){return new YGeoPoint(parseFloat(xyObject.y),parseFloat(xyObject.x));};ssYahooMap.prototype.getShapeLength=function(mapItem){return 0;};ssYahooMap.prototype.openItemWindow=function(latLng,mapItem){this.moveTo(mapItem,latLng);this.map.showSmartWindow(latLng,mapItem.name+mapItem.getDescription());};ssYahooMap.prototype.adjustZoom=function(zoom){var zooms=new Array(0,16,16,15,14,13,12,11,10,9,8,7,6,5,4,3,3,2,2,1,1);return zooms[zoom];};ssYahooMap.prototype.moveTo=function(mapItem,latLong){if(latLong){this.map.panToLatLon(latLong);}else{var shapeCenter=mapItem.getCenter();this.map.panToLatLon(shapeCenter);};};ssYahooMap.prototype.newMarker=function(mapItem){var latLng=this.getLatLong(mapItem.points[0]);var theIcon;if(mapItem.iconName=='standard'){theIcon=new YImage(this.imageUrl(this.iconFileName('yahoo')),new YSize(30,33),new YCoordPoint(0,0),new YCoordPoint(0,0));}else{theIcon=new YImage(this.imageUrl(this.iconFileName(mapItem.iconName)),new YSize(32,32),new YCoordPoint(15,0),new YCoordPoint(-15,0));};var theShape=new YMarker(latLng,theIcon);if(mapItem.name!==''){theShape.addAutoExpand(mapItem.name+mapItem.getDescription());};this.map.addOverlay(theShape);return theShape;};ssYahooMap.prototype.newPolygon=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new YPolyline(latLngs,this.getColor(mapItem.lineColor),mapItem.lineWidth,mapItem.lineOpacity);this.map.addOverlay(theShape);return theShape;};ssYahooMap.prototype.newPolyline=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new YPolyline(latLngs,this.getColor(mapItem.lineColor),mapItem.lineWidth,mapItem.lineOpacity);this.map.addOverlay(theShape);return theShape;};function ssVirtualEarthMap(opts){ssVirtualEarthMap.baseConstructor.call(this,opts);this.smallMapLimit=400;var mapElement=document.getElementById(this.elementID);this.map=new VEMap(this.elementID);if(mapElement.offsetWidth<this.smallMapLimit||mapElement.offsetHeight<this.smallMapLimit){this.map.SetDashboardSize(VEDashboardSize.Small);}else{this.map.SetDashboardSize(VEDashboardSize.Normal);};var mapTypes={Road:VEMapStyle.Road,Aerial:VEMapStyle.Aerial,Hybrid:VEMapStyle.Hybrid,Terrain:VEMapStyle.Shaded};this.map.AttachEvent('onmouseover',function(e){if(e.elementID)return true;});this.map.LoadMap(this.getLatLong(this.center),this.zoom,mapTypes[this.mapType]);var self=this;this.map.AttachEvent("onclick",function(e){if(e.elementID){var shape=self.map.GetShapeByID(e.elementID);var mapItem=shape.ssMapItem_;self.map.ShowInfoBox(shape,mapItem.getCenter(),new VEPixel(10,0));return false;};});};ss.extend(ssBaseMap,ssVirtualEarthMap);ssWaitForVE=function(elementID,callback){var interval=setInterval(function(){if((eval("typeof VEMap")!="undefined")&&(document.getElementById(elementID).attachEvent!=undefined)){clearInterval(interval);callback();}},10);};ssVirtualEarthMap.prototype.getLatLong=function(xyObject){return new VELatLong(parseFloat(xyObject.y),parseFloat(xyObject.x));};ssVirtualEarthMap.prototype.getShapeLength=function(mapItem){return 0;};ssVirtualEarthMap.prototype.openItemWindow=function(latLng,mapItem){this.map.HideInfoBox();this.moveAway(latLng);this.moveTo(mapItem,latLng);this.map.ShowInfoBox(mapItem.shape,latLng,new VEPixel(10,0));};ssVirtualEarthMap.prototype.moveAway=function(latLng){var dummyLat=(latLng.Latitude>45?0:90);this.map.PanToLatLong(new VELatLong(dummyLat,latLng.Longitude));};ssVirtualEarthMap.prototype.getVEColor=function(sColor,nOpacity){this.oColor.parse(sColor);return new VEColor(this.oColor.r,this.oColor.g,this.oColor.b,nOpacity);};ssVirtualEarthMap.prototype.moveTo=function(mapItem,latLong){if(latLong){this.map.PanToLatLong(latLong);}else{var shapeCenter=mapItem.getCenter();this.map.PanToLatLong(shapeCenter);};};ssVirtualEarthMap.prototype.newMarker=function(mapItem){var latLng=this.getLatLong(mapItem.points[0]);var theShape=new VEShape(VEShapeType.Pushpin,latLng);if(mapItem.name!==''){theShape.SetTitle(mapItem.name);};if(mapItem.text!==''){theShape.SetDescription(mapItem.getDescription());};if(mapItem.iconName!='standard'){theShape.SetCustomIcon('<img class="veIconOffset" src="'+
this.imageUrl(this.iconFileName(mapItem.iconName))+'">');};this.map.AddShape(theShape);return theShape;};ssVirtualEarthMap.prototype.newPolygon=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new VEShape(VEShapeType.Polygon,latLngs);if(mapItem.name!==''){theShape.SetTitle(mapItem.name);if(mapItem.text!==''){theShape.SetDescription(mapItem.getDescription());};};theShape.HideIcon();theShape.SetLineColor(this.getVEColor(mapItem.lineColor,mapItem.lineOpacity));theShape.SetLineWidth(mapItem.lineWidth);theShape.SetFillColor(this.getVEColor(mapItem.fillColor,mapItem.fillOpacity));this.map.AddShape(theShape);return theShape;};ssVirtualEarthMap.prototype.newPolyline=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new VEShape(VEShapeType.Polyline,latLngs);if(mapItem.name!==''){theShape.SetTitle(mapItem.name);if(mapItem.text!==''){theShape.SetDescription(mapItem.getDescription());};};theShape.HideIcon();theShape.SetLineColor(this.getVEColor(mapItem.lineColor,mapItem.lineOpacity));theShape.SetLineWidth(mapItem.lineWidth);this.map.AddShape(theShape);return theShape;};function ssMapQuestMap(opts){ssMapQuestMap.baseConstructor.call(this,opts);var mapTypes={Road:'map',Aerial:'sat',Hybrid:'hyb',Terrain:'map'};var mapElement=document.getElementById(this.elementID);this.map=new MQA.TileMap(mapElement,this.zoom,this.getLatLong(this.center),mapTypes[this.mapType]);if(mapElement.offsetWidth<this.smallMapLimit||mapElement.offsetHeight<this.smallMapLimit){this.map.addControl(new MQA.ZoomControl);this.map.addControl(new MQA.ViewControl,new MQA.MapCornerPlacement(MQA.MapCorner.BOTTOM_RIGHT,new MQA.Size(-2,-2)));}else{this.map.addControl(new MQA.LargeZoomControl);this.map.addControl(new MQA.ViewControl);};this.map.getInfoWindow().setMinWidth(200);};ss.extend(ssBaseMap,ssMapQuestMap);ssMapQuestMap.prototype.getLatLong=function(xyObject){return new MQA.LatLng(parseFloat(xyObject.y),parseFloat(xyObject.x));};ssMapQuestMap.prototype.getLatLongs=function(xyArray){var latLngs=new MQA.LatLngCollection();for(var i in xyArray){latLngs.add(this.getLatLong(xyArray[i]));};return latLngs;};ssMapQuestMap.prototype.openItemWindow=function(latLng,mapItem){this.map.setInfoTitleHTML(mapItem.name);this.map.setInfoContentHTML(mapItem.getDescription());this.moveTo(mapItem,latLng);this.map.getInfoWindow().isAttachedToPoi=false;this.map.openInfoWindow(this.map.llToPix(latLng));};ssMapQuestMap.prototype.adjustZoom=function(zoom){var zooms=new Array(0,1,2,2,3,3,4,4,5,6,7,8,9,10,11,12,13,14,15,16,16);return zooms[zoom];};ssMapQuestMap.prototype.getShapeLength=function(mapItem){return 0;};ssMapQuestMap.prototype.moveTo=function(mapItem,latLong){if(latLong){this.map.setCenter(latLong);}else{var shapeCenter=mapItem.getCenter();this.map.setCenter(shapeCenter);};};ssMapQuestMap.prototype.newMarker=function(mapItem){var latLng=this.getLatLong(mapItem.points[0]);var theShape=new MQA.Poi(latLng);if(mapItem.name!==''){theShape.setValue('infoWindowTitleText',mapItem.name);theShape.setValue('infoContentHTML',mapItem.getDescription());if(mapItem.iconName!='standard'){theIcon=new MQA.Icon(this.imageUrl(this.iconFileName(mapItem.iconName)),32,32);theShape.setValue('icon',theIcon);theShape.setValue('iconOffset',new MQA.Point(-16,-32));if(mapItem.iconName.indexOf('small')!=-1){theIcon=new MQA.Icon(this.imageUrl(this.iconFileName('full-shadow')),59,32);}else{theIcon=new MQA.Icon(this.imageUrl(this.iconFileName('small-shadow')),59,32);};theShape.setValue('shadow',theIcon);theShape.setValue('shadowOffset',new MQA.Point(0,-32));};};this.map.addShape(theShape);return theShape;};ssMapQuestMap.prototype.newPolygon=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new MQA.PolygonOverlay();theShape.setValue('shapePoints',latLngs);if(mapItem.name!==''){theShape.setValue('infoWindowTitleText',mapItem.name);theShape.setValue('infoContentHTML',mapItem.getDescription());};theShape.setValue('color',this.getColor(mapItem.lineColor));theShape.setValue('colorAlpha',mapItem.lineOpacity);theShape.setValue('borderWidth',mapItem.lineWidth);theShape.setValue('fillColor',this.getColor(mapItem.fillColor));theShape.setValue('fillColorAlpha',mapItem.fillOpacity);this.map.addShape(theShape);return theShape;};ssMapQuestMap.prototype.newPolyline=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new MQA.LineOverlay();theShape.setValue('shapePoints',latLngs);this.map.addShape(theShape);return theShape;};function ssGoogleMap(opts){ssGoogleMap.baseConstructor.call(this,opts);this.editable=ss.isMapEditor();var mapElement=document.getElementById(this.elementID);$(this.elementID).css('overflow','hidden');var mapTypes={Road:google.maps.MapTypeId.ROADMAP,Aerial:google.maps.MapTypeId.SATELLITE,Hybrid:google.maps.MapTypeId.HYBRID,Terrain:google.maps.MapTypeId.TERRAIN};var isSmall=(mapElement.offsetWidth<this.smallMapLimit||mapElement.offsetHeight<this.smallMapLimit);var mapOpts={zoom:this.zoom,center:this.getLatLong(this.center),mapTypeId:mapTypes[this.mapType],mapTypeControl:true,zoomControl:true,streetViewControl:true,scaleControl:!isSmall,rotateControl:!isSmall};if(isSmall){mapOpts.zoomControlOptions={style:google.maps.ZoomControlStyle.SMALL}
mapOpts.streetViewControl=false;mapOpts.zoomControlOptions={style:google.maps.ZoomControlStyle.SMALL}};if(this.editable){};this.map=new google.maps.Map(mapElement,mapOpts);this.infoWindow=new google.maps.InfoWindow({position:this.getLatLong(this.center),content:""});};ss.extend(ssBaseMap,ssGoogleMap);ssGoogleMap.prototype.getLatLong=function(xyObject){return new google.maps.LatLng(parseFloat(xyObject.y),parseFloat(xyObject.x));};ssGoogleMap.prototype.openItemWindow=function(latLng,mapItem){this.infoWindow.setPosition(latLng);this.infoWindow.setContent(mapItem.name+mapItem.getDescription());this.infoWindow.open(this.map);};ssGoogleMap.prototype.moveTo=function(mapItem,latLong){if(latLong){this.map.panTo(latLong);}else{var shapeCenter=mapItem.getCenter();this.map.panTo(shapeCenter);};};ssGoogleMap.prototype.makeIcon=function(name,shadow,shadowWidth,shadowHeight){var icon=new google.maps.MarkerImage(this.imageUrl(this.iconFileName(name)),new google.maps.Size(32,32),new google.maps.Point(0,0),new google.maps.Point(16,31));shadowWidth=shadowWidth||40;shadowHeight=shadowHeight||32;if(!shadow){if(name.indexOf('small')!=-1){shadow='small-shadow';}else{shadow='full-shadow';};};var shadow=new google.maps.MarkerImage(this.imageUrl(this.iconFileName(shadow)),new google.maps.Size(shadowWidth,shadowHeight),new google.maps.Point(0,0),new google.maps.Point(16,31));return{'icon':icon,'shadow':shadow};};ssGoogleMap.prototype.newMarker=function(mapItem){var sIconName=mapItem.iconName.toLowerCase();if(!this.icons[sIconName]){this.icons[sIconName]=this.makeIcon(sIconName);};var theShape=new google.maps.Marker({draggable:this.editable,position:this.getLatLong(mapItem.points[0]),title:mapItem.name,icon:this.icons[sIconName].icon,shadow:this.icons[sIconName].shadow,map:this.map});google.maps.event.addListener(theShape,'click',function(event){mapItem.click(event.latLng);});return theShape;};ssGoogleMap.prototype.newPolygon=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new google.maps.Polygon({paths:latLngs,strokeColor:this.getColor(mapItem.lineColor),strokeOpacity:mapItem.lineOpacity,strokeWeight:mapItem.lineWidth,fillColor:this.getColor(mapItem.fillColor),fillOpacity:mapItem.fillOpacity,map:this.map});google.maps.event.addListener(theShape,'click',function(event){mapItem.click(event.latLng);});return theShape;};ssGoogleMap.prototype.newPolyline=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new google.maps.Polyline({path:latLngs,strokeColor:this.getColor(mapItem.lineColor),strokeOpacity:mapItem.lineOpacity,strokeWeight:mapItem.lineWidth,map:this.map});google.maps.event.addListener(theShape,'click',function(event){mapItem.click(event.latLng);});return theShape;};function ssMapItems(ssMap){this.ssMap=ssMap;this.items=Object();this.nextKey=1;this.length=0;};ssMapItems.prototype.add=function(mapItem){mapItem.key=this.nextKey++;this.items[mapItem.key]=mapItem;this.length++;return mapItem;};ssMapItems.prototype.addMarker=function(opts){return this.add(new ssMapItemMarker(opts,this));};ssMapItems.prototype.addPolygon=function(opts){return this.add(new ssMapItemPolygon(opts,this));};ssMapItems.prototype.addPolyline=function(opts){return this.add(new ssMapItemPolyline(opts,this));};ssMapItems.prototype.itemClick=function(itemKey){var mapItem=this.items[itemKey];mapItem.click();};ssMapItems.prototype.refreshList=function(elementID){var sElementID='';if(arguments.length>0){sElementID=elementID;this.ssMap.itemList=sElementID;}else{sElementID=this.ssMap.itemList;};if(sElementID!=''){var mapName="'"+this.ssMap.elementID+"'";var sContents='';var sID='';var sHandle='';if(this.ssMap.editable){sHandle='<div class="move-handle"></div>';};for(var item in this.items){var mapItem=this.items[item];if(mapItem.inItemList||this.ssMap.editable){if(this.ssMap.editable){sID=' id="item-'+mapItem.key+'"';};sContents+='<li'+sID+' onclick="ssMaps['+mapName+'].itemClick('+mapItem.key+')">';sContents+=sHandle+mapItem.getListContent();sContents+='</li>';};};$(sElementID).html(sContents);};};function ssMapItem(opts,list){this.name='';this.fillColor='#ff0';this.fillOpacity=0.2;this.icon='';this.lineColor='#fd645c';this.lineOpacity=0.7;this.lineWidth=3;this.points=[];this.shape=null;this.text='';this.type='';this.hasIcon=false;this.iconName='standard';this.hasLine=false;this.hasFill=false;this.inItemList=true;this.showCoordinates=true;jQuery.extend(this,opts);if(list){this.ssMap=list.ssMap;this.map=this.ssMap.map;};};ssMapItem.prototype.addEditingHandler=function(){};ssMapItem.prototype.getCenter=function(){if(this.points.length==1){return(this.ssMap.getLatLong(this.points[0]));}else{return(this.ssMap.getShapeCenter(this));};};ssMapItem.prototype.click=function(latLng){if(this.name!=''){this.ssMap.openItemWindow(latLng?latLng:this.getCenter(),this);};};ssMapItem.prototype.getDescription=function(){var sText=this.text;if(sText!=''){sText='<div class="smib">'+sText+'</div>';};if(this.points.length==1&&this.showCoordinates){if(sText==''){sText='<br><br>';};sText+=(this.points[0].y+','+this.points[0].x);};return sText;};ssMapItem.prototype.getListContent=function(){if(this.name!=''){return(this.name);}else{return(this.type+' ('+this.key+')');};};ssMapItem.prototype.getLength=function(){return this.ssMap.getShapeLength(this);};ssMapItem.prototype.moveTo=function(latLong){return this.ssMap.moveTo(this,latLong);};function ssMapItemMarker(opts,list){ssMapItemMarker.baseConstructor.call(this,opts,list);this.type='Marker';this.hasIcon=true;this.shape=this.ssMap.newMarker(this);this.shape.ssMapItem_=this;if(this.ssMap.editable)this.addEditingHandler();};ss.extend(ssMapItem,ssMapItemMarker);function ssMapItemPolygon(opts,list){ssMapItemPolygon.baseConstructor.call(this,opts,list);this.type='Polygon';this.hasLine=true;this.hasFill=true;this.shape=this.ssMap.newPolygon(this);this.shape.ssMapItem_=this;if(this.ssMap.editable)this.addEditingHandler();};ss.extend(ssMapItem,ssMapItemPolygon);function ssMapItemPolyline(opts,list){ssMapItemPolyline.baseConstructor.call(this,opts,list);this.type='Polyline';this.hasLine=true;this.shape=this.ssMap.newPolyline(this);this.shape.ssMapItem_=this;if(this.ssMap.editable)this.addEditingHandler();};ss.extend(ssMapItem,ssMapItemPolyline);
