var count,size,hd;
        
function widgetOnInit()
{
  count = -1; 
  tm.interval = parseInt(GetSetting( "refreshsec" )) * 1000;
  tm.enabled = true; 
  tmOnTimer(); 
  if(count>0)
    icon.Src = "images\\" + GetSetting( "icon" ) + "f.png"
  else
    icon.Src = "images\\" + GetSetting( "icon" ) + ".png";
  bg.src = GetSetting("bg");
  txt.fontName = GetSetting( "txtfn" );   
  txt.fontSize = parseInt(GetSetting( "txtsize" ));   
}

function tmOnTimer()
{
  LockRefresh;
  var pcount = recycleItemCount;
  
  if(count==pcount)
    return;
  
  count =  pcount;
  size =   recycleSize;
  if(count==0)
  {
    txt.caption = "回收站空"; 
  }                   
  else
  { 
    if(!dockedOnSidebar)
      txt.caption = count + "项 " + convertBytes2(size)
    else 
      txt.caption = count + "项\n" + convertBytes2(size);
  }
  if(count>0)
    icon.Src = "images\\" + GetSetting( "icon" ) + "f.png"
  else
    icon.Src = "images\\" + GetSetting( "icon" ) + ".png";
  
  UnLockRefresh;
}

function nMenu1OnClick()
{
  tmOnTimer();
}

function OnAllSettingsSaved()
{
  widgetOnInit();
}

function widgetOnDBClick()
{
  OpenLink("::{645FF040-5081-101B-9F08-00AA002F954E}");

//  Run("::{645FF040-5081-101B-9F08-00AA002F954E}");
  tmOnTimer(); 
}

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

function refreshrc()
{
  clearTimeout(hd);
  tmOnTimer();
  Print( "refreshrc" );
}

function widgetOnDropFile(fileNameList)
{
  deleteToRecycleBin( fileNameList );
  tmOnTimer();
}

function widgetOnUnDock()
{
  LockRefresh;

  bg.Visible = false;
  //txt.fontStr = "clWhite/-17/Tahoma/13/1000";
  txt.Left = 0;
  txt.Top = 125;
  txt.Width = 128;
  txt.Height = 50;
  txt.align = 1; 
  
  icon.Width = 128;
  icon.Height = 128;
  
  widgetWidth = 128;
  widgetHeight = 142;
  
  UnLockRefresh;
  count = -1;
  tmOnTimer();
}

function widgetOnDock()
{
  LockRefresh;

  bg.Visible = true;
//  txt.fontStr = "clWhite/-17/Tahoma/13/1000";
  txt.Left = 60;
  txt.Top = 25;
  txt.Width = 60;
  txt.Height = 50;
  txt.align = 2; 
  
 
  icon.Width = 64;
  icon.Height = 64;
  
  widgetWidth = 133;
  widgetHeight = 70;
  
  UnLockRefresh;  
  count = -1;
  tmOnTimer();
}

function txtOnMouseDown()
{
  if( confirm2("确认清空回收站?") )
  {
    emptyRecycleBin;
    tmOnTimer();
  }  
}


function convertBytes2(b)
{
  var i = 0, u = Array(' MB', ' GB', ' TB');

  while (b >= 1024 && (b / 1024) >= 1)
  {
    b /= 1024;
    i++;
  }

  Print(i );
  var str;
  switch(i)                             
  {     
    case 0 : 
      str = 'B';
      break;
    case 1 : 
      str = 'KB';
      break;
    case 2 : 
      str = 'MB';
      break;
    case 3 :
      str = 'GB';
      break;
    case 4 :
      str = 'TB';
      break;
    default: 
      str = "GB";
  }


  return (Math.round(b * 100)/100).toFixed(1) + str;
}