/* SCLS Member Libraries Map */
/* This script uses the Google Maps API to produces an interactive map of the SCLS Member Libraries*/

window.onload=function initialize() {
  if (GBrowserIsCompatible()) {
	
	//Create the marker objects, make them clickable, and send them back 
	function createMarker(point,title,html) {
		
		//Add a directions link
		html += '<br><br><a href="http://maps.google.com/maps?saddr=&daddr=' + point.toUrlValue() + '" target ="_blank">Directions<\/a>';

        var marker = new GMarker(point, {title:title});
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
    }
	
	//Data for each library
	var libraryData = [['Albertson Memorial Library (Albany)', 42.7062149, -89.4369609, '200 N Water St., Albany, WI 53502', 'http://www.albertsonlibrary.org/'],
						['Adams County Library', 43.9661571, -89.8216054, '559 N Cedar St., Adams, WI 53910', 'http://www.scls.lib.wi.us/acl/'],
						['Lettie W. Jensen Library (Amherst)', 44.4545182, -89.2845575, '278 N Main St., Amherst, WI 54406', 'http://www.scls.lib.wi.us/amh/'],
						['Lester Public Library of Arpin', 44.5345965, -90.0450967, '8091 County Road E, Arpin, WI 54410','http://www.arpinpl.org' ],
						['Baraboo Public Library', 43.4708849, -89.7448223, '230 4th Ave., Baraboo, WI 53913', 'http://www.baraboopubliclibrary.org/'],
						['Belleville Public Library', 42.8583237, -89.5339907, '130 S. Vine St., Belleville, WI 53508', 'http://www.scls.lib.wi.us/blv/'],
						['Black Earth Library', 43.1380363, -89.7479987, '1210 Mills St., Black Earth, WI 53515', 'http://www.bepubliclibrary.org/'],
						['Memorial Public Library (Brodhead)', 42.606391, -89.377914, '1207 25th Street., Brodhead 53520', 'http://www.brodheadlibrary.org/'], 
						['Jane Morgan Memorial Library (Cambria)', 43.543202, -89.107994, '109 W. Edgewater St., Box 477, Cambria 53923', 'http://www.janemorganmemoriallibrary.org/'],
						['Cambridge Community Library', 43.003609, -89.01673, '200 S. Spring St., Box 490, Cambridge 53523', 'http://www.cambridgelib.org/'],
						['Columbus Public Library', 43.3394307, -89.0163346, '223 W. James St., Columbus 53925', 'http://www.columbuspubliclibrary.info/'],
						['Rosemary Garfoot Public Library (Cross Plains)', 43.113821, -89.647001, '2107 Julius St., Cross Plains 53528', 'http://www.rgpl.org/' ],
						['Dane County Library Service', 43.073932, -89.387354, '201 W. Mifflin St., Madison 53703', 'http://www.dcls.info/'],
						['Deerfield Public Library', 43.0542914, -89.0758858, '12 W. Nelson St., P.O. Box 408, Deerfield 53531', 'http://www.scls.lib.wi.us/deerfield/'],
						['DeForest Area Public Library', 43.2476013, -89.3423667, '203 Library St., DeForest 53532', 'http://www.deforest.lib.wi.us/'],
						['LaValle Public Library', 43.582204, -90.129932, '101 W. Main St., Box 7, La Valle 53941', 'http://www.scls.lib.wi.us/lav/'],
						['Lodi Woman\'s Club Public Library', 43.3082756, -89.5337574, '130 Lodi St., Lodi 53555', 'http://www.lodipubliclibrary.org/'],
						['Madison Public Library: Central Branch', 43.0740796, -89.3873152, '201 W. Mifflin St., Madison 53703', 'http://www.madisonpubliclibrary.org/'],
						['Madison Public Library: Alicia Ashman Branch', 43.0758147, -89.5185977, '733 N. High Point Rd., Madison 53717', 'http://www.madisonpubliclibrary.org/about/ashman.html'],
						['Madison Public Library: Hawthorne Branch', 43.101523, -89.346592, '2707 East Washington Ave., Madison, WI 53704', 'http://www.madisonpubliclibrary.org/about/hawthorn.html'],
						['Madison Public Library: Lakeview Branch', 43.128382, -89.3635144, '2845 N. Sherman Ave., Madison, WI 53704', 'http://www.madisonpubliclibrary.org/about/lakeview.html'], 
						['Madison Public Library: Meadowridge Branch', 43.032489, -89.478433, '5740 Raymond Rd., Madison, WI 53711', 'http://www.madisonpubliclibrary.org/about/meadow.html'],
						['Madison Public Library: Monroe Street Branch', 43.0659581, -89.4154815, '1705 Monroe St., Madison, WI 53711', 'http://www.madisonpubliclibrary.org/about/monroe.html'],
						['Madison Public Library: Pinney Branch', 43.0837105, -89.3233334, '204 Cottage Grove Road, Madison, WI 53716', 'http://www.madisonpubliclibrary.org/about/pinney.html'],
						['Madison Public Library: Sequoya Branch', 43.0535988, -89.4500662, '4340 Tokay Blvd, Madison, WI 53711', 'http://www.madisonpubliclibrary.org/about/sequoya.html'],
						['Madison Public Library: South Madison Branch', 43.041682, -89.395026, '2222 S. Park St., Madison, WI 53713', 'http://www.madisonpubliclibrary.org/about/southmad.html'],
						['Marshall Community Library', 43.1680504, -89.0521801, '605 Waterloo Road, Marshall 53559', 'http://www.marlib.org/'],
						['Marshfield Public Library', 44.6654005, -90.1726801, '211 E. Second St., Marshfield 54449', 'http://www.marshfieldlibrary.org/'],
						['Mazomanie Free Library', 43.175541, -89.794877, '102 Brodhead St., P.O. Box 458, Mazomanie 53560', 'http://www.scls.lib.wi.us/mazomanie/'],
						['E.D. Locke Public Library (McFarland)', 43.0134546, -89.2874297, '5920 Milwaukee St., McFarland 53558', 'http://www.mcfarlandlibrary.org/'],
						['Middleton Public Library', 43.09515, -89.5090772, '7425 Hubbard Ave., Middleton 53562', 'http://www.midlibrary.org/'],
						['Monona Public Library', 43.063786, -89.342094, '1000 Nichols Rd., Monona 53716', 'http://www.mononalibrary.org/'],
						['Monroe Public Library', 42.6026852, -89.6398499, '925 16th Ave., Monroe 53566', 'http://www.monroepubliclibrary.org/' ],
						['Monticello Public Library', 42.745565, -89.5895746, '512 E. Lake Ave., P.O. Box 149, Monticello 53570', 'http://www.monticellopubliclibrary.org/'],
						['Mt. Horeb Public Library', 43.0082522, -89.7216748, '105 Perimeter Rd., Mt. Horeb 53572', 'http://www.mhpl.org/'],
							['Charles & JoAnn Lester Library (Nekoosa)', 44.3152622, -89.9020799, '100 Park St., Nekoosa 54457', 'http://www.nekoosalibrary.com/'],
						['New Glarus Public Library', 42.8170769, -89.6353518, '319 Second St., PO Box 35, New Glarus 53574', 'http://www.newglaruspubliclibrary.org/'],
						['North Freedom Public Library', 43.460391, -89.860758, '105 N. Maple St., Box 60, North Freedom 53951', 'http://www.scls.lib.wi.us/nof/'],
						['Oregon Public Library', 42.9265714, -89.3809596, '256 Brook St., Oregon 53575', 'http://www.oregonpubliclibrary.org/'],
						['Angie W. Cox Public Library (Pardeeville)', 43.538292, -89.299934, '119 N. Main St., Box 370, Pardeeville 53954', 'http://www.pardeevillelibrary.com/'],
						['Pittsville Community Library', 44.4392336, -90.1263998, '5291 Third Ave., Pittsville 54466', 'http://www.scls.lib.wi.us/pit/'],
						['Kraemer Library & Community Center (Plain)', 43.2787943, -90.0423811, '910 Main St., Plain 53577', 'http://www.kraemerlibrary.org/' ],
						['Portage Public Library', 43.5386327, -89.4605868, '253 W. Edgewater St., Portage 53901', 'http://www.scls.lib.wi.us/portage/'],
						['Poynette Area Public Library', 43.391657, -89.402779, '118 N. Main St., Box 368, Poynette 53955', 'http://www.poynettelibrary.com/'],
						['Prairie du Sac Public Library', 43.2913416, -89.7218842, '560 Park Ave., Prairie du Sac 53578', 'http://www.pdslibrary.org/'],
						['Reedsburg Public Library', 43.5315094, -90.0055344, '370 Vine St., Reedsburg 53959', 'http://www.reedsburglibrary.org/'],
						['Rio Community Library', 43.445598, -89.2409493, '324 W. Lyons St., P.O. Box 306, Rio 53960', 'http://www.scls.lib.wi.us/rio/'],
						['Rock Springs Public Library', 43.480399, -89.917949, '101 First St., P.O. Box 56, Rock Springs 53961', 'http://www.rockspringslibrary.com/'],
						['Lester Public Library of Rome', 44.2014731, -89.8101532, '1157 Rome Center Dr., Nekoosa 54457', 'http://www.romepubliclibrary.org/'],
						['Sauk City Public Library', 43.2752524, -89.7205635, '515 Water St., Sauk City 53583', 'http://www.saukcitylibrary.org/'],
						['Spring Green Community Library', 43.1778028, -90.0661757, '230 E. Monroe St., Spring Green 53588', 'http://www.springgreenlibrary.org/'],
						['Portage County Public Library (Stevens Point)', 44.5234172, -89.5844272, '1001 Main St., Stevens Point 54481', 'http://library.uwsp.edu/pcl/'],
						['Portage County Public Library: Almond Branch', 44.2626292, -89.4087453, '122 Main St., Almond, WI 54909', 'http://library.uwsp.edu/pcl/almond.htm'], 
						['Portage County Public Library: Plover Branch', 44.464309, -89.53218, '2151 Roosevelt Dr., Plover, WI 54467', 'http://library.uwsp.edu/pcl/plover.htm'], 
						['Portage County Public Library: Rosholt Branch', 44.6286808, -89.3087984, '137 N. Main Street, Roshold, WI 54473', 'http://library.uwsp.edu/pcl/rosholt.htm'],
						['Stoughton Public Library', 42.916479, -89.218108, '304 S. 4th St., Stoughton 53589', 'http://www.stoughtonpubliclibrary.org/'],
						['Sun Prairie Public Library', 43.175502, -89.235506, '1350 Linnerud Dr., Sun Prairie 53590', 'http://www.sunprairiepubliclibrary.org/'],
						['Verona Public Library', 42.996136, -89.529885, '500 Silent St., Verona 53593', 'http://www.veronapubliclibrary.org/'],
						['Lester Public Library of Vesper', 44.4838212, -89.9693176, '6550 Virginia St., Vesper 54489', 'http://www.scls.lib.wi.us/ves/' ],
						['Waunakee Public Library', 43.185089, -89.455882, '710 South St., Waunakee 53597', 'http://www.waunakeepubliclibrary.org/'],
						['Kilbourn Public Library (Wisconsin Dells)', 43.6253035, -89.7723008, '620 Elm St., Wisconsin Dells 53965', 'http://www.dellslibrary.org/'],
						['McMillan Memorial Library (Wisconsin Rapids)', 44.3882131, -89.8209536, '490 East Grand Ave., Wisconsin Rapids 54494', 'http://www.mcmillanlibrary.org/'],
						['Wyocena Public Library', 43.4940502, -89.3091797, '165 E. Dodge St., P.O. Box 913., Wyocena 53969']];
	
	//Draw the map on the page with the zoom slider
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(43.636075, -89.593506),8);
	
	//Create a manager to handle the markers more efficiently  
	var mgr = new GMarkerManager(map);
	
	//Markers have to be in an array
	var sclsMarkers = [];
	
	//Loop through the raw data array to create markers and put the markers in an array	
	var arrayLength= libraryData.length;
	
	for (var i = 0; i < arrayLength ; i++) {
		
		var point = new GLatLng(libraryData[i][1], libraryData[i][2]);
		var marker = createMarker(point, libraryData[i][0], '<b>'+ libraryData[i][0] + '</b><br>' + libraryData[i][3] + '<br><a href="' + libraryData[i][4] + '">' + libraryData[i][4] + '</a>');
		sclsMarkers.push(marker);
		
	}
	
	//Add the markers to the manager and specify the zoom levels at which they should be visible
	mgr.addMarkers(sclsMarkers, 0, 17);
	mgr.refresh();
	
  }
}
