 				log "OpenStreetMap files loaded"
 				redraw.modify (v) -> v+1
 		javascript.setAttribute 'src', 'https://api.tiles.mapbox.com/mapbox.js/v2.1.6/mapbox.js'
-		document.getElementsByTagName('head')[0].appendChild javascript	
+		document.getElementsByTagName('head')[0].appendChild javascript
+	else 
+		log "  OpenStreetMap files already loaded"
 
 # Initialize the map with tiles
 setupMap = ->
 	Obs.observe ->
-		log "setupMap"
+		log "setupMap()"
 		if map?
 			log "  map already initialized"
 		else if not L?

			window.map = L.mapbox.map('OpenStreetMap', 'nlthijs48.4153ad9d', {zoomControl:false, updateWhenIdle:false, detectRetina:true})
			layer = L.mapbox.tileLayer('nlthijs48.4153ad9d')
			log "  Initialized MapBox map"
			#mapReady.modify () -> (L? and map?)
		Obs.onClean ->
			log "onClean() of setupMap()"
			if map?
				map.remove()
				window.map = null
				log "  removed map"

# Add flags to the map
renderFlags = ->
	log "rendering flags"
	Db.shared.observeEach 'game', 'flags', (flag) !->
		if mapReady() and map?
			if not window.flagMarkers?
				log "flagMarkers list reset"
				window.flagMarkers = [];
			location = L.latLng(flag.get('location', 'lat'), flag.get('location', 'lng'))
			log "Added flag"
			marker = L.marker(location)
			marker.bindPopup("lat: " + location.lat + "<br>long: " + location.lng)
			marker.addTo(map)
			flagMarkers.push marker
			#log 'Added marker, marker list: ', flagMarkers
			
			log "Added circle"
			if not window.flagCircles?
				log "flagCircles list reset"
				window.flagCircles = [];

				scoresContent()
			else if page == 'log'
				logContent()

exports.renderSettings = !->
	if Db.shared
