﻿  var player    =  null;
  var playlist  =  null; 
  var _lastTime=-1;//前一个duration
  var playPause=false;
  var _time = 0;
  var captionxml=null;//当前视频用的字幕
  var currentCaption = null;//当前的字幕段
  var totalduration = 0;
  function playerReady(obj)
  {
    player = gid(obj.id);
    addListeners();
  };
 
 
  function addListeners()
  {
    playlist = player.getPlaylist();
 
    if((playlist !== null) && (playlist.length > 0))
    {
      player.addModelListener('STATE', 'stateMonitor');
      player.addModelListener('TIME', 'timeMonitor');
    }
    else
    {
      setTimeout("addListeners();", 100);
    }
  };
 
 
  function stateMonitor(obj)
  {
    if(obj.newstate == 'COMPLETED')
    {  player.sendEvent("STOP");
     /*    
      if(currentDivContents != '')
      {
        gid(currentPlayerID + 'o').innerHTML = currentDivContents;
      }*/
    }
  };
 
  function timeMonitor(obj){
    totalduration = obj.duration;
     _time = obj.position;
  };
  function gid(name)
  {
    return document.getElementById(name);
  };

  var currentDivContents = '';
  var currentPlayerID    = '';
 
 
  function loadPlayer(videofile, imagefile, width, height, playerid,captionfile,logofile)
  {
    //...if a player is already loaded, remove the player and restore it's div contents
    if(currentDivContents != '')
    {
      swfobject.removeSWF('playerID');
      gid(currentPlayerID + 'o').innerHTML = currentDivContents;
    }
 
    //...save current div contents
    currentDivContents = eval(document.getElementById(playerid + 'o')).innerHTML;
 
    //...save current player id
    currentPlayerID = playerid;
    var flashvars =
    {
      'file':                     encodeURIComponent(videofile),
//      'streamer':                'rtmp://static.yalolo.com',
//      'type':                    'rtmp',
//      'image':                    encodeURIComponent(imagefile),
      'plugins':                 'captions-1,logomover-1',
      'id':                      'playerID',
      'captions.file':           'http://www.yalolo.com'+captionfile,
	  'skin':                    'http://www.longtailvideo.com/files/skins/modieus.swf',
	  'logo':                    encodeURIComponent(logofile),
	  'controlbar':              'over',
	  'abouttext':               'www.yalolo.com',
	  'aboutlink':               'http://www.yalolo.com',
      'autostart':               'true'
    };
 
    var params =
    {
      'wmode':                   'opaque',
      'allowscriptaccess':       'always',
      'allowfullscreen':         'true'
    };
 
    var attributes =
    {
      'id':                      'playerID',
      'name':                    'playerID'
    };
    swfobject.embedSWF('/flash/player-v4_6.swf', playerid, width, height, '9.0.124', false, flashvars, params, attributes);
  };