var ge;
var placemarks = [
    //{label: 'Enterprise Rent-A-Car', content: "", lat: 33.8002, lon: -117.918448},
    //{label: 'MIX Restaurant and Lounge', content: "<strong>Mix Restaurant & Lounge</strong><br/>777 West Convention Way, Anaheim, CA<br/>(714) 740-4412<br/><br/>Mix Restaurant features an extensive variety of imaginative dishes created from some of the finest organic and natural ingredients available in the region", lat: 33.799994, lon: -117.918},
    //{label: 'Hilton Hotel', content: "<strong>Hilton Anaheim</strong><br/>777 West Convention Way<br/>Anaheim, CA 92802<br/>(714) 750-4321<br/><br/>The <strong>Hilton Anaheim</strong> hotel is located in the heart of California's famous <strong>Orange County</strong>, adjacent to the <strong>Anaheim Convention Center</strong> and steps from the <em><strong>Disneyland&reg; Resort</strong></em>. Hilton Anaheim offers over 100,000 square feet of meeting and event function space and the finest hotel rooms in Anaheim.", lat: 33.7999, lon: -117.919400}
];

//Note:
/*
    Latitude: Smaller number will move left, larger will move right
    Longitude: 
    zoom: smaller - zoom in, larger - zoom out
	Use google earth to help coordinate the finding process
*/

var geProperties = [];
geProperties['stregis_princeville'] = {lat: 22.219929, lon: -159.497305, rotation: 70, altitude: 70, zoom: 250, 
    markers: [
        {label: 'The St. Regis Princeville Resort', content: "St. Regis Princeville", lat: 22.219929, lon: -159.497305}
    ]
};

geProperties['westin_princeville'] = {lat: 22.221587, lon: -159.468635, rotation: 90, altitude: 70, zoom: 180, 
    markers: [
        {label: 'The Westin Princeville Ocean Resort Villas', content: "Westin Princeville", lat: 20.9199, lon: -156.694844}
    ]
};


geProperties['sheraton_waikiki'] = {lat: 21.278097662826024, lon: -157.82958, rotation: 10, altitude: 70, zoom: 450, 
    markers: [
        {label: 'Sheraton Waikiki', content: "Sheraton Waikiki", lat: 21.278097662826024, lon: -157.82958}
    ]
};


geProperties['moana_surfrider'] = {lat: 21.27657804234913, lon: -157.8264355659485, rotation: 40, altitude: 70, zoom: 250, 
    markers: [
        {label: 'Moana Surfrider', content: "Moana Surfrider", lat: 21.27657804234913, lon: -157.8264355659485}
    ]
};

geProperties['princess_kaiulani'] = {lat: 21.277287, lon: -157.826093, rotation: 40, altitude: 60, zoom: 180, 
    markers: [
        {label: 'Sheraton Princess  Kaiulani', content: "Sheraton Princess  Kaiulani", lat: 21.277287, lon: -157.826093}
    ]
};

geProperties['sheraton_maui'] = {lat: 20.92691078867837, lon: -156.69521927833557, rotation: 40, altitude: 70, zoom: 200, 
    markers: [
        {label: 'Sheraton Maui', content: "Sheraton Maui", lat: 20.92691078867837, lon: -156.69521927833557}
    ]
};


geProperties['westin_maui'] = {lat: 20.920019, lon: -156.695491, rotation: 90, altitude: 70, zoom: 180, 
    markers: [
        {label: 'Westin Maui', content: "Westin Maui", lat:  20.919854, lon: -156.695514}
    ]
};

geProperties['westin_kaanapali'] = {lat: 20.937778, lon: -156.691668, rotation: 90, altitude: 70, zoom: 220, 
    markers: [
        {label: 'Westin Kaanapali', content: "Westin Kaanapali", lat:  20.937778, lon: -156.691668}
    ]
};


geProperties['sheraton_kauai'] = {lat: 21.876623, lon: -159.462015, rotation: 0, altitude: 70, zoom: 250, 
    markers: [
        {label: 'Sheraton Kauai', content: "Sheraton Kauai", lat:  21.876623, lon: -159.462015}
    ]
};

geProperties['sheraton_keauhou'] = {lat: 19.558357, lon: -155.965405, rotation: 40, altitude: 70, zoom: 250, 
    markers: [
        {label: 'Sheraton Keauhou Bay', content: "Sheraton Keauhou Bay", lat:  19.558357, lon: -155.965405}
    ]
};

geProperties['royal_hawaiian'] = {lat: 21.277199, lon: -157.828799, rotation: 0, altitude: 70, zoom: 200, 
    markers: [
        {label: 'The Royal Hawaiian', content: "The Royal Hawaiian", lat:  21.277199, lon: -157.828799}
    ]
};





currGEProperty = "";
google.load("earth", "1");

function loadGE(property) {
    currGEProperty = property;
    if(!geProperties[currGEProperty])
        return;
    document.getElementById('map3d').innerHTML = '';
    google.earth.createInstance('map3d', initCallback, failureCallback);
}

function initCallback(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);

    // add a navigation control
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

    // add some layers
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

    //fly to Hilton Anaheim
    var la = ge.createLookAt('');
    
    var property = geProperties[currGEProperty];
    
    la.set(property.lat, property.lon, 18, ge.ALTITUDE_RELATIVE_TO_GROUND, property.rotation, property.altitude, property.zoom);
    ge.getView().setAbstractView(la);

    ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);


    for(var i = 0; i < property.markers.length; i++)
    {
    
        var obj = property.markers[i];
        createPlacemark(obj.label, obj.content, obj.lat, obj.lon);
    }
}

function failureCallback(errorCode) {
}



function createPlacemark(label, content, lat, lon) {
    var placemark = ge.createPlacemark('');
    placemark.setName(label);
    ge.getFeatures().appendChild(placemark);
    placemark.setDescription(content);


    // Create style map for placemark
    var icon = ge.createIcon('');
    icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
    var style = ge.createStyle('');
    style.getIconStyle().setIcon(icon);
    placemark.setStyleSelector(style);

    // Create point
    var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    var point = ge.createPoint('');
    point.setLatitude(lat);
    point.setLongitude(lon);
    placemark.setGeometry(point);
    
    google.earth.addEventListener(placemark, 'click', function(event) {
        // prevent the default balloon from popping up
        event.preventDefault();

        var balloon = ge.createHtmlStringBalloon('');
        balloon.setFeature(event.getTarget());
        balloon.setMaxWidth(300);
        balloon.setContentString(content);
        ge.setBalloon(balloon);
    });
}
