// CODE LIBRARY REQUIRED FOR 2007 STARCOUNT MAPS 

	var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 0);

	// associative array of icons
	var gicons = [];
	gicons["1"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag1.png");
		gicons["1"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["1"].iconSize = new GSize(12, 20);
		gicons["1"].shadowSize = new GSize(22, 20);
		gicons["1"].iconAnchor = new GPoint(6, 20);
		gicons["1"].infoWindowAnchor = new GPoint(5, 0);
	gicons["2"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag2.png");
		gicons["2"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["2"].iconSize = new GSize(12, 20);
		gicons["2"].shadowSize = new GSize(22, 20);
		gicons["2"].iconAnchor = new GPoint(6, 20);
		gicons["2"].infoWindowAnchor = new GPoint(5, 0);
	gicons["3"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag3.png");
		gicons["3"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["3"].iconSize = new GSize(12, 20);
		gicons["3"].shadowSize = new GSize(22, 20);
		gicons["3"].iconAnchor = new GPoint(6, 20);
		gicons["3"].infoWindowAnchor = new GPoint(5, 0);
	gicons["4"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag4.png");
		gicons["4"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["4"].iconSize = new GSize(12, 20);
		gicons["4"].shadowSize = new GSize(22, 20);
		gicons["4"].iconAnchor = new GPoint(6, 20);
		gicons["4"].infoWindowAnchor = new GPoint(5, 0);
	gicons["5"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag5.png");
		gicons["5"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["5"].iconSize = new GSize(12, 20);
		gicons["5"].shadowSize = new GSize(22, 20);
		gicons["5"].iconAnchor = new GPoint(6, 20);
		gicons["5"].infoWindowAnchor = new GPoint(5, 0);
	gicons["6"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag6.png");
		gicons["6"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["6"].iconSize = new GSize(12, 20);
		gicons["6"].shadowSize = new GSize(22, 20);
		gicons["6"].iconAnchor = new GPoint(6, 20);
		gicons["6"].infoWindowAnchor = new GPoint(5, 0);
	gicons["7"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/mag7.png");
		gicons["7"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["7"].iconSize = new GSize(12, 20);
		gicons["7"].shadowSize = new GSize(22, 20);
		gicons["7"].iconAnchor = new GPoint(6, 20);
		gicons["7"].infoWindowAnchor = new GPoint(5, 0);
	gicons["-99"] = new GIcon(G_DEFAULT_ICON, "http://windows2universe.org/citizen_science/starcount/maps/cloudy.png");
		gicons["-99"].shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
		gicons["-99"].iconSize = new GSize(12, 20);
		gicons["-99"].shadowSize = new GSize(22, 20);
		gicons["-99"].iconAnchor = new GPoint(6, 20);
		gicons["-99"].infoWindowAnchor = new GPoint(5, 0);


    function loadMap(cLat, cLng, cZoom) {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("scmap"));
        map.setCenter(new GLatLng(cLat, cLng), cZoom);
		//map.addControl(new GLargeMapControl());
		map.addControl(new GSmallMapControl());
        map.addControl(new GMenuMapTypeControl()); 
        //map.addControl(new GScaleControl());
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		map.enableDoubleClickZoom();
		map.removeMapType(G_SATELLITE_MAP);
		map.addMapType(G_PHYSICAL_MAP);
	    map.setMapType(G_HYBRID_MAP);
		map.getContainer().style.overflow="hidden"; 
		// hides any copyright overflow
        GDownloadUrl("http://www.windows2universe.org/citizen_science/starcount/maps/genxml.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
			var constellation = markers[i].getAttribute("constellation");
            var lmag = markers[i].getAttribute("lmag");
            var comm_add = markers[i].getAttribute("comm_add");
            var id = markers[i].getAttribute("id");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, constellation, lmag, comm_add, id);
            map.addOverlay(marker);
          }
        });
      }
    }

    function createMarker(point, constellation, lmag, comm_add, id) {
      var marker = new GMarker(point, gicons[lmag]);
	  if (lmag == -99) {
		  lmag = "Cloudy";
	  } //END IF
	  //SPLIT COMMENT INTO REASONABLE WIDTH LINES
	  var tmpComment = splitLine(comm_add,60);
	  var splitComment = tmpComment.replace(/\n/g,'<br \/>');
	  
	  var html = "<b> Limiting Magnitude: " + lmag + 
	             "</b> <br/>Constellation: " + constellation +
				 "<br />Observation #" + id +
				 "<br />" + splitComment;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }


//  ************************************************************************
//  *                                                                      *
//  *        LINE SPLITTING  FUNCTIONS ARE IN THE FOLLOWING BLOCK          *
//  *                                                                      *
//  ************************************************************************

// Line Splitter Function
// copyright Stephen Chapman, 19th April 2006
// you may copy this code but please keep the copyright notice as well
function splitLine(st,n) {
	var b = ''; 
	var s = st;
	while (s.length > n) {
		var c = s.substring(0,n);
		var d = c.lastIndexOf(' ');
		var e =c.lastIndexOf('\n');
		if (e != -1) d = e; 
		if (d == -1) d = n; 
		b += c.substring(0,d) + '\n';
		s = s.substring(d+1);
		} //END WHILE
	return b+s;
} //END FUNCT
                  
