
// works the same as youtube/vimeo, see comments in that file.

var _jwplayer = [], _jwplayeri = 0;

// this is the function the jwplayer calls once it's loaded. 
// each time it's called, it creates a new object in the global array, and passes the array key into the class so the class can refer to itself externally
function onJWPlayerReady( id ) {
  _jwplayeri++;
  _jwplayer[ _jwplayeri ] = new _jwplayero( id, _jwplayeri );
}


function _jwplayero( id, i ) {
  
  if( !id || !i ) return;
  
  this.id = id;
  this.o = document.getElementById( this.id );
  if( !this.o ) return;

	jwplayer(this.id).onPlay(function(){_jwplayer[i].videoLog('play');});
	jwplayer(this.id).onPause(function(){_jwplayer[i].videoLog('pause');});
	jwplayer(this.id).onSeek(function(){_jwplayer[i].videoLog('seek');});
	jwplayer(this.id).onComplete(function(){_jwplayer[i].videoLog('end');});
  
  this.videoLog = function( action ) {
    // seeks happen too fast and register the time you are coming FROM, because after the click the movie hasn't actually changed time yet
    // so we use a timeout to delay seeks slightly, that fixes it
    if( window.videogoyes ) setTimeout( "videogoyes( '"+action+"', _jwplayer["+i+"].videoTime(), _jwplayer["+i+"].videoURL(), _jwplayer["+i+"].videoTitle());", ( action=="seek" ? 200 : 1 ));
  }
  
  this.videoTime = function() {
    return Math.round( jwplayer(this.id).getPosition() );
  }
  
  this.videoURL = function() {
		return jwplayer(this.id).config.file;
  }
	
  this.videoTitle = function() {
		return jwplayer(this.id).getPlaylistItem().title || "";
  }

}




