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

var _vimeo = [], _vimeoi = 0;


// this is the function the youtube player 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 onVimeoReady( id ) {
  _vimeoi++;
  _vimeo[ _vimeoi ] = new _vimeoo( id, _vimeoi );
}


function _vimeoo( id, i ) {
  
  if( !id || !i ) return;
  
  this.id = id;
  this.o = document.getElementById( this.id );
  if( !this.o ) return;
  
  this.o.api_addEventListener("onPlay",   "_vimeo["+i+"].videoLog('play')");
  this.o.api_addEventListener("onPause",  "_vimeo["+i+"].videoLog('pause')");
  this.o.api_addEventListener("onSeek",   "_vimeo["+i+"].videoLog('seek')");
  this.o.api_addEventListener("onFinish", "_vimeo["+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+"', _vimeo["+i+"].videoTime(), _vimeo["+i+"].videoURL(), _vimeo["+i+"].videoTitle());", ( action=="seek" ? 200 : 1 ));
  }
  
  this.videoTime = function() {
    return Math.round( this.o.api_getCurrentTime() );
  }
  
  this.videoURL = function() {
    // we have to log a URL, but vimeo's API does not give it to us, so we request that user's specify the video ID in an external var
    // if they don't do that, then we'll just return the vimeo base URL.
    return "http://vimeo.com/" + this.videoMeta('id');
  }
  
  this.videoTitle = function() {
    return this.videoMeta('title');
  }
  
  this.videoMeta = function( x ) {
    if( window._vimeometa && _vimeometa[ this.id ] && _vimeometa[ this.id ][ x ] ) return _vimeometa[ this.id ][ x ];
    return '';
  }
}





