/**
 * HyperCities Save Snapshot Control.
 * @author David Shepard
 * @copyright (c) 2009, by HyperCities Tech Team
 * @date      2009-07-15
 * @version   0.1
 * @description This control removes all maps and all objects from the screen, then resets the timeslider back to 1700-current year.
 *
 */

var GSaveSnapshotControl = function () {
    
}

GSaveSnapshotControl.prototype = new GControl();

GSaveSnapshotControl.prototype.initialize = function (map) {
	//var container = this.getContainer();
	var container = document.createElement("div");
	//this.setButtonStyle_(container);
        container.id = "saveMapButton";
	//container.append(document.createTextNode("Reset Map"));
        var btnImage = document.createElement("img");
        btnImage.src = "images/camera.gif";
        btnImage.alt = "Save Snapshot - Save all collections and maps.";
        btnImage.title = "Save Snapshot - Save all collections and maps.";
        container.appendChild(btnImage);
	GEvent.addDomListener(container, "click", function () {
            HyperCities.session.saveSnapshot();
	});
	map.getContainer().appendChild(container);

	return container;
}

GSaveSnapshotControl.prototype.getDefaultPosition = function() {
	//HyperCities.debug("getDefaultPosition called.");
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(160, 5));
}

function LoadSnapshotControl () {
	
}
LoadSnapshotControl.prototype = new GControl();

LoadSnapshotControl.prototype.initialize = function (map) {
	var container = document.createElement("div");
	container.id = "loadMapButton";
	var btnImage = document.createElement("img");
	// finish style info
	btnImage.alt = "Load saved snapshot";
	container.appendChild(btnImage);
	GEvent.addDomListener(container, "click", function () {
            // The following two closures handle selecting a file from the remote
            // server and the user's own computer, respectively
            var __loadFromServer = function () {
                // get all files associated with user
                // display selection box
                // on clicking OK, return the file
            };
            var __loadFromClient = function () {
                // handled as normal file upload
            };
            // Show dialog box: select file to upload, or choose one from
            // your own computer.
            // The form is an <input type="file" name="local">
            // If the file field is filled, warn if someone tries to click on the other button/
            // Have a "source" attribute or variable set
            var idFunctionMaps = {'server':__loadFromServer, 'client':__loadFromClient};
            idFunctionMaps[selectionReturnVariable]();
            HyperCities.session.loadSnapshot();
	});
}

ClearMapControl.prototype.setButtonStyle_ = function (button) {
	button.style.textDecoration = "underline";
	button.style.color = "#0000cc";
	button.style.backgroundColor = "white";
	button.style.font = "small Arial";
	button.style.border = "1px solid black";
	button.style.padding = "2px";
	button.style.marginBottom = "3px";
	button.style.textAlign = "center";
	button.style.width = "6em";
	button.style.cursor = "pointer";
}