if(!pegmanGIcon){
	var pegmanGIcon = new GIcon(G_DEFAULT_ICON);
	pegmanGIcon.image = "http://media.sddt.com/images/scout_sprite_005.png";
	pegmanGIcon.transparent = "http://maps.gstatic.com/mapfiles/cb/man-pick.png";
	pegmanGIcon.imageMap = [26,13,30,14,32,28,27,28,28,36,18,35,18,27,16,26,16,20,16,14,19,13,22,8];
	pegmanGIcon.iconSize = new GSize(49, 52);
	pegmanGIcon.iconAnchor = new GPoint(25, 35);
	pegmanGIcon.infoWindowAnchor = new GPoint(25, 5);
	pegmanGIcon.shadow = "";
	/*
	pegmanGIcon.dragCrossImage = "http://media.sddt.com/images/scout_sprite_dragcross.png";
	pegmanGIcon.dragCrossSize = new GSize(24,24);
	pegmanGIcon.dragCrossAnchor = new GPoint(12,12);
	*/
	pegmanGIcon._images = {
		'default':"http://media.sddt.com/images/scout_sprite_005.png",
		'dragRight':"http://media.sddt.com/images/scout_sprite_drag_right.png",
		'dragLeft':"http://media.sddt.com/images/scout_sprite_drag_left.png"
	};
}
if(!dotGIcon){
	var dotGIcon = new GIcon();
	dotGIcon.image = "http://media.sddt.com/images/gmap-dot-red.png";
	dotGIcon.shadow = "";
	dotGIcon.iconSize = new GSize(8,8);
	dotGIcon.shadowSize = new GSize(0,0);
	dotGIcon.iconAnchor = new GPoint(4,4);
	dotGIcon.infoWindowAnchor = new GPoint(4,4);
	dotGIcon.imageMap = [1,0,7,0,8,1,8,7,7,8,1,8,0,7,0,1];
}
if(!nullGIcon){
	var nullGIcon = new GIcon();
	nullGIcon.image = "";
	nullGIcon.shadow = "";
	nullGIcon.iconSize = new GSize(0,0);
	nullGIcon.shadowSize = new GSize(0,0);
	nullGIcon.iconAnchor = new GPoint(0,0);
	nullGIcon.infoWindowAnchor = new GPoint(0,0);
}


if(!gMaps)
	var gMaps = {};
if(!gMaps.clients)
	gMaps.clients = {};
if(!gMaps.clients.geocode)
	gMaps.clients.geocode = new GClientGeocoder();
if(!gMaps.clients.streetView)
	gMaps.clients.streetView = new GStreetviewClient();
if(!yes)
	var yes = true;
if(!no)
	var no = false;
if(!boundsSD)
	var boundsSD = new GLatLngBounds(new GLatLng(32.718672,-117.164072),new GLatLng(32.718988,-117.163592));

function initTraffic(map){
	map._custom.traffic = {};
	map._custom.traffic.control = new GControlTraffic();
	map._custom.traffic.overlay = new GTrafficOverlay({hide:true});
	map._custom.traffic.state = 0;
	map.addOverlay(map._custom.traffic.overlay);
	map.addControl(map._custom.traffic.control);
	
	return map;
}

