fixxgears = {

	createStore : function() {
        if ( 'undefined' == typeof google || ! google.gears ) return;

		if ( 'undefined' == typeof localServer )
			localServer = google.gears.factory.create("beta.localserver");

        store = localServer.createManagedStore(this.storeName());
		store.manifestUrl = "/gears-manifest.jsp?ajax=true";
		store.checkForUpdate();
    },

	getPermission : function() {
		if ( 'undefined' != typeof google && google.gears ) {
			if ( ! google.gears.factory.hasPermission )
				google.gears.factory.getPermission( 'fixx','/styles/labtastic/images/logo.jpg',"Do you want to allow fixx to use Google Gears to speed up system performance? If you don't want fixx to use Google Gears, please select 'Never allow this site'" );
			try {
				this.createStore();
			} catch(e) {} // silence if canceled
		}
	},

	storeName : function() {
		var name = window.location.protocol + window.location.host;

		name = name.replace(/[\/\\:*"?<>|;,]+/g, '_'); // gears beta doesn't allow certain chars in the store name
		name = 'fixx_' + name.substring(0, 60); // max length of name is 64 chars
		return name;
	},

	I : function(id) {
		return document.getElementById(id);
	}
};

(function() {
  // We are already defined. Hooray!
  if (window.google && google.gears) {
    return;
  }

  var factory = null;

  // Firefox
  if (typeof GearsFactory != 'undefined') {
    factory = new GearsFactory();
  } else {
    // IE
    try {
      factory = new ActiveXObject('Gears.Factory');
      // privateSetGlobalObject is only required and supported on WinCE.
      if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
        factory.privateSetGlobalObject(this);
      }
    } catch (e) {
      // Safari
      if ((typeof navigator.mimeTypes != 'undefined')
           && navigator.mimeTypes["application/x-googlegears"]) {
        factory = document.createElement("object");
        factory.style.display = "none";
        factory.width = 0;
        factory.height = 0;
        factory.type = "application/x-googlegears";
        document.documentElement.appendChild(factory);
      }
    }
  }

  // *Do not* define any objects if Gears is not installed. This mimics the
  // behavior of Gears defining the objects in the future.
  if (!factory) {
    return;
  }

  // Now set up the objects, being careful not to overwrite anything.
  //
  // Note: In Internet Explorer for Windows Mobile, you can't add properties to
  // the window object. However, global objects are automatically added as
  // properties of the window object in all browsers.
  if (!window.google) {
    google = {};
  }

  if (!google.gears) {
    google.gears = {factory: factory};
  }

    fixxgears.getPermission();
})();
