﻿/////////////////////////////////////////////////////////////////////////////////
// DESCRIPTION:		Global Variables
// REMARKS:			Supports Google Maps 3.0 
var panorama;
var currentPanoramaHeading = 0;
var currentPanoramaPitch = 0;
var currentPanoramaZoom = 1;
var scrollTimer;
var scrolling = false;
var locationTimer;
var zoomingIn = true;
var positions;
var currentLocation = 0;
var geocoder = null;
var map = null;
var mapAddressName;
var point = null;
var mapZoom = 15;
var marker = null;
var tourDescription;

/////////////////////////////////////////////////////////////////////////////////
// DESCRIPTION:		Street View Tour Cities
// REMARKS:			Supports Google Maps 3.0 
var SVTlocations = [];
var lastI;
var cities = [
['London', 51.5002, -0.1262, '<a href="http://london.streetviewtours.com">London Tourism Guide</a><br/>Browse the <a href="http://london.streetviewtours.com">visitors guide to London</a>'],
['Paris', 48.8567, 2.3510, '<a href="http://paris.streetviewtours.com">Paris Tourism Guide</a><br/>Browse the <a href="http://paris.streetviewtours.com">visitors guide to Paris</a>'],
['Singapore', 1.2894, 103.8500, '<a href="http://singapore.streetviewtours.com">Singapore Tourism Guide</a><br/>Browse the <a href="http://singapore.streetviewtours.com">visitors guide to Singapore</a>'],
['Hong Kong', 22.3964, 114.1095, '<a href="http://hongkong.streetviewtours.com">Hong Kong Tourism Guide</a><br/>Browse the <a href="http://hongkong.streetviewtours.com">visitors guide to Hong Kong</a>'],
['New York', 40.7590, -73.9845, '<a href="http://newyork.streetviewtours.com">New York Tourism Guide</a><br/>Browse the <a href="http://newyork.streetviewtours.com">visitors guide to New York</a>'],
['Rome', 41.8955, 12.4823, '<a href="http://rome.streetviewtours.com">Rome Tourism Guide</a><br/>Browse the <a href="http://rome.streetviewtours.com">visitors guide to Rome</a>'],
['Barcelona', 41.3879, 2.1699, '<a href="http://barcelona.streetviewtours.com">Barcelona Tourism Guide</a><br/>Browse the <a href="http://barcelona.streetviewtours.com">visitors guide to Barcelona</a>'],
['Toronto', 43.6525, -79.3817, '<a href="http://toronto.streetviewtours.com">Toronto Tourism Guide</a><br/>Browse the <a href="http://toronto.streetviewtours.com">visitors guide to Toronto</a>'],
['Madrid', 40.4167, -3.7003, '<a href="http://madrid.streetviewtours.com">Madrid Tourism Guide</a><br/>Browse the <a href="http://madrid.streetviewtours.com">visitors guide to madrid</a>'],
['Amsterdam', 52.3738, 4.8909, '<a href="http://amsterdam.streetviewtours.com">Amsterdam Tourism Guide</a><br/>Browse the <a href="http://amsterdam.streetviewtours.com">visitors guide to Amsterdam</a>'],
['Los Angeles', 34.0522, -118.2437, '<a href="http://losangeles.streetviewtours.com">Los Angeles Tourism Guide</a><br/>Browse the <a href="http://losangeles.streetviewtours.com">visitors guide to Los Angeles </a>'],
['San Francisco', 37.7749, -122.4194, '<a href="http://sanfrancisco.streetviewtours.com">San Francisco Tourism Guide</a><br/>Browse the <a href="http://sanfrancisco.streetviewtours.com">visitors guide to San Francisco</a>'],
['Orlando', 28.5383, -81.3792, '<a href="http://orlando.streetviewtours.com">Orlando Tourism Guide</a><br/>Browse the <a href="http://orlando.streetviewtours.com">visitors guide to Orlando</a>'],
['Miami', 25.7890, -80.2264, '<a href="http://miami.streetviewtours.com">Miami Tourism Guide</a><br/>Browse the <a href="http://miami.streetviewtours.com">visitors guide to Miami</a>'],
['Sydney', -33.8671, 151.2071, '<a href="http://sydney.streetviewtours.com">Sydney Tourism Guide</a><br/>Browse the <a href="http://sydney.streetviewtours.com">visitors guide to Sydney</a>'],
['Las Vegas', 36.1146, -115.1728, '<a href="http://lasvegas.streetviewtours.com">Las Vegas Tourism Guide</a><br/>Browse the <a href="http://lasvegas.streetviewtours.com">visitors guide to Las Vegas</a>'],
['Tokyo', 35.6895, 139.6917, '<a href="http://tokyo.streetviewtours.com">Tokyo Tourism Guide</a><br/>Browse the <a href="http://montreal.streetviewtours.com">visitors guide to Tokyo</a>'],
['Washington DC ', 38.8988, -77.0367, '<a href="http://washington.streetviewtours.com">Washington DC  Tourism Guide</a><br/>Browse the <a href="http://washington.streetviewtours.com">visitors guide to Washington DC </a>'],
['Chicago', 41.8500, -87.6501, '<a href="http://chicago.streetviewtours.com">Chicago Tourism Guide</a><br/>Browse the <a href="http://chicago.streetviewtours.com">visitors guide to Chicago</a>'],
['Boston', 42.3584, -71.0598, '<a href="http://boston.streetviewtours.com">Boston Tourism Guide</a><br/>Browse the <a href="http://boston.streetviewtours.com">visitors guide to Boston</a>'],
['Melbourne', -37.8143, 144.9632, '<a href="http://melbourne.streetviewtours.com">Melbourne Tourism Guide</a><br/>Browse the <a href="http://melbourne.streetviewtours.com">visitors guide to Melbourne</a>'],
['Montreal', 45.5089, -73.5542, '<a href="http://montreal.streetviewtours.com">Montreal Tourism Guide</a><br/>Browse the <a href="http://montreal.streetviewtours.com">visitors guide to Montreal</a>'],
['Atlanta', 33.7490, -84.3880, '<a href="http://atlanta.streetviewtours.com">Atlanta Tourism Guide</a><br/>Browse the <a href="http://atlanta.streetviewtours.com">visitors guide to Atlanta</a>'],
['Houston', 29.7629, -95.3831, '<a href="http://houston.streetviewtours.com">Houston Tourism Guide</a><br/>Browse the <a href="http://houston.streetviewtours.com">visitors guide to Houston</a>'],
['Caribbean Weddings and Honeymoons', 17.9927, -76.7920, '<a href="http://romanticgetaways.streetviewtours.com">Caribbean Weddings and Honeymoons</a><br/>Browse the <a href="http://romanticgetaways.streetviewtours.com">Caribbean weddings and Honeymoon Guide</a>'],
['Vancouver', 49.2485, -123.1088, '<a href="http://vancouver.streetviewtours.com">Vancouver Tourism Guide</a><br/>Browse the <a href="http://vancouver.streetviewtours.com">visitors guide to Vancouver</a>']
];

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		InitializeMap
// DESCRIPTION:		initializes the map with full controls
// REMARKS:			Supports Google Maps 3.0
function InitializeMap() {
    var myLatLng = new google.maps.LatLng(39.397, -100.644);
    var myOptions = {
        zoom: 3,
        center: myLatLng,
        mapTypeControl: true,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
        navigationControl: true,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false,
        sensor: 'true'		
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
	
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		InitializeMapNoTypeControl
// DESCRIPTION:		initializes the map with no type control
// REMARKS:			Supports Google Maps 3.0
function InitializeMapNoTypeControl() {
    var myLatLng = new google.maps.LatLng(39.397, -100.644);
    var myOptions = {
        zoom: 3,
        center: myLatLng,
        mapTypeControl: false,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
        navigationControl: true,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false,
        sensor: 'true'
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
	
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		InitializeMapNoNavControl
// DESCRIPTION:		initializes the map with no nav controls
// REMARKS:			Supports Google Maps 3.0
function InitializeMapNoNavControl() {
    var myLatLng = new google.maps.LatLng(39.397, -100.644);
    var myOptions = {
        zoom: 3,
        center: myLatLng,
        mapTypeControl: true,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
        navigationControl: false,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false,
        sensor: 'true'
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
	
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		InitializeMapNoControls
// DESCRIPTION:		initializes the map with no controls
// REMARKS:			Supports Google Maps 3.0
function InitializeMapNoControls() {
    var myLatLng = new google.maps.LatLng(39.397, -100.644);
    var myOptions = {
        zoom: 3,
        center: myLatLng,
        mapTypeControl: false,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
        navigationControl: false,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false,
        sensor: 'true'
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
	
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadLocationOnMap
// DESCRIPTION:		shows a location on the map
// REMARKS:			Supports Google Maps 3.0 
function LoadLocationOnMap(address, addressName) {
    mapAddressName = addressName;
    geocoder.geocode({ 'address': address }, LoadAddressOnMap);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		AddMarker
// DESCRIPTION:		adds a marker to the map
// REMARKS:			Supports Google Maps 3.0 
function AddMarker(lati, longi)
{
	// create the marker, add the marker to the map, and center around the marker
	// Create the marker image
        // Origins, anchor positions and coordinates of the marker
        // increase in the X direction to the right and in
        // the Y direction down.
        // This marker is 20 pixels wide by 32 pixels tall.
        // The origin for this image is 0,0.
        // The anchor for this image is the base of the flagpole at 0,32.
        var image = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin.png',
        new google.maps.Size(32, 32),
        new google.maps.Point(0, 0),
        new google.maps.Point(0, 32));

        // The shadow image is larger in the horizontal dimension
        // while the position and offset are the same as for the main image.
        // Shapes define the clickable region of the icon.
        // The type defines an HTML &lt;area&gt; element 'poly' which
        // traces out a polygon as a series of X,Y points. The final
        // coordinate closes the poly by connecting to the first
        // coordinate.
        var shadow = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin_shadow.png',
            new google.maps.Size(48, 32),
            new google.maps.Point(0, 0), 
            new google.maps.Point(0, 32));
        
        // Create the shape
        var shape = {
            coord: [1, 1, 1, 32, 18, 32, 18, 1],
            type: 'poly'
        };
	
		var markerPosition = new google.maps.LatLng(lati, longi);
	
	    marker = new google.maps.Marker({
            position: markerPosition,
            title:mapAddressName,
			icon: image,
            shape: shape});

        marker.setMap(map); 
        map.setCenter(markerPosition);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddressOnMap
// DESCRIPTION:		This function is called when the geocoder returns an
//                  answer.  It adds a marker to the map 
// REMARKS:			Supports Google Maps 3.0 
function LoadAddressOnMap(results, status) {
   
    // clear the previous marker, if it exists
    if(marker)
    {
        marker.setMap(null); 
        marker = null;
    }
    
    if (status == google.maps.GeocoderStatus.OK) 
    {
		var lat = results[0].geometry.location.lat();
		var lng = results[0].geometry.location.lng();
		AddMarker(lat, lng);
        
    } 
	else 
	{
	    alert("Failed to load address: " + mapAddressName);
	}
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadBaseHome
// DESCRIPTION:		Loads the home page for streetview tours along witht the
//                  5 featured destinations
// REMARKS:			Supports Google Maps 3.0 
function LoadBaseHome() {
    // create the geocoder object
    geocoder = new google.maps.Geocoder();
    
    // create the positions
    positions = new Array(5);
    positions[0] = "Theater District - Times Square, New York, NY, USA";
    positions[1] = "318 Yonge St, Toronto, ON, Canada";
    positions[2] = "5 Place de l'Hôtel-de-Ville, Paris, France";
    positions[3] = "201 Piccadilly, London, England, United Kingdom";
    positions[4] = "582 Nathan Rd, Hong Kong";
    
    // load our street view panorama
    var cityPosition = new google.maps.LatLng(40.757333, -73.986);
    var panoramaOptions = {
        position: cityPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
        addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    
    // load the update listeners
    LoadUpdateListeners();
    
    // show the current position
    ShowAddress(positions[currentLocation]);
    
    // create scrolling timer
    scrollTimer = window.setInterval(ScrollPanorama, 200);
    scrolling = true;
    locationTimer = window.setInterval(ChangeBaseHomeLocation, 15000);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadUpdateListeners
// DESCRIPTION:		loads the listeners that waits for point of view updates
// REMARKS:			Supports Google Maps 3.0 
function LoadUpdateListeners() {
    // point of view change
    google.maps.event.addListener(panorama, 'pov_changed', function() {
        currentPanoramaHeading = panorama.getPov().heading;
        currentPanoramaPitch = panorama.getPov().pitch;
        currentPanoramaZoom = panorama.getPov().zoom;
    });
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadBaseAbout
// DESCRIPTION:		loads the about page for streetview tours
// REMARKS:			Supports Google Maps 3.0 
function LoadBaseAbout() {
    
    // load our street view panorama
    var cityPosition = new google.maps.LatLng(40.757333, -73.986);
    var panoramaOptions = {
        position: cityPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    
    // load the update listeners
    LoadUpdateListeners();
    
    // create scrolling timer
    scrollTimer = window.setInterval(ScrollPanorama, 200);
    scrolling = true;
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadBaseCities
// DESCRIPTION:		loads the various cities that Street View Tours supports
//                  along with markers for the city
// REMARKS:			Supports Google Maps 3.0 
function LoadBaseCities() {
    
    // initializes the map
    InitializeMap();
    
    // load the various supported cities into the map
    for (var i = 0; i < cities.length; i++) 
    {
        // get the current city
        var city = cities[i];
        SVTlocations[i] = new Object;
        
        // Create the marker image
        // Origins, anchor positions and coordinates of the marker
        // increase in the X direction to the right and in
        // the Y direction down.
        // This marker is 20 pixels wide by 32 pixels tall.
        // The origin for this image is 0,0.
        // The anchor for this image is the base of the flagpole at 0,32.
        var image = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin.png',
        new google.maps.Size(32, 32),
        new google.maps.Point(0, 0),
        new google.maps.Point(0, 32));

        // The shadow image is larger in the horizontal dimension
        // while the position and offset are the same as for the main image.
        // Shapes define the clickable region of the icon.
        // The type defines an HTML &lt;area&gt; element 'poly' which
        // traces out a polygon as a series of X,Y points. The final
        // coordinate closes the poly by connecting to the first
        // coordinate.
        var shadow = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin_shadow.png',
            new google.maps.Size(48, 32),
            new google.maps.Point(0, 0), 
            new google.maps.Point(0, 32));
        
        // Create the shape
        var shape = {
            coord: [1, 1, 1, 32, 18, 32, 18, 1],
            type: 'poly'
        };
        
        // Create the marker
        var latlng = new google.maps.LatLng(city[1], city[2]);
        var marker = new google.maps.Marker({
            position: latlng,
            visible: true,
            clickable: true,
            icon: image,
            shape: shape,
            title: city[0],
            map: map
        });
        
        // asociate the marker and information text
        SVTlocations[i].marker = marker;
        SVTlocations[i].html = city[3];
        
        // Create the infoWindow.
        SVTlocations[i].infoWindow = new google.maps.InfoWindow({
            content: SVTlocations[i].html
        });
        
        // Create the listener with a closure...
        SVTlocations[i].listener = CreateCityClosure(i, SVTlocations[i].marker);
    }
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		CreateCityClosure
// DESCRIPTION:		creates a closure for the city marker
// REMARKS:			Supports Google Maps 3.0 
function CreateCityClosure(i, marker) {
    var listener = google.maps.event.addListener(marker, 'mouseover', function() {
        OpenCityInfoWindow(i); 	// <-- this is the key to making it work
    });
    return listener;
}

////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		OpenCityInfoWindow
// DESCRIPTION:		Adds a close listener to a city marker
// REMARKS:			Supports Google Maps 3.0 
function OpenCityInfoWindow(i) {
    if (typeof (lastI) == 'number' && typeof (SVTlocations[lastI].infoWindow) == 'object') {
        SVTlocations[lastI].infoWindow.close();
    }
    lastI = i;
    SVTlocations[i].infoWindow.open(map, SVTlocations[i].marker);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadBaseHow
// DESCRIPTION:		loads the How page for streetview tours
// REMARKS:			Supports Google Maps 3.0 
function LoadBaseHow() {
    
    // load our street view panorama
    var cityPosition = new google.maps.LatLng(51.509343, -0.135972);
    var panoramaOptions = {
        position: cityPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    
    // load the listeners
    LoadUpdateListeners();
    
    // create scroller
    scrollTimer = window.setInterval(ScrollPanorama, 200);
    scrolling = true;
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddress
// DESCRIPTION:		loads a given address
// REMARKS:			Supports Google Maps 3.0 
function LoadPosition(lat, lng, name, mpZoom, svZoom, svHeading)
{
	// save settings
	mapAddressName = name;
	currentPanoramaZoom = svZoom;
	currentPanoramaHeading = svHeading;
	
	// load our map
	InitializeMap();
	map.setZoom(mpZoom);	
	AddMarker(lat, lng);
	
	// load our streetview panorama
    var currentPosition = new google.maps.LatLng(lat, lng);
    var panoramaOptions = {
        position: currentPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddress
// DESCRIPTION:		loads a given address
// REMARKS:			Supports Google Maps 3.0 
function LoadPosition(lat, lng, name, mpZoom, svZoom, svHeading, svPitch)
{
	// save settings
	mapAddressName = name;
	currentPanoramaZoom = svZoom;
	currentPanoramaHeading = svHeading;
	currentPanoramaPitch = svPitch;
	
	// load our map
	InitializeMap();
	map.setZoom(mpZoom);	
	AddMarker(lat, lng);
	
	// load our streetview panorama
    var currentPosition = new google.maps.LatLng(lat, lng);
    var panoramaOptions = {
        position: currentPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
}


/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddress
// DESCRIPTION:		loads a given address
// REMARKS:			Supports Google Maps 3.0 
function LoadAddress(address, scrollEnabled, yaw) {
    
    // create the geocoder object
    geocoder = new google.maps.Geocoder();
    
    // set the yaw
    currentPanoramaHeading = yaw;
    
    // load our streetview panorama
    var currentPosition = new google.maps.LatLng(51.509343, -0.135972);
    var panoramaOptions = {
        position: currentPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    
    // call showaddress
    ShowAddress(address);

    // create scroller, if necessary
    if (scrollEnabled == true) {
        scrollTimer = window.setInterval(ScrollPanorama, 200);
        scrolling = true;
    }
    
    // load the listeners
    LoadUpdateListeners();
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadMap
// DESCRIPTION:		loads a given map
// REMARKS:			Supports Google Maps 3.0 
function LoadMap(mapAddress, mapAddressName)
{
	// load the map with no visible controls and 
    InitializeMap();
	// create the geocoder object
    geocoder = new google.maps.Geocoder();
    LoadLocationOnMap(mapAddress, mapAddressName);
	map.setZoom(mapZoom);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddressAndMap
// DESCRIPTION:		loads a given address
// REMARKS:			Supports Google Maps 3.0 
function LoadAddressAndMap(streetViewAddress, scrollEnabled, yaw, mapAddress, mapAddressName) {
    
    // load the address
    LoadAddress(streetViewAddress, scrollEnabled, yaw);
    
    // load the map with no visible controls and 
    InitializeMap();
    LoadLocationOnMap(mapAddress, mapAddressName);
	map.setZoom(mapZoom);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadAddressAndMapWithZoom
// DESCRIPTION:		loads a given address
// REMARKS:			Supports Google Maps 3.0 
function LoadAddressAndMapWithZoom(streetViewAddress, scrollEnabled, yaw, streetviewZoom, mapAddress, mapAddressName, mapZoomValue) {
    
    // set the current zoom for the map and panorama
    mapZoom = mapZoomValue;
    currentPanoramaZoom = streetviewZoom;
    
    // load the address
    LoadAddress(streetViewAddress, scrollEnabled, yaw);

    // load the map with no visible controls and 
    InitializeMap();
    LoadLocationOnMap(mapAddress, mapAddressName);
	map.setZoom(mapZoom);

    // set zoom  levels
    var pov = panorama.getPov();
    pov.zoom = currentPanoramaZoom;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadSearchableMap
// DESCRIPTION:		loads a searchable map, compllete with adsense code
// REMARKS:			Currently NOT Supported in 3.0 (googleBar) does not exist
function LoadSearchableMap(latitude, longitude, zoom) {
    var map;
    if (GBrowserIsCompatible()) {
        var mapOptions = {
            googleBarOptions: {
                style: "new",
                adsOptions: {
                    client: "pub-9232413282463697",
                    channel: "",
                    adsafe: "high",
                    language: "en"
                }
            }
        }
		map = new GMap2(document.getElementById("map_canvas"), mapOptions);
		map.setCenter(new GLatLng(latitude, longitude), zoom);
		map.setUIToDefault();
		map.enableGoogleBar();
    }
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ChangeBaseHomeLocation
// DESCRIPTION:		changes the location
// REMARKS:			Supports Google Maps 3.0 
function ChangeBaseHomeLocation() {
    // increment the location count
    currentLocation++;
    
    // update the location
    if (currentLocation >= 5) currentLocation = 0;
    ShowAddress(positions[currentLocation]);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ScrollPanorama
// DESCRIPTION:		spins us around
// REMARKS:			Supports Google Maps 3.0 
function ScrollPanorama() {
    currentPanoramaHeading += 2;
    var pov = panorama.getPov();
    pov.heading = currentPanoramaHeading;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ScrollPanoramaRight
// DESCRIPTION:		spins us around - to the right
// REMARKS:			Supports Google Maps 3.0 
function ScrollPanoramaRight() {
    currentPanoramaHeading += 2;
    var pov = panorama.getPov();
    pov.heading = currentPanoramaHeading;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ScrollPanoramaLeft
// DESCRIPTION:		spins us around - to the left
// REMARKS:			Supports Google Maps 3.0 
function ScrollPanoramaLeft() {
    currentPanoramaHeading -= 2;
    var pov = panorama.getPov();
    pov.heading = currentPanoramaHeading;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		StopScroll
// DESCRIPTION:		stops us from spinning
// REMARKS:			Supports Google Maps 3.0 
function StopScroll() {
    if (scrolling == true) {
        window.clearInterval(scrollTimer);
        scrolling = false;
    }
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		StartScroll
// DESCRIPTION:		starts the spinning
// REMARKS:			Supports Google Maps 3.0 
function StartScroll() {
    if (scrolling == false) {
        scrollTimer = window.setInterval(ScrollPanorama, 200);
        scrolling = true;
    }
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		StartScroll
// DESCRIPTION:		starts the spinning - left
// REMARKS:			Supports Google Maps 3.0 
function StartScrollLeft() {
    if (scrolling == true) {
        StopScroll();
    }
    if (scrolling == false) {
        scrollTimer = window.setInterval(ScrollPanoramaLeft, 200);
        scrolling = true;
    }
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		StartScroll
// DESCRIPTION:		starts the spinning - right
// REMARKS:			Supports Google Maps 3.0 
function StartScrollRight() {
    if (scrolling == true) {
        StopScroll();
    }
    if (scrolling == false) {
        scrollTimer = window.setInterval(ScrollPanoramaRight, 200);
        scrolling = true;
    }
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ZoomIn
// DESCRIPTION:		zooms in
// REMARKS:			Supports Google Maps 3.0 
function ZoomIn() {
    if (currentPanoramaZoom < 5) {
        currentPanoramaZoom++;
    }
    var pov = panorama.getPov();
    pov.zoom = currentPanoramaZoom;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ZoomIn
// DESCRIPTION:		zooms for the best fit
// REMARKS:			Supports Google Maps 3.0 
function ZoomBestFit() {
    currentPanoramaZoom = 1;
    var pov = panorama.getPov();
    pov.zoom = currentPanoramaZoom;
    panorama.setPov(pov);
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ZoomOut
// DESCRIPTION:		zooms Out
// REMARKS:			Supports Google Maps 3.0 
function ZoomOut() {
    if (currentPanoramaZoom > 0) {
        currentPanoramaZoom--;
    }
    var pov = panorama.getPov();
    pov.zoom = currentPanoramaZoom;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		PitchUp
// DESCRIPTION:		pitches Up
// REMARKS:			Supports Google Maps 3.0 
function PitchUp() {
    if (currentPanoramaPitch >= -90) {
        currentPanoramaPitch += 10;
    }
    var pov = panorama.getPov();
    pov.pitch = currentPanoramaPitch;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		PitchDown
// DESCRIPTION:		pitches Down
// REMARKS:			Supports Google Maps 3.0 
function PitchDown() {
	if (currentPanoramaPitch < 90) {
        currentPanoramaPitch -= 10;
    }
    var pov = panorama.getPov();
    pov.pitch = currentPanoramaPitch;
    panorama.setPov(pov);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ShowPosition
// DESCRIPTION:		shows the given Position
// REMARKS:			Supports Google Maps 3.0 
function ShowPosition(latitude, longitude) {
    panorama.setPosition(new google.maps.LatLng(latitude, longitude));
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ShowAddress
// DESCRIPTION:		shows the given address
// REMARKS:		    Supports Google Maps 3.0
function ShowAddress(address) {
    if (geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                panorama.setPosition(results[0].geometry.location);
            } else {
                alert("Failed to load address: " + address);
            }
        });
    }
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadMapWithZoom
// DESCRIPTION:		loads a map with a zoomp level
// REMARKS:         Supports Google Maps 3.0
function LoadMapWithZoom(mapLat, mapLong, mapZoom) {
    // load the map
    InitializeMap();

    var currentPosition = new google.maps.LatLng(mapLat, mapLong);
    
	// create the marker, add the marker to the map, and center around the marker
	// Create the marker image
        // Origins, anchor positions and coordinates of the marker
        // increase in the X direction to the right and in
        // the Y direction down.
        // This marker is 20 pixels wide by 32 pixels tall.
        // The origin for this image is 0,0.
        // The anchor for this image is the base of the flagpole at 0,32.
        var image = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin.png',
        new google.maps.Size(32, 32),
        new google.maps.Point(0, 0),
        new google.maps.Point(0, 32));

        // The shadow image is larger in the horizontal dimension
        // while the position and offset are the same as for the main image.
        // Shapes define the clickable region of the icon.
        // The type defines an HTML &lt;area&gt; element 'poly' which
        // traces out a polygon as a series of X,Y points. The final
        // coordinate closes the poly by connecting to the first
        // coordinate.
        var shadow = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin_shadow.png',
            new google.maps.Size(48, 32),
            new google.maps.Point(0, 0), 
            new google.maps.Point(0, 32));
        
        // Create the shape
        var shape = {
            coord: [1, 1, 1, 32, 18, 32, 18, 1],
            type: 'poly'
        };
    marker = new google.maps.Marker({
        position: currentPosition,
        title: "Current Position",
		icon: image,
        shape: shape
    });

    marker.setMap(map);
    map.setCenter(currentPosition);
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:			LoadMapAndAssociatedStreetView
// DESCRIPTION:		loads a map along with a corresponding street view panorama
// REMARKS:
function LoadMapAndAssociatedStreetView() {
    var currentPosition = new google.maps.LatLng(42.345573, -71.098326);
    var mapOptions = {
        center: currentPosition,
        zoom: mapZoom,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: true
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var panoramaOptions = {
        position: currentPosition,
        pov: {
            heading: currentPanoramaHeading,
            pitch: currentPanoramaPitch,
            zoom: currentPanoramaZoom
        },
		addressControl: false
    };
    var panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    map.setStreetView(panorama);
	
	// load the update listeners
    LoadUpdateListeners();
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadStreetViewer
// DESCRIPTION:		Loads the street viewer
// REMARKS:			Supports Google Maps 3.0
function LoadStreetViewer(currentAddress, currentHeading, useLat, defaultLatPosition, defaultLongPosition){

	mapAddressName = currentAddress;
// set the position

    var currentCenter = new google.maps.LatLng(defaultLatPosition,defaultLongPosition);
    var mapOptions = {
        center: currentCenter,
        zoom: 17 ,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: true
    };
    map = new google.maps.Map(document.getElementById("mapDiv"), mapOptions);
	
    var panoramaOptions = {
        position: currentCenter,
        pov: {
            heading: currentHeading,
            pitch: 0,
            zoom: 1
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    map.setStreetView(panorama);

	// add words to panorama
	tourDescription = document.createElement("div");
    tourDescription.setAttribute("id", "virtualTourDescription");
	tourDescription.innerHTML = 'You are looking at the default position';
	panorama.controls[google.maps.ControlPosition.BOTTOM].push(tourDescription); 
	
	// load the update listeners
    LoadUpdateListeners();
	
	// position change
    google.maps.event.addListener(panorama, 'links_changed', function() {
        var links = panorama.getLinks();
        var currentLocation = links[0].description;
        if (mapAddressName) {
            tourDescription.innerHTML = tourDescription.innerHTML = 'You are looking at ' + currentLocation + "<br />(You searched for " + mapAddressName + ")";
        }
        else {
            tourDescription.innerHTML = tourDescription.innerHTML = 'You are looking at ' + currentLocation + "<br />(No address has been searched yet.)";
        }

    });
	
	if(!useLat)
	{
		// create the geocoder
		if (geocoder == null) { geocoder = new google.maps.Geocoder(); }
		
		var nearestPanoLatLng = null;
		var geoCodeLatLng

		if (geocoder) {
			geocoder.geocode({ 'address': currentAddress }, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					geoCodeLatLng = results[0].geometry.location;
					
					var client = new google.maps.StreetViewService();
					
					client.getPanoramaByLocation(geoCodeLatLng, 50, function(result2, status2) {
					  if (status2 == google.maps.StreetViewStatus.OK) {
					  
						currentCenter = results[0].geometry.location;//result2.location.latLng;
						tourDescription.innerHTML = 'You are looking at ' + mapAddressName + "<br />(You searched for " + mapAddressName + ")";
						// set up our center here
						panorama.setPosition(currentCenter);
						map.setCenter(currentCenter);
					  }
					  else
					  {
						var defaultCenter = new google.maps.LatLng(defaultLatPosition, defaultLongPosition);
						panorama.setPosition(defaultCenter);
						map.setCenter(defaultCenter);
						tourDescription.innerHTML = 'You are looking at the default position<br />';
						alert("Failed to find a Street View image near " + currentAddress);
					  }

					});
					
				} else {
					var defaultCenter = new google.maps.LatLng(defaultLatPosition, defaultLongPosition);
					panorama.setPosition(defaultCenter);
					map.setCenter(defaultCenter);
					tourDescription.innerHTML = 'You are looking at the default position<br />';
					alert("Failed to load address: " + mapAddressName);
				}
			});
		}
	}
	

}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadVirtualCityTour
// DESCRIPTION:		Loads the demo for the Virtual City Tour
// REMARKS:			Supports Google Maps 3.0
function LoadVirtualCityTour(latPosition, longPosition) {

    // set the position
    var currentCenter = new google.maps.LatLng(latPosition, longPosition);

    var mapOptions = {
        center: currentCenter,
        zoom: 17,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: true
    };
    map = new google.maps.Map(document.getElementById("mapDiv"), mapOptions);
    var panoramaOptions = {
        position: currentCenter,
        pov: {
            heading: 0,
            pitch: 0,
            zoom: 1
        },
		addressControl: false
    };
    panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    map.setStreetView(panorama);
	
	// add words to panorama
	tourDescription = document.createElement("div");
    tourDescription.setAttribute("id", "virtualTourDescription");
	tourDescription.innerHTML = 'You are looking at the default position<br />(Times Square, New York)';
	panorama.controls[google.maps.ControlPosition.BOTTOM].push(tourDescription); 
	
	// load the update listeners
    LoadUpdateListeners();
	
	// position change
    google.maps.event.addListener(panorama, 'links_changed', function() {
        var links = panorama.getLinks();
        var currentLocation = links[0].description;
        if (mapAddressName) {
            tourDescription.innerHTML = tourDescription.innerHTML = 'You are looking at ' + currentLocation + "<br />(You searched for " + mapAddressName + ")";
        }
        else {
            tourDescription.innerHTML = tourDescription.innerHTML = 'You are looking at ' + currentLocation + "<br />(No address has been searched yet.)";
        }

    });

}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ShowVirtualCitySearchAddress
// DESCRIPTION:		shows the provided address
// REMARKS:			Supports Google Maps 3.0
function ShowVirtualCitySearchAddress(address) {

	// create the geocoder
    if (geocoder == null) { geocoder = new google.maps.Geocoder(); }
    mapAddressName = address;
    
	var nearestPanoLatLng = null;
	var geoCodeLatLng

    if (geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                geoCodeLatLng = results[0].geometry.location;
				
				var client = new google.maps.StreetViewService();
				
				client.getPanoramaByLocation(geoCodeLatLng, 50, function(result2, status2) {
				  if (status2 == google.maps.StreetViewStatus.OK) {
				  
					currentCenter = results[0].geometry.location;//result2.location.latLng;
					tourDescription.innerHTML = 'You are looking at ' + mapAddressName + "<br />(You searched for " + mapAddressName + ")";
					// set up our center here
					panorama.setPosition(currentCenter);
					map.setCenter(currentCenter);
				  }
				  else
				  {
					var defaultCenter = new google.maps.LatLng(40.759011, -73.9844722);
					panorama.setPosition(defaultCenter);
					map.setCenter(defaultCenter);
					tourDescription.innerHTML = 'You are looking at the default position<br />(Times Square, New York)';
					alert("Failed to find a Street View image near " + address);
				  }

				});
                
            } else {
				var defaultCenter = new google.maps.LatLng(40.759011, -73.9844722);
				panorama.setPosition(defaultCenter);
				map.setCenter(defaultCenter);
				tourDescription.innerHTML = 'You are looking at the default position<br />(Times Square, New York)';
				alert("Failed to load address: " + mapAddressName);
            }
        });
    }

}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadVirtualCitySearch
// DESCRIPTION:		shows the provided address
// REMARKS:			Supports Google Maps 3.0
function LoadVirtualCitySearch(address) {

    // create the geocoder
    geocoder = new google.maps.Geocoder();

    if (geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                currentCenter = results[0].geometry.location;
                LoadVirtualCityTour(currentCenter);
            } else {
                currentCenter = new google.maps.LatLng(40.759011, -73.9844722);
                LoadVirtualCityTour(currentCenter);
                alert("Failed to load address: " + address);
            }
        });
    }
}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		ToggleStreetView
// DESCRIPTION:		toggles the streetview between visible and invisible
// REMARKS:			Supports Google Maps 3.0
function ToggleStreetView() {

    var toggle = panorama.getVisible();

    if (toggle == false) {
        panorama.setVisible(true);

    } else {
        panorama.setVisible(false);
    }

}

/////////////////////////////////////////////////////////////////////////////////
// FUNCTION:		LoadMapAndStreetViewOverlay
// DESCRIPTION:		loads a map with a streetview overlay
// REMARKS:			Supports Google Maps 3.0
function LoadMapAndStreetViewOverlay(latitude, longitude, zoom, names, latis, longis, images, urls) {

    // Set up the map
    var currentPosition = new google.maps.LatLng(latitude, longitude);
    var mapOptions = {
        center: currentPosition,
        zoom: zoom,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: false
    };
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    // We get the map's default panorama and set up some defaults.
    panorama = map.getStreetView();
    panorama.setPosition(currentPosition);
    panorama.setPov({
        heading: 0,
        zoom: 1,
        pitch: 0
    }
    );

    for (i = 0; i < names.length; i++) {

        // get the current attraction
        var attractionName = names[i];
        var latitude = latis[i];
        var longitude = longis[i];
        var attractionURL = urls[i];
		var attImage = images[i];

        SVTlocations[i] = new Object;

        // Create the marker image
        // Origins, anchor positions and coordinates of the marker
        // increase in the X direction to the right and in
        // the Y direction down.
        // This marker is 20 pixels wide by 32 pixels tall.
        // The origin for this image is 0,0.
        // The anchor for this image is the base of the flagpole at 0,32.
        var image = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin.png',
        new google.maps.Size(32, 32),
        new google.maps.Point(0, 0),
        new google.maps.Point(0, 32));

        // The shadow image is larger in the horizontal dimension
        // while the position and offset are the same as for the main image.
        // Shapes define the clickable region of the icon.
        // The type defines an HTML &lt;area&gt; element 'poly' which
        // traces out a polygon as a series of X,Y points. The final
        // coordinate closes the poly by connecting to the first
        // coordinate.
        var shadow = new google.maps.MarkerImage('http://streetviewtours.com/images/pushpin_shadow.png',
            new google.maps.Size(48, 32),
            new google.maps.Point(0, 0),
            new google.maps.Point(0, 32));

        // Create the shape
        var shape = {
            coord: [1, 1, 1, 32, 18, 32, 18, 1],
            type: 'poly'
        };

        // Create the marker
        var latlng = new google.maps.LatLng(latitude, longitude);

        var marker = new google.maps.Marker({
            position: latlng,
            visible: true,
            clickable: true,
            icon: image,
            shape: shape,
            title: attractionName,
            map: map
        });

        // asociate the marker and information text
        SVTlocations[i].marker = marker;
        SVTlocations[i].html = "<a href='" + attractionURL + "'>" + attractionName + "</a><br />" + "<a href='" + attractionURL + "'>" + attImage + "</a>";

        // Create the infoWindow.
        SVTlocations[i].infoWindow = new google.maps.InfoWindow({
            content: SVTlocations[i].html
        });

        // Create the listener with a closure...
        SVTlocations[i].listener = CreateCityClosure(i, SVTlocations[i].marker);
    }
}
