 				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?

# ========== Events ==========
exports.render = ->
	log 'FULL RENDER'
	#loadMap()
	# Ask for location
	if !Geoloc.isSubscribed()
		Geoloc.subscribe()


# Home page with map
mainContent = ->
	log "mainContent()"
	renderMap()
	renderFlags()
	Obs.observe ->
		log "  Map bounds and minzoom set"
		if mapReady()
			# Limit scrolling to the bounds and also limit the zoom level
			loc1 = L.latLng(Db.shared.get('game', 'bounds', 'one', 'lat'), Db.shared.get('game', 'bounds', 'one', 'lng'))
			loc2 = L.latLng(Db.shared.get('game', 'bounds', 'two', 'lat'), Db.shared.get('game', 'bounds', 'two', 'lng'))
			bounds = L.latLngBounds(loc1, loc2)
			map.setMaxBounds(bounds)
			map.fitBounds(bounds);
			map._layersMinZoom = map.getBoundsZoom(bounds)
		Obs.onClean ->
			if map?
				log "  Map bounds and minzoom reset"
				map.setMaxBounds()
				map._layersMinZoom = 0
	addBar()
