// (c) 2008 John Cardinal

var ssMaps={};var ssSmallMapLimit=275;function ssBaseMap(opts){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;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.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<ssSmallMapLimit||mapElement.offsetHeight<ssSmallMapLimit){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 theShape=new YMarker(latLng);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);var mapElement=document.getElementById(this.elementID);this.map=new VEMap(this.elementID);if(mapElement.offsetWidth<ssSmallMapLimit||mapElement.offsetHeight<ssSmallMapLimit){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.LoadMap(this.getLatLong(this.center),this.zoom,mapTypes[this.mapType]);var self=this;this.map.AttachEvent("onmouseover",function(e){if(e.elementID){var shape=self.map.GetShapeByID(e.elementID);if(shape.GetType()==VEShapeType.Pushpin){}else if(shape.GetType()==VEShapeType.Polygon){self.map.ShowInfoBox(shape);}else if(shape.GetType()==VEShapeType.Polyline){self.map.ShowInfoBox(shape);};return false;};});};ss.extend(ssBaseMap,ssVirtualEarthMap);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);};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());};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<ssSmallMapLimit||mapElement.offsetHeight<ssSmallMapLimit){this.map.addControl(new MQA.ZoomControl);}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());};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 mapOpts={};if(this.editable){};var mapElement=document.getElementById(this.elementID);$(this.elementID).css('overflow','hidden');this.map=new GMap2(mapElement,mapOpts);this.map.addMapType(G_PHYSICAL_MAP);this.map.setCenter(this.getLatLong(this.center),this.zoom);if(mapElement.offsetWidth<ssSmallMapLimit||mapElement.offsetHeight<ssSmallMapLimit){this.map.addControl(new GSmallMapControl());}else{this.map.addControl(new GLargeMapControl());};this.map.addControl(new GMenuMapTypeControl(false,true));var mapTypes={Road:G_NORMAL_MAP,Aerial:G_SATELLITE_MAP,Hybrid:G_HYBRID_MAP,Terrain:G_PHYSICAL_MAP};this.map.setMapType(mapTypes[this.mapType]);GEvent.addListener(this.map,"click",function(overlay,latLng){if(overlay){if(typeof(overlay.ssMapItem_)!='undefined'){overlay.ssMapItem_.click(latLng);};};});};ss.extend(ssBaseMap,ssGoogleMap);ssGoogleMap.prototype.getLatLong=function(xyObject){return new GLatLng(parseFloat(xyObject.y),parseFloat(xyObject.x));};ssGoogleMap.prototype.openItemWindow=function(latLng,mapItem){this.map.openInfoWindowHtml(latLng,mapItem.name+mapItem.getDescription());};ssGoogleMap.prototype.getShapeCenter=function(mapItem){return(mapItem.shape.getBounds().getCenter());};ssGoogleMap.prototype.getShapeLength=function(mapItem){return(mapItem.shape.getLength?mapItem.shape.getLength():0);};ssGoogleMap.prototype.moveTo=function(mapItem,latLong){if(latLong){this.map.panTo(latLong);}else{var shapeCenter=mapItem.getCenter();this.map.panTo(shapeCenter);};};ssGoogleMap.prototype.newMarker=function(mapItem){var thePoint=this.getLatLong(mapItem.points[0]);var theShape=new GMarker(thePoint,{draggable:this.editable,title:mapItem.name});this.map.addOverlay(theShape);return theShape;};ssGoogleMap.prototype.newPolygon=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new GPolygon(latLngs,this.getColor(mapItem.lineColor),mapItem.lineWidth,mapItem.lineOpacity,this.getColor(mapItem.fillColor),mapItem.fillOpacity);this.map.addOverlay(theShape);return theShape;};ssGoogleMap.prototype.newPolyline=function(mapItem){var latLngs=this.getLatLongs(mapItem.points);var theShape=new GPolyline(latLngs,this.getColor(mapItem.lineColor),mapItem.lineWidth,mapItem.lineOpacity);this.map.addOverlay(theShape);return theShape;};ssGoogleMap.prototype.newRectangle=function(mapItem,isSquare){var rectOpts={};if(isSquare)rectOpts["aspectRatio"]=mapItem.aspectRatio;var sw=this.ssMap.getLatLong(mapItem.points[0]);var ne=this.ssMap.getLatLong(mapItem.points[1]);mapItem.shape=new RectangleOverlay(new GLatLngBounds(sw,ne),this.getColor(mapItem.lineColor),mapItem.lineWidth,mapItem.lineOpacity,this.getColor(mapItem.fillColor),mapItem.fillOpacity,rectOpts);this.map.addOverlay(mapItem.shape);};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.addRectangle=function(opts){return this.add(new ssMapItemRectangle(opts,this));};ssMapItems.prototype.addSquare=function(opts){return this.add(new ssMapItemSquare(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='';for(var item in this.items){var mapItem=this.items[item];if(mapItem.inItemList||this.ssMap.editable){sContents+='<li onclick="ssMaps['+mapName+'].itemClick('+mapItem.key+')">';sContents+=mapItem.getListContent();sContents+='</li>';};};$(sElementID).html(sContents);};};function ssMapItem(opts,list){this.name='';this.fillColor='#ff0';this.fillOpacity=0.2;this.icon='';this.lineColor='#f00';this.lineOpacity=0.7;this.lineWidth=3;this.points=[];this.shape=null;this.text='';this.type='';this.hasIcon=false;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);function ssMapItemRectangle(opts,list){ssMapItemRectangle.baseConstructor.call(this,opts,list);this.type='Rectangle';this.hasLine=true;this.hasFill=true;this.shape=this.ssMap.newRectangle(this,false);this.shape.ssMapItem_=this;if(this.ssMap.editable)this.addEditingHandler();};ss.extend(ssMapItem,ssMapItemRectangle);function ssMapItemSquare(opts,list){ssMapItemSquare.baseConstructor.call(this,opts,list);this.type='Square';this.hasLine=true;this.hasFill=true;this.shape=this.ssMap.newRectangle(this,true);this.shape.ssMapItem_=this;if(this.ssMap.editable)this.addEditingHandler();};ss.extend(ssMapItem,ssMapItemSquare);