function is_human(){
  try{
    var location = new URL(new String(document.location));
    var path     = new String(location.getPath());    
    var host     = new String(location.getHost());
    var reference= new String(location.getReference());
    reference = reference.substring(1);    
    if(path!="/"){
      if(path.substring(0,1)=="/"){
        path=path.substring(1);
      }      
      if(reference==""){
        if(path==""){
          document.location.hash=path;
        }else{
          document.location="http://"+host+"/#"+path;
        }
      }else{
        defaultURL=reference.replace(/,/g,"/");
      }
    }
  }catch(e){
    alert("Error in is_human:"+e.message);
  }
}

onlyLoaded=true;
defaultURL="mainpage";

function urlUpdated(path){
  try{
    path=new String(path).replace(/,/g,"/");
    //alert("defaultURL:"+defaultURL+" path:"+path);
    if(defaultURL!=path&&onlyLoaded){
      transitLinkToFlash(defaultURL);
    }else{      
      onlyLoaded=false;
      defaultURL   = path;
      document.location.hash=defaultURL;
    }
  }catch(e){
    alert("Error in urlUpdated:"+e.message);
  }
}

function transitLinkToFlash(str) {
  try{
    str=new String(str).replace(/\//g,",");
    var mov = _getFlash("mbflash");
    mov.SetVariable ( "_level0.controller.jsToFlash", str )
  }catch(e){
    alert("Error in transitLinkToFlash:"+e.message);
  }
}


function flash2JS(){
  try{
    var arr = Array.prototype.slice.call(arguments, 0);
    var el  = document.getElementById('textfield');
    var str = '<b>flash2JS: ' + arr[0];  
    if ( arr[1] ) { str += ' -> ' + arr[1]; }
    if ( arr[2] ) { str += ' -> ' + arr[2]; }
    str += '</b>';
    //el.innerHTML = str;
    arr=new String(arr);arr=arr.substring(arr.indexOf("#"));//alert("Flash2Js:"+arr);
    urlUpdated(arr);
  }catch(e){
    alert("Error in flash2JS:"+e.message);
  }
}

function _getFlash(movieName) {
  try{
    if (window.document[movieName]) {return window.document[movieName];}else 
    if( document.embeds && document.embeds[movieName] ){return document.embeds[movieName];}else{return document.getElementById(movieName);}
  }catch(e){
    alert("Error in _getFlash:"+e.message);
  }
}


function setDefaultURL(path){
  try{
    path=new String(path).replace("/",/,/g);
    alert(path);
    urlUpdated(path);
  }catch(e){
    alert("Error in urlUpdated:"+e.message);
  }
}


