function controlador() {
    desplazamiento(x_1, y_1, 1, estado_1);
    desplazamiento(x_2, y_2, 2, estado_2);
    desplazamiento(x_3, y_3, 3, estado_3);
    desplazamiento(x_4, y_4, 4, estado_4);
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}



function finAudio() {
    tramo++;
    if (tramo == 5) {
            var flashMovie = getFlashMovieObject("myFlash");
            flashMovie.callJavaScript("d", "");
    }
}






function desplazamiento(destinoX, destinoY, token, estado) {
    var x;
    var y;
    if (token == tramo) {
        //Hacemos movimiento
        x = parseInt (document.getElementById("avatar").style.left);
        y = parseInt (document.getElementById("avatar").style.top);
        if (x == destinoX && y == destinoY) {
            //Este movimiento ya ha finalizado. Ya no invocamos mas la funcion
            var flashMovie = getFlashMovieObject("myFlash");
            var audio = "index/" + token + ".mp3";
            flashMovie.callJavaScript(estado, audio);
        } else {
            //Nos estamos moviendo
            if (x < destinoX) {
                document.getElementById("avatar").style.left = x + 2;
            } else if (x > destinoX) {
                document.getElementById("avatar").style.left = x - 2;
            } else {
                document.getElementById("avatar").style.left = x;
            }
            if (y < destinoY) {
                document.getElementById("avatar").style.top = y + 2;
                autoScrollDown();
            } else if (y > destinoY) {
                document.getElementById("avatar").style.top = y - 2;                         
                autoScrollUp();
            } else {
                document.getElementById("avatar").style.top = y;
            }
            setTimeout("desplazamiento(" + destinoX + ", " + destinoY + ", " + token + ", \"" + estado + "\")",5);
        }
    } else {
        //No hacemos nada
        setTimeout("desplazamiento(" + destinoX + ", " + destinoY + ", " + token + ", \"" + estado + "\")",5);
    }
    return true
}




function autoScrollDown() {
    if (navigator.appVersion > "3") {
        posY = parseInt (document.getElementById("avatar").style.top);
        if (posY > medioY) {
            window.scrollBy(0,2);
        }
        return true;
    }
}

function autoScrollUp() {
    if (navigator.appVersion > "3") {
        posY = parseInt (document.getElementById("avatar").style.top);
        if (posY > medioY) {
            window.scrollBy(0,-2);
        }
        return true;
    }
}





function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

