var currentPosition;
var currentVolume;
var currentItem;
var currentState;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) {
  thisMovie("fpl").sendEvent(typ, prm);
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
   }
   else {
     return document[movieName];
   }
};

function openPlay(x, scrubbing) {
  if((currentState == 0) && (!scrubbing)) {
    sendEvent('playpause');
    sendEvent('playpause');
    setTimeout("sendEvent('scrub', " + x + ")", 25);
  }
  else if(currentState == 2) {
    sendEvent('scrub', x);
  }

  if((currentState == 0) || (currentState == 1)) {
	// found desired position 
    if(((currentPosition > (x - 2)) && (currentPosition < (x + 2))) && (scrubbing)) {
      scrubbing = false;
      sendEvent('playpause');
    }
	// keep scrubbing until the scrub point is downloaded
    else if(((currentPosition < (x - 2)) || (currentPosition > (x + 2))) && (scrubbing))  {
      sendEvent('scrub', x);
      scrubbing = true;
      setTimeout("openPlay(" + x + ", " + scrubbing + ")", 500);
    }
	// one time to get the loop started, since we're scrubbing, come back in 1 second to check on the position, then we fall into one of the two positions above: play or scrub some more
    else {
      scrubbing = true;
      setTimeout("openPlay(" + x + ", " + scrubbing + ")", 500);
    }
  }
};
