/******************************************************

  flash storage -- local computer up to 100K storage

  early prototype stage

  (c) 2005 Pixel-Apes.

 ******************************************************/



var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function FlashStorage( storage, bindId )
{
  this.storage = storage;
  this.fake = true;
  this.bindId = bindId;
  FlashStorage.bindings[ this.bindId ] = this;

  this.testFlash = function()
  {
    var s = document.getElementById(FlashStorage.containerId);
    if (!s) return false;
    try { if (!s.SetVariable) return false; } catch(e) { };
    return true;
  }

  this._noFlash = -1;
  this.noFlash = function()
  {
    if (this._noFlash === -1) this._noFlash = !this.testFlash();
    return this._noFlash; 
  }
  this.noFlashContent = { "what" : "??Attention!?? Your changes will be lost if you will not log in \n(because you have no Flash installed)", "tag" : "" };



  this.reset = function()
  { 
    if (this.noFlash()) return;
    var s = document.getElementById(FlashStorage.containerId);
    s.GotoFrame( 4 );
    s.Play();
  }
  this.store = function( what, tag )
  {
    if (this.fake) return;
    
    if (this.noFlash()) 
    { 
      this.noFlashContent = { "what" : what, "tag" : tag };
      return;
    }

    var s = document.getElementById(FlashStorage.containerId);
    s.SetVariable( "store_value", escape(what) );
    s.SetVariable( "storage_id",  this.bindId+(tag!==""?","+tag:"") );
    s.GotoFrame( 14 );
    s.Play();
  }
  this.restore = function( tag )
  {
    this.fake = false;

    if (this.noFlash())
    {
      var fs = FlashStorage.bindings[ this.bindId ];
      fs.storage.onFlashRestoreComplete( this.noFlashContent.what, this.noFlashContent.tag );
      return;
    }

    var s = document.getElementById(FlashStorage.containerId);
    s.SetVariable( "storage_id",  this.bindId+(tag!==""?","+tag:"") );
    s.GotoFrame( 24 );
    s.Play();
  }
}
FlashStorage.bindings = [];
FlashStorage.containerId = "FlashStorageContainer";

// Handle all the FSCommand messages in a Flash movie.
function FlashStorageContainer_DoFSCommand(command, args) {
  var s = document.getElementById(FlashStorage.containerId);
  if (command == "restore") 
  {
     // TEMP
     if (args != "undefined") 
     {
       args = unescape( args );
       var m = args.match( /^(.*)\|/ );
       var id = m[1];
       var content = args.substr( m[0].length );
       var tag = "";

       var m = id.match( /^(.*),(.*)$/ );
       if (m != null)
       {
         id  = m[1];
         tag = m[2];
       }

       var fs = FlashStorage.bindings[ id ];
       fs.storage.onFlashRestoreComplete( content, tag );
     }

  }
  s.GotoFrame( 39 );
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  document.write('<script language=\"VBScript\"\>\n');
  document.write('On Error Resume Next\n');
  document.write('Sub FlashStorageContainer_FSCommand(ByVal command, ByVal args)\n');
  document.write('  Call FlashStorageContainer_DoFSCommand(command, args)\n');
  document.write('End Sub\n');
  document.write('</script\>\n');
}

