var playstate = 0;


function button0OnClick()
{
  if(playstate == 0)
  {
    if(!playerRemote.play)
      return;
    
    playstate = 1;
    btplaypause.comb3in1ImgSrc = "button-pause.png";
    btplaypause.tooltip = '暂停'; 
  }
  else
  {
    if(!playerRemote.pause)
      return;
    playstate = 0;
    btplaypause.comb3in1ImgSrc = "button-play.png"; 
    btplaypause.tooltip = '开始播放'; 
  }
  
  SetSetting('path',playerRemote.path );
  SaveSetting('path');
}

function widgetOnDock()
{
  scale = 88;
}

function widgetOnUnDock()
{
  scale = 100;
}

function btinfoOnClick()
{
  playerRemote.Visible = !playerRemote.Visible;
  
}

function btprevOnClick()
{
  playerRemote.prev;

  
  SetSetting('path',playerRemote.path );
  SaveSetting('path');
}

function btnextOnClick()
{
  LockRefresh;
   
  playerRemote.next;

  
  UnLockRefresh; 
  
  SetSetting('path',playerRemote.path );
  SaveSetting('path');
}

function widgetOnInit()
{
  playerRemote.playername = GetSetting("player");
  playerRemote.path = GetSetting("path");
  


  btplaypause.tooltip = '开始播放'; 

}

function OnAllSettingsSaved()
{
   widgetOnInit();
   SaveAllOption;
}

function widgetOnClose()
{
  SetSetting('path',playerRemote.path );
  SaveSetting('path');

}

function btstopOnClick()
{
  LockRefresh;
   
  playerRemote.stop;
  playstate = 0;
  btplaypause.comb3in1ImgSrc = "button-play.png"; 
  btplaypause.tooltip = '开始播放'; 
 
  UnLockRefresh; 
  
  SetSetting('path',playerRemote.path );
  SaveSetting('path');  
}

function nMenu7OnClick()
{
  if(playerRemote.playerName!="wmplayer")
  {
    var f =  openFileDialog;
    if(!fileExists( f ))
      return;
    
  }
  
  playerRemote.openMusic(f);
 
  playstate = 1;
  btplaypause.comb3in1ImgSrc = "button-pause.png";
  btplaypause.tooltip = '暂停'; 
  
}

function Run(objPath) 
{
    try 
    {
        var objShell = new ActiveXObject('wscript.shell');
        objShell.Run(objPath);
        objShell = null;
    }
    catch (e)
    {
    alert('找不到指定文件'+objPath+'(或它的组件之一)，请确定文件或路径是否正确，并确定更改了你的IE安全级别：工具--Internet 选项 -- 安全 -- 自定义级别 -- 没有标记为安全的 ActiveX 控件进行初始化和脚本运行\n设置为“启用”或 “提示”');
    }
}


function widgetOnDropFile(fileNameList)
{
  if(fileNameList=='')
    return;

  var fl =  fileNameList.split("|");
  var flist = '';
  
  for(var i=0;i<fl.length;i++)
  {
    flist += '"'+fl[i]+'";' ; 
  }

  Print(flist  );
    
  if(playerRemote.playerName!="wmplayer")
    playerRemote.openMusic(fl[0])
  else
    Run( '"'+ systemDisk + '\\Program Files\\Windows Media Player\\wmplayer.exe"  '+ flist )
 
  playstate = 1;
  btplaypause.comb3in1ImgSrc = "button-pause.png";
  btplaypause.tooltip = '暂停'; 
    
}