var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

// A function to create the marker and set up the event window
function createMarker(point,name,html,icon) {
	var marker = new GMarker(point,icon);

	// The info window version with the "to here" form open
	to_htmls[i] = html + '<br><br>Directions: <b>To here</b> | <a href="javascript:fromhere(' + i + ')">From here</a>' +
		'<br><br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
		'<input type="text" size="40" maxlength="48" name="saddr" id="saddr" value="" style="width: 150px" /> ' +
		'<input value="Get Directions" type="submit">' +
		'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +
		      // "(" + name + ")" +
		'"/>';
	// The info window version with the "from here" form open
	from_htmls[i] = html + '<br><br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> | <b>From here</b>' +
		'<br><br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
		'<input type="text" size="40" maxlength="48" name="daddr" id="daddr" value="" style="width: 150px" /> ' +
		'<input value="Get Directions" type="submit">' +
		'<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
		      // "(" + name + ")" +
		'"/>';
	// The inactive version of the direction info
	html = html + '<br><br>Directions: <a href="javascript:tohere('+i+')">To here</a> | <a href="javascript:fromhere('+i+')">From here</a>';

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// functions that open the directions forms
function tohere(i) {
	gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}
function fromhere(i) {
	gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

// Display the map, with some controls and set the initial location
function initialize() {
	var map = new GMap2(document.getElementById("map_canvas"));
	map.setCenter(new GLatLng(38.903491,-77.044458), 15);
	map.addControl(new GSmallZoomControl());
	
	// Set up markers with info windows 
	var myIcon = new GIcon();
	myIcon.image = '/wp-content/themes/lsi_v2/style/images/gmaps/image.png';
	myIcon.printImage = '/wp-content/themes/lsi_v2/style/images/gmaps/printImage.gif';
	myIcon.mozPrintImage = '/wp-content/themes/lsi_v2/style/images/gmaps/mozPrintImage.gif';
	myIcon.iconSize = new GSize(100,49);
	myIcon.shadow = '/wp-content/themes/lsi_v2/style/images/gmaps/shadow.png';
	myIcon.transparent = '/wp-content/themes/lsi_v2/style/images/gmaps/transparent.png';
	myIcon.shadowSize = new GSize(125,49);
	myIcon.printShadow = '/wp-content/themes/lsi_v2/style/images/gmaps/printShadow.gif';
	myIcon.iconAnchor = new GPoint(35,49);
	myIcon.infoWindowAnchor = new GPoint(50,0);
	myIcon.imageMap = [96,0,98,1,99,2,99,3,99,4,99,5,99,6,99,7,99,8,99,9,99,10,99,11,99,12,99,13,99,14,99,15,99,16,99,17,99,18,99,19,99,20,99,21,99,22,99,23,99,24,99,25,99,26,99,27,99,28,99,29,99,30,99,31,99,32,98,33,97,34,94,35,56,36,54,37,52,38,50,39,49,40,47,41,45,42,44,43,42,44,40,45,39,46,37,47,35,48,34,48,34,47,35,46,36,45,36,44,37,43,37,42,38,41,39,40,39,39,40,38,40,37,41,36,5,35,2,34,1,33,0,32,0,31,0,30,0,29,0,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,1,1,3,0];
	var point = new GLatLng( 38.903485, -77.044553);
	var marker = createMarker(point,'Liquidity Services, Inc.','<strong>Liquidity Services, Inc.</strong><br>1920 L Street NW, 6th Floor<br>Washington, DC 20036',myIcon)
	map.addOverlay(marker);
}
