var page1="软件程序";
var page2="常用网址";
var page3="游戏娱乐";
var page4="我的收藏";

var curIndex=1;
var imgs =new Array();
var scs =new Array();
var curImg;

function widgetOnLoad()
{
  curImg = image1;
  for(var i=1;i<=12;i++)
  {
    imgs[i]=eval("image"+i);
    scs[i]=eval("sc"+i);
  }
  
  
//  loadIconsByPage(1);

}

//根据页面需要载入快捷方式数据 
function loadIconsByPage(idx)
{
  var iniName,ico;

  txttt.text = eval("page" + idx );
  btBg.src = "src\\" + idx + ".png";
  if(idx==1)
    imgBtMask.left = 1
  else if(idx==2)
    imgBtMask.left = 33
  else if(idx==3)
    imgBtMask.left = 65
  else if(idx==4)
    imgBtMask.left = 93;

  for(var i=1;i<=12;i++)
  {
    iniName = idx+".sc"+i;
    scs[i].iniName = iniName;
    
    scs[i].displayName = getValue(iniName+".displayName","");
    scs[i].path = getValue(iniName+".path","");
    scs[i].param = getValue(iniName+".param","");
    ico = getValue(iniName+".icon","");
    
    if((ico=="")||(ico=="icon.png"))
    {
      scs[i].icon = "null.png";
      imgs[i].OnClick = "";
      imgs[i].cursor= 0;
    }
    else
    {
      scs[i].icon = ico;
      imgs[i].OnClick = "!OpenFile";
      imgs[i].cursor= -21;
    }
    scs[i].UpdateTargets;    
  }  
  
  if(idx>curIndex)
    layerIcons.AnimateChange.Style = 3
  else
    layerIcons.AnimateChange.Style = 4;
  curIndex = idx;
  
}

function button1OnClick(Sender)
{
  layerIcons.InitAnimateChange;
   
  loadIconsByPage(Sender.tag);

  layerIcons.StartAnimateChange;

  
}




function widgetOnPopupMenu()
{
  if(widget.CurrentObject!=null)
  {
    
    menuitem1.visible = widget.CurrentObject.core!=null;
    menuitem2.visible = widget.CurrentObject.core!=null;
    menuitem1.core = widget.CurrentObject.core;
    menuitem2.Core = widget.CurrentObject.core;
    if(widget.CurrentObject.core!=null)
      curImg = widget.CurrentObject;
    
    menuitem3.visible = layerIcons.visible;
  }  
}

function image1OnDragDrop(Sender,Data,Point)
{
  Sender.OnClick = "!OpenFile";
  Sender.cursor= -21;  
}


function btPrevOnMouseDown(Sender,Button,Shift,X,Y)
{
  var idx;
  if(curIndex-1<=0)
    idx = 4
  else
    idx = curIndex-1;

  layerIcons.InitAnimateChange;
  loadIconsByPage(idx);
  layerIcons.StartAnimateChange;
}

function layer1OnMouseDown(Sender,Button,Shift,X,Y)
{
  var idx;
  if(curIndex+1>4)
    idx = 1
  else
    idx = curIndex+1;

  layerIcons.InitAnimateChange;
  loadIconsByPage(idx);
  layerIcons.StartAnimateChange;
}


function menuitem2OnClick(Sender)
{
  if(menuitem2.Core!=null)
  {
      menuitem2.Core.icon = "null.png";
      curImg.OnClick = "";
      curImg.cursor= 0;
      curImg.src = "null.png";

      var iniName = menuitem2.Core.iniName; 
      setValue(iniName+".displayName","");
      setValue(iniName+".path","");
      setValue(iniName+".param","");
      setValue(iniName+".icon","");   
      saveini;  
      menuitem2.Core.UpdateTargets;
      
  }
}

function menuitem3OnClick(Sender)
{
  for(var i=1;i<=12;i++)
  {
    imgs[i].OnClick = "";
    imgs[i].cursor= 0;
    imgs[i].src = "null.png";
        
    scs[i].icon = "null.png";
    scs[i].displayName = "";
    scs[i].path = "";
    scs[i].param = "";
   
    var iniName = scs[i].iniName;
    setValue(iniName+".displayName","");
    setValue(iniName+".path","");
    setValue(iniName+".param","");
    setValue(iniName+".icon","");
    saveini;
    scs[i].UpdateTargets;
  }
  
}


function bt1OnClick(Sender)
{
  layerMid.InitAnimateChange;

  bgWelcome.visible = false;
  btBg.visible = true; 
  layerIcons.visible = true;
  loadIconsByPage(Sender.tag);
  layerMid.AnimateChange.Style = 23;

  layerMid.StartAnimateChange;  
}

function bgOnDblClick(Sender)
{
  if(bgWelcome.visible) return;
  layerMid.InitAnimateChange;

  bgWelcome.visible = true;
  btBg.visible = false;
  layerIcons.visible = false;
  
  layerMid.AnimateChange.Style = 12;

  layerMid.StartAnimateChange;
}
