var localServer;
var STORE_NAME = "hello_world";
var MANIFEST_FILE = "manifest.json";
var store;

function textOut(s) {
  alert(s);
}

// Create the managed resource store
function createStore() {
  store = localServer.createManagedStore(STORE_NAME);
  store.manifestUrl = MANIFEST_FILE;
  store.checkForUpdate();

  var timerId = window.setInterval(
      function() {
        if (store.currentVersion) {
	  window.clearInterval(timerId);
	  textOut("The documents are now available offline. The version stored is: " + store.currentVersion);
	} else if (store.updateStatus == 3) {
	  textOut("Error: " + store.lastErrorMessage);
        }
      }, 500);
}


function init() {
  if (!window.google || !google.gears) {
    textOut("Note: You must install Gears first.");
  } else {
    localServer = google.gears.factory.create("beta.localserver");
    textOut("Yay, Google Gears is already installed.");
  }
}
