var user_agent=navigator.userAgent.toLowerCase();
var is_iphone = ((user_agent.indexOf('iphone')!=-1));
var map_large;
var pgButtonDiv;
var xShowPG = false;

//--------------------------------------------------------------------------------------------
// Setup P&G Locations Map Button
//--------------------------------------------------------------------------------------------
function pgLocations(){}
pgLocations.prototype = new GControl();
pgLocations.prototype.initialize = function(map){

  pgButtonDiv = document.createElement("div");
  this.setButtonStyle_(pgButtonDiv);
  pgButtonDiv.appendChild(document.createTextNode("Toggle P&G Locations"));
  google.maps.Event.addDomListener(pgButtonDiv, "click", function(){pgLocationsToggle(map);});

  map.getContainer().appendChild(pgButtonDiv);
  return pgButtonDiv;
}
pgLocations.prototype.getDefaultPosition = function(){return new google.maps.ControlPosition(G_ANCHOR_BOTTOM_RIGHT, new google.maps.Size(3,3));}
pgLocations.prototype.setButtonStyle_ = function(button){button.className='pgLocations';}

//--------------------------------------------------------------------------------------------
// Function for initializing Google Map
//--------------------------------------------------------------------------------------------
function gMapInitialize(){

	// Initialize Large Map Modal Window
	if(document.getElementById('large_map_open')){
		$('#large_map_open').openDOMWindow({eventType:'click',width:710,height:445,functionCallOnOpen:getLargeHoodMap});
		$('#large_map_open_pg').openDOMWindow({eventType:'click',width:710,height:445,functionCallOnOpen:getLargeHoodMapPG});
	}

	// Initialize Small Map
	if(GBrowserIsCompatible()){
		map = new google.maps.Map2(document.getElementById('google_map'));
		map.setCenter(new google.maps.LatLng('39.10','-84.52'),11);
		var uiOptions = map.getDefaultUI(new google.maps.Size(292,292));
		uiOptions.zoom.scrollwheel = false;
		uiOptions.controls.menumaptypecontrol = false;
		map.setUI(uiOptions);

		if(xHoodMap != false){
			var geoXml = new google.maps.GeoXml(xHoodMap);
			map.addOverlay(geoXml);
			google.maps.Event.addListener(geoXml,'load',function(){
				if(geoXml.loadedCorrectly()){

					// Hide 'loader' after LOAD
					google.maps.Event.addListener(map,"moveend",function(){$("#google_map_loader").fadeOut('slow');});

					// Add Location markers to Map
					if(typeof xLocations != 'undefined'){
						for(x in xLocations){map.addOverlay(new google.maps.Marker(new google.maps.LatLng(xLocations[x][0],xLocations[x][1])));}
					}

					// Center Map
					geoXml.gotoDefaultViewport(map);

				}
			});
		}
	}
}$(document).ready(gMapInitialize);
//--------------------------------------------------------------------------------------------
// Loads a Larger Map in modal window
//--------------------------------------------------------------------------------------------
function getLargeHoodMap(){

	map_large = new google.maps.Map2(document.getElementById("google_map_large"));

	// Setup Large Neighborhood Map
    map_large.setCenter(new google.maps.LatLng('39.10','-84.52'),11);
    var uiOptions = map_large.getDefaultUI();
    uiOptions.zoom.scrollwheel = false;
    map_large.setUI(uiOptions);
	map_large.addControl(new pgLocations());

	// Get Large Neighborhood Boundaries
	if(xHoodMap != false){
		var geoXml = new google.maps.GeoXml(xHoodMap);
		map_large.addOverlay(geoXml);
		google.maps.Event.addListener(geoXml,"load",function(){
			if(geoXml.loadedCorrectly()){

				// Hide 'loader' after LOAD
				google.maps.Event.addListener(map_large,"moveend",function(){$("#google_map_large_loader").fadeOut('slow');});

				// Add Location markers to Map
				if(typeof xLocations != 'undefined'){
					for(x in xLocations){map_large.addOverlay(new google.maps.Marker(new google.maps.LatLng(xLocations[x][0],xLocations[x][1])));}
				}

				// Handle P&G Locations Logic
				pgVisible = false;
				if(xShowPG) pgLocationsToggle(map_large);
				geoXml.gotoDefaultViewport(map_large);
				xShowPG=false;
			}
		});
	}
}
function getLargeHoodMapPG(){xShowPG=true;getLargeHoodMap();}
