
// this effectively replaces fscommand, RBGISClient.swf will call this function like an event handler
function flashEvent(event, args) {
  // just to test that it works...
  /*if (event=="Map load") {
    alert(event + " : " + args);
  } else {
    window.status = event + " : " + args;
  }*/
  
  var p;
  
  if (event == "Map mousemove") {
    SetMapLatLon(args.split(",")[1], args.split(",")[0]);
  }
  else if (event == "Map load") {
    SetBBox(args);
	SetMapScale(args);
  }
  else if (event == "Map save") {
	PopupSave('savemap.aspx?' + args);
  }
  else if (event == "Map topography") {
    Topography(args);
  }
  else if (event == "Map placenames") {
    Placenames(args);
  }
  else if (event == "Map resize") {
    MapWidth = args.split(",")[0]
  }
  else if (event == "Map querybox") {
    //alert(args);
    //flashMovie('GISClient').PointFeature();

    try
    {
        clearTimeout(SetPointTimeout);
    }
    catch(err)
    {

    }
    
    PopupInfo('info.aspx?bbox=' + args);
  }
  else if (event == "Map query") {
    //alert(args);

    try
    {
        clearTimeout(SetPointTimeout);
    }
    catch(err)
    {

    }
    
    p = args.split("&")
    flashMovie('GISClient').PointFeature(parseFloat(p[0].substr(2)),parseFloat(p[1].substr(2)));
    
    if (p.length>2) {
        layer = p[2].substr(6);
        id = p[3].substr(3);
    }
    else
    {
        layer = "";
        id = "";
    }
    
    PopupInfo('info.aspx?x=' + p[0].substr(2) + '&y=' + p[1].substr(2) + '&mapwidth=' + MapWidth.toString() + '&layer=' + layer + '&id=' + id);
  }
  else if (event == "Symbol press") {
    try
    {
        clearTimeout(SetPointTimeout);
    }
    catch(err)
    {

    }
    
    p = args.split("&")
    flashMovie('GISClient').PointFeature(parseFloat(p[0].substr(2)),parseFloat(p[1].substr(2)))
    
    var layer = "";
    
    if (document.getElementById("ctl00_cphSideBar_chkNOAA"))
    {
        if (document.getElementById("ctl00_cphSideBar_chkNOAA").checked)
        {
            layer = document.getElementById("ctl00_cphSideBar_hdnWMS").value.substr(3);

            if (layer == "SST")
            {
                if (document.getElementById("ctl00_cphSideBar_rblNOAASSTMeanMax_1").checked)
                {
                    layer = "SSTMAX"
                }
                else
                {
                    layer = "SST2"
                }
            }
        }
    }
    
    PopupInfo('info.aspx?x=' + p[0].substr(2) + '&y=' + p[1].substr(2) + '&mapwidth=' + MapWidth.toString() + '&layer=' + layer + '&id=' + p[p.length-1].substr(4));
    //flashMovie('GISClient').Load();
  }
  else {
    //window.status = event + " : " + args
  }
}


// use this to access the flash movie so you can call it's external functions
function flashMovie(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
