var rssitem =new Array();
var curcore;
var nowCore;

function widgetOnLoad()
{
  nowCore = rsscore1; 
  for(var i=1;i<=6;i++)
    rssitem[i] = eval( "text"+i );

  timercore1.enabled = false;

  curcore = getValue("curcore",1); 
  BindCore( curcore );
  
  menuitem1.checked = getValue("autoNextChannel",true);
  timercore1.enabled = menuitem1.checked;
}

function Nextpage()
{
  if(!rssitems.InitAnimateChange)
    return;

  rssitems.AnimateChange.Style = 5 ;
  nowCore.cmd( null,"!NextPage");

  rssitems.StartAnimateChange;
  
}

function PrevPage()
{
  if(!rssitems.InitAnimateChange)
    return;

  rssitems.AnimateChange.Style = 6 ;
  nowCore.cmd( null,"!PrevPage");

  rssitems.StartAnimateChange;  
}

function BindCore(core)
{
  nowCore = eval("rsscore"+core);
  curcore =  core;
  
  for(var i=1;i<=6;i++)
    rssitem[i].core = nowCore;

  rsstt.core=nowCore;
  layerBtNext.core=nowCore;
  layerBtPrev.core=nowCore;
  layerBtSet.core=nowCore;
  textLoading.core=nowCore;
  textHint.core = nowCore;
  menuitem2.core = nowCore;
  
  image2.src = "C" + core + ".png";

  setValue( "curcore",core);
  saveIni;
}

function timercore1OnUpdate(Sender)
{
    curcore = curcore+1;
    if( curcore>4 ) curcore=1;
    BindCore( curcore );
}

function widgetOnEnter()
{
  textHint.FadeTo( 1,0.3 );
  timercore1.enabled = false;
}

function widgetOnLeave()
{
   textHint.FadeTo( 0,0.3);
   timercore1.enabled = menuitem1.checked;
}


function button1OnMouseDown(Sender,Button,Shift,X,Y)
{
  if(!rssitems.InitAnimateChange)
    return;

  if(Sender.tag>=curcore)
    rssitems.AnimateChange.Style = 3 
  else
    rssitems.AnimateChange.Style = 4 ;

  BindCore(Sender.tag);

  
  rssitems.StartAnimateChange;


}


function menuitem1OnClick(Sender)
{
  menuitem1.checked = !menuitem1.checked;
  timercore1.enabled = menuitem1.checked;
  setValue( "autoNextChannel",menuitem1.checked);
  saveIni; 
}

function bgOnMouseWheel(Sender,Shift,WheelDelta)
{
  if( WheelDelta<0 )
    Nextpage()
  else
    PrevPage();
}



function layerBtPrevOnMouseDown(Sender,Button,Shift,X,Y)
{
  PrevPage();
}

function layerBtNextOnMouseDown(Sender,Button,Shift,X,Y)
{
  Nextpage();
}
