google.load("earth", "1");
var ridingId = 0;
var ge = null;
var currentContribFile = "contrib40.kmz";
function init() {
    google.earth.createInstance('map3d', initCB, failureCB);
}
function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);

    /* Set options */
    var options = ge.getOptions();  
    options.setStatusBarVisibility(1);
    options.setGridVisibility(0);
    options.setOverviewMapVisibility(0);
    options.setScaleLegendVisibility(1);
    options.setAtmosphereVisibility(1);
    options.setMouseNavigationEnabled(1);

    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);

    /* Set kml/kmz file */
    href = "http://earth.smurfmatic.net/canada2008/contributions/" + currentContribFile;
    google.earth.fetchKml(ge, href, function(kmlObject) {
	if (kmlObject) {
	    if ('getFeatures' in kmlObject) {
		kmlObject.getFeatures().appendChild(kmlObject);
	    }
	    //alert(kmlObject.getAbstractView());
	    ge.getFeatures().appendChild(kmlObject);
	    if (kmlObject.getAbstractView()) {
		ge.getView().setAbstractView(kmlObject.getAbstractView());
	    } else {
		var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		lookAt.setLatitude(56);
		lookAt.setLongitude(-98);
		lookAt.setRange(5000000);
		ge.getView().setAbstractView(lookAt);
	    }
	}
    });
}
function failureCB(errorCode) {
    //alert(errorCode);
}

