var map = null;
var geocoder = null;
var lat1 = null;
var long1 = null;
var myPano = null;
var svOverlay = null;
var ohio = new GLatLng(39.9829, -83.0248);

//updated 01-05-12
//three tabs
// no reverse geo yet
// geo's ohio

function load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(ohio, 8);
		// setting overhead map to ohio variable
		myPano = new GStreetviewPanorama(document.getElementById("pano"));
		svOverlay = new GStreetviewOverlay();
		map.addOverlay(svOverlay);
		// add streetview blue

		var stateHouse = new GLatLng(39.961084, -83.000302);
		myPano.setLocationAndPOV(stateHouse);
		// set to streetview to boston

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
	}
}

function showAddress(address) {

	if (!address) {
		address = 'Grandview Heights, Ohio';
	}

	if (geocoder) {
		geocoder
				.getLatLng(
						address,
						function(point) {
							if (!point) {
								alert(address + " not found");
							} else {

								map.setCenter(point, 13);
								var marker = new GMarker(point);
								myPano.setLocationAndPOV(point);

								// removes the shado from the info window and
								// markers
								map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.display = "none";
								map.getPane(G_MAP_MARKER_SHADOW_PANE).style.display = "none";

								// sets streetview to address

								// results mimic
								// http://itouchmap.com/latlong.html

								GEvent
										.addListener(
												map,
												"click",
												function(overlay, pixel) {

													myPano
															.setLocationAndPOV(pixel);
													// sets streetview to
													// location clicked

													var lat2 = pixel.lat();
													var lng2 = pixel.lng();
													var lat1 = pixel.lat();
													var latd = parseInt(lat1);
													var latr = Math.abs(lat1
															- latd);
													var latd = Math.abs(latd);
													var latm = Math
															.floor(latr * 60);
													var lats = Math.floor(latr
															* 3600 - latm * 60);
													var latt = Math
															.floor(Math
																	.abs((latr * 3600 - latm * 60)
																			- lats) * 10000);
													if (latm < 10) {
														latm = "0" + latm;
													}
													if (lats < 10) {
														lats = "0" + lats;
													}
													if (latt < 1000) {
														latt = "0" + latt;
													}// may need to add a
														// less than 100 to
													var long1 = pixel.lng();
													var longd = parseInt(long1);
													var longr = Math.abs(long1
															- longd);
													var longd = Math.abs(longd);
													var longm = Math
															.floor(longr * 60);
													var longs = Math
															.floor(longr * 3600
																	- longm
																	* 60);
													var longt = Math
															.floor(Math
																	.abs((longr * 3600 - longm * 60)
																			- longs) * 1000);
													if (longt < 100) {
														longt = "0" + longt;
													}// adds a 0 if less than
														// 100
													if (longs < 10) {
														longs = "0" + longs;
													}
													if (longd < 100) {
														longd = "0" + longd;
													}
													if (longm < 10) {
														longm = "0" + longm;
													}
													var clickedLEOTFormat = '<div class="clickedInfoWindow">You new values are: '
															+ '<BR><b>LONGITUDE:    <\/b>'
															+ longd
															+ '.'
															+ longm
															+ '.'
															+ longs
															+ '.'
															+ longt
															+ '<br><b>LATITUDE:    <\/b>'
															+ latd
															+ '.'
															+ latm
															+ '.'
															+ lats
															+ '.'
															+ latt
															+ '<BR><\/div>';

													var clickedDecimalFormat = '<div class="clickedInfoWindow">Decimal (Latitude, Longitude):<br><strong> '
															+ lat1.toFixed(6)
															+ ', '
															+ long1.toFixed(6)
															+ '<strong><\/div>';

													var clickedDirectionsToHere = '<div class="clickedInfoWindow">Directions to this location'
															+ '<div class="infoWindowDirections">'
															+ '<form action= "http://maps.google.com/maps" method="get">'
															+ '<label for="saddr">From:<\/label>'
															+ '<input type= "text" name= "saddr" id="saddr" value="" / size="20" >'
															+ '<input type="hidden" name="daddr" id="daddr" value="'
															+ lat1
															+ ','
															+ long1
															+ '" />'
															+ '<input type= "submit" value=" Go " />'
															+ '<\/form><\/div><\/div>';

													marker.hide();

													// Create an array that will
													// hold the tabs
													var clickedTabs = [];
													// Create tabs and add them
													// to the array
													clickedTabs
															.push(new GInfoWindowTab(
																	'LEOT',
																	clickedLEOTFormat));
													clickedTabs
															.push(new GInfoWindowTab(
																	'OH-1',
																	clickedDecimalFormat));
													clickedTabs
															.push(new GInfoWindowTab(
																	'To',
																	clickedDirectionsToHere));
													// ADDreverse address,
													// directions, hours degrees
													// minutes

													// hide the marker before
													// putting up new address
													map.openInfoWindowTabsHtml(
															pixel, clickedTabs);

												});
								var lat1 = point.lat();
								// decimal format
								var latd = parseInt(lat1);
								var latr = Math.abs(lat1 - latd);
								var latd = Math.abs(latd);
								var latm = Math.floor(latr * 60);
								var lats = Math.floor(latr * 3600 - latm * 60);
								var latt = Math
										.floor(Math
												.abs((latr * 3600 - latm * 60)
														- lats) * 10000);
								if (latm < 10) {
									latm = "0" + latm;
								}
								if (lats < 10) {
									lats = "0" + lats;
								}
								if (latt < 1000) {
									latt = "0" + latt;
								}// may need to add a less than 100 to
								var long1 = point.lng();
								// decimal format
								var longd = parseInt(long1);
								var longr = Math.abs(long1 - longd);
								var longd = Math.abs(longd);
								// degrees
								var longm = Math.floor(longr * 60);
								// minutes
								var longs = Math.floor(longr * 3600 - longm
										* 60);
								// seconds
								var longt = Math.floor(Math
										.abs((longr * 3600 - longm * 60)
												- longs) * 1000);

								if (longt < 100) {
									longt = "0" + longt;
								}// adds a 0 if less than 100
								if (longs < 10) {
									longs = "0" + longs;
								}
								if (longd < 100) {
									longd = "0" + longd;
								}
								if (longm < 10) {
									longm = "0" + longm;
								}
								map.addOverlay(marker);// puts the first mark
														// on the screen
								// info window displays address + LAT/LON
								var inputLEOTFormat = address
										+ '<div class="inputInfoWindow"><b>LONGITUDE:    <\/b>'
										+ longd + '.' + longm + '.' + longs
										+ '.' + longt
										+ '<br><b>LATITUDE:    <\/b>' + latd
										+ '.' + latm + '.' + lats + '.' + latt
										+ '<br><\/div>';
								var inputAddressDecimalFormat = '<div class="inputInfoWindow">'
										+ address
										+ '<br/>Decimal (Latitude, Longitude)<br><strong>'
										+ lat1.toFixed(6)
										+ ', '
										+ long1.toFixed(6) + '</strong><\/div>';
								var inputDirectionsToHere = '<div class="inputInfoWindow">Directions to '
										+ address
										+ '<div id="directions">'
										+ '<form action= "http://maps.google.com/maps" method="get">'
										+ '<label for="saddr">From:<\/label>'
										+ '<input type= "text" name= "saddr" id="saddr" value="" / size="20" >'
										+ '<input type="hidden" name="daddr" id="daddr" value="'
										+ lat1
										+ ','
										+ long1
										+ '" />'
										+ '<input type= "submit" value=" Go " />'
										+ '<\/form><\/div><\/div>';
								// Create an array that will hold the tabs
								var inputTabs = [];

								// Create tabs and add them to the array
								inputTabs.push(new GInfoWindowTab('LEOT',
										inputLEOTFormat));
								inputTabs.push(new GInfoWindowTab('OH-1',
										inputAddressDecimalFormat));
								inputTabs.push(new GInfoWindowTab('To',
										inputDirectionsToHere));

								marker.openInfoWindowHtml(inputTabs);
							}
						});
	}
}

