/*	10:42 2007-5-13 by buglol	*/

var switchNews = function()
{
  this.content = [];
  if(typeof($)=="undefined")$=function(hook){return document.getElementById(hook);}
  this.timeout = 5000;
  this.timer = "";
  this.width = 250;
  this.height = 150;
  this.border = "0px solid #FF7700";
  this.background = "#313035";
  this.display = "block";
  this.color = "black";
  this.padding = "0";
  this.showNewDays = 3;
  this.IMG = "/test/library/images/";
  this.H = 0;

  var dignityRegionHeight = 20;
  var me = this;
  var L = 0;
  var curPoint = 1,s1,s2;
  document.write("<div style='width:"+this.width+"px';height:"+this.height+"px' id='___forPositionDiv__id_BUGLOL17739ENDEAVOR'></div>");
  this.initize = function()
  {
     L = this.content.length;me.H=(me.H?me.H:me.height-100);
     if(!L){document.write("No news currently...");return false;}
     var hookSwitchNewsDivObjectContent = $("hookSwitchNewsDivObjectContent");
     var hookSwitchNewsDivObjectControl = $("hookSwitchNewsDivObjectControl");
     var _ = $("___forPositionDiv__id_BUGLOL17739ENDEAVOR");
     if (!hookSwitchNewsDivObjectContent) 
     {
	hookSwitchNewsDivObjectContent = document.createElement("div");
	hookSwitchNewsDivObjectContent.id = "hookSwitchNewsDivObjectContent";
	hookSwitchNewsDivObjectControl = document.createElement("div");
	hookSwitchNewsDivObjectControl.id = "hookSwitchNewsDivObjectControl";
	with(hookSwitchNewsDivObjectContent.style)
	{
	  position = "relative";
	  display = this.display;
	  background = this.background;
	  color = this.color;
	  padding = this.padding+"px";
	  border = "0px";
	  width = this.width+"px";
	  overflow = "hidden";
	  //wordbreak = "break-all";
	  height=(this.height-dignityRegionHeight)+"px";
        }
	with(hookSwitchNewsDivObjectControl.style)
	{
	  position = "relative";
	  display = this.display;
	  color = this.color;
	  padding = "0px";
	  border = "0px";
	  width=this.width+"px";
	  height="20px";
	  background="#313035";
	  filter="Alpha(Opacity=100)";
	  clear="both";
	  float="right";
        }
	_.appendChild(hookSwitchNewsDivObjectContent);
	_.appendChild(hookSwitchNewsDivObjectControl);
     }//end if

     s2 = "<table id='SN_trigger_idx_capital' align='right' cellpadding=1 cellspacing=5><tr>";
     for(i=0;i<L;i++)
     {
	if(this.content[i].length!=4){alert("Argue does not matched!");return false;}
	s2 += "<td id='SN_trigger_idx_"+i+"' style='width:16px;heigth:16px;cursor:pointer;text-align:center;color:blue;'>" + (i+1) + "</td>";
     }
     s2 += "</tr></table>";
     $("hookSwitchNewsDivObjectContent").innerHTML = draw(0);
     L>1?($("hookSwitchNewsDivObjectControl").innerHTML = s2):"";
     for(var i=0;i<(L>1?L:0);i++)
     {
	$("SN_trigger_idx_"+i).onclick = function()
	{
	  clearTimeout(me.timer);
	  me.show(parseInt(this.innerHTML,10)-1);
	  curPoint = parseInt(this.innerHTML,10)-1;
	}
     }
  }

  this.show = function(idx)
  {
    for(i=0;i<L;i++)
    {
      $("SN_trigger_idx_"+i).style.background = (i==idx?"#024483":"#FFF");
      $("SN_trigger_idx_"+i).style.color = (i==idx?"#FFF":"#000");
    }
    $("hookSwitchNewsDivObjectContent").innerHTML = draw(idx);
    curPoint = curPoint % L;
    me.timer = setTimeout(function ()
    {
      me.show(curPoint++);
    },me.timeout);
  }
  function draw(idx)
  {
    s1 = "";
    s1 += "<table width='98%' cellpadding=7 cellspacing=8><thead><tr><td style='font-weight:bolder;width:78%;'>"+"<img align='absmiddle' src='"+me.IMG+"newstitle.gif' style='padding-right:15px;'>"+me.content[idx][0] +(me.content[idx][3]>me.showNewDays?"":"<img style='padding-left:20px;' align=absmiddle src="+me.IMG+"new.gif>")+"</td><td align=right><img align='absmiddle' src='"+me.IMG+"date.gif' style='padding-right:15px;'>"+me.content[idx][2]+"</td></tr></thead>";
    s1 += "<tbody><tr><td colspan='2' style='background:#313035;border:0px dotted #FFFF33;' valign='top'><div style='overflow: hidden;height:"+me.H+"px;'>"+me.content[idx][1]+"</div></td></tr></tbody></table>";
    return s1;
  }
  this.hide = function(H)
  {
     hookSwitchNewsDivObjectContent.style.display = H?"none":"block";
  }
  me.timer = setTimeout(function ()
  {
    if(L&&L>1)me.show(curPoint++);
  },me.timeout);
}