function initStreetView(map){
	map._custom.streetView = {};
	map._custom.streetView.panoramaContainer = new GControlStreetViewPanorama();
	map._custom.streetView.pegmanControl = new GControlStreetViewPegman();

	map.addControl(map._custom.streetView.panoramaContainer);
	map.addControl(map._custom.streetView.pegmanControl);

	map._custom.streetView.pegman = new GMarker(boundsSD.getCenter(),{icon:pegmanGIcon,draggable:true});
	map._custom.streetView.pegman.prevLatLng = map._custom.streetView.pegman.getLatLng();

	map._custom.listeners.pegmanDragStart = GEvent.addListener(map._custom.streetView.pegman,"dragstart",function(){
		$(".pegman.control").addClass("onMap");
		map._custom.streetView.overlay.show();
		this.setImage(this.getIcon()._images.dragRight);
		return this;
	});
	map._custom.listeners.pegmanDrag = GEvent.addListener(map._custom.streetView.pegman,"drag",function(){
		if(this.getLatLng().lng() - this.prevLatLng.lng() > 0)
			this.setImage(this.getIcon()._images.dragRight);
		else
			this.setImage(this.getIcon()._images.dragLeft);
		this.prevLatLng = this.getLatLng();
		return this;
	});
	map._custom.listeners.pegmanDragEnd = GEvent.addListener(map._custom.streetView.pegman,"dragend",function(){
		map._custom.streetView.overlay.hide();
		this.setImage(this.getIcon()._images['default']);
		this.setLatLng(arguments[0]);
		this.show();
		gMaps.clients.streetView.getNearestPanoramaLatLng(this.getLatLng(),function(){
			if(arguments[0]){
				$(map.getContainer()).children(".panoContainer").show().css({"left":"9%","top":"9%"});
				map._custom.streetView.panorama.setLocationAndPOV(arguments[0]);
			}
			return this;
		});
		return this;
	});
	
	map._custom.listeners.mapDragEnd = GEvent.addListener(map,"dragend",function(){
		if(!this._custom.streetView.pegman.isHidden() && this.getBounds().containsLatLng(this._custom.streetView.pegman.getLatLng()))
			$(".pegman.control").addClass("onMap");
		else
			$(".pegman.control").removeClass("onMap");
	});

	map.addOverlay(map._custom.streetView.pegman);
	map._custom.streetView.pegman.hide();

	map._custom.listeners.mapLoad_StreetViewOverlay = GEvent.addListener(map,"load",function(){
		this._custom.streetView.overlay = new GStreetviewOverlay();
		this.addOverlay(this._custom.streetView.overlay);
		this._custom.streetView.overlay.hide();
	});
	
	return map;
}

gMaps.init = function(mapID,opts){
	map = new GMap2($("#"+mapID).get(0));
	map._custom = {};
	map._custom.marks = new Array();
	map._custom.marksBounds = new GLatLngBounds();
	map._custom.listeners = {};
	
	if(map.getMapTypes().length > 1){
		map.addControl(new GMapTypeControl(true));
		map.addControl(new GControlSddtLogo(),new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 28)));
	} else {
		map.addControl(new GControlSddtLogo());
	}

	if(arguments[1]){
		if(opts.gMapUIOptions)
			map.setUI(opts.gMapUIOptions);
		if(opts.traffic)
			initTraffic(map);
		if(opts.streetView)
			initStreetView(map);
		if(opts.googleBar)
			map.enableGoogleBar();
		if(opts.onLoad)
			map._custom.listeners.onMapLoad = GEvent.addListener(map,"load",opts.onLoad);
	}
	
	map.addMarker = function(marker,opts){
		if(arguments.length < 1)
			return this;
		var map = this;
		marker.clickable = true;
		
		var streetView = typeof(map._custom.streetView) == 'object';
		var onPlacementCallback = function(){return null};
		var extendViewport = true;
		if(arguments[1]){
			if(typeof(opts.streetView) == 'boolean')
				streetView = opts.streetView;
			if(typeof(opts.onPlacementCallback) == 'function')
				onPlacementCallback = opts.onPlacementCallback;
			if(typeof(opts.extendViewport) == 'boolean')
				extendViewport = opts.extendViewport;
		}
		
		var placeMarker = function(point){
			if(!point)
				return this;
			if((typeof(marker.markerType) == "string")&&(marker.markerType == "label"))
				var mark = new LabeledMarker(point,marker)
			else
				var mark = new GMarker(point,marker);
			var infoContainer = $("<div>"+marker.infoWindowHtml+"</div>").addClass("marker-infowindow").get(0);
			map._custom.marks.push(mark);
			mark.bindInfoWindow(infoContainer,{"maxWidth":marker.infoWindowWidth});
			
			if(streetView){
				gMaps.clients.streetView.getNearestPanorama(mark.getLatLng(),function(){
					var svData = arguments[0];
					if(svData.location && svData.location.latlng){
						$(infoContainer).append("<a>Street View</a>");
						$(infoContainer).children("a").attr("href","javascript:;").bind("click",function(){
							GEvent.trigger(map._custom.streetView.pegman,"dragend",svData.location.latlng);
						});
						mark.bindInfoWindow(infoContainer,{"maxWidth":marker.infoWindowWidth});
					}
					return svData;
				});
			}
			
			map._custom.marksBounds.extend(point);
			map.addOverlay(mark);
			
			if(extendViewport){
				map.setCenter(map._custom.marksBounds.getCenter());
				map.setZoom(map.getBoundsZoomLevel(map._custom.marksBounds));
			}

			onPlacementCallback(mark,map);

			return mark;
		}

		if(typeof(marker.latlng) == 'object'){
			placeMarker(marker.latlng);
		} else {
			gMaps.clients.geocode.getLatLng(marker.address,placeMarker);
		}

		return this;
	}

	return map;
}
