function p$(string)
{
  document.write(string);
}

function $(id)
{
  return document.getElementById(id);
}

/*******************************************/

function ImageRotate()
{
  //图片宽度
  if (typeof arguments[0] == "number")
  {
    this.imgWidth = arguments[0];
  }
  //图片高度
  if (typeof arguments[1] == "number")
  {
    this.imgHeight = arguments[1];
  }
  //图片切换的间隔
  if (typeof arguments[2] == "number")
  {
    this.timeOut = arguments[2];
    this.timeOut2 = arguments[2] / 2;
  }
  //链接目标
  this.linkTarget = arguments[3];

  //图片层
  this.oImageDiv = $(arguments[4]);
  //图片链接
  this.oImageLink = document.createElement("a");
  //信息层
  this.oInfoDiv = $(arguments[5]);
  //按钮层
  this.oButtonDiv = $(arguments[6]);
  //渐变线
  this.oLine = document.createElement("<div id='" + arguments[7] + "'></div>");
  //链接文字
  this.oText = $(arguments[8]);

  //图片和文字数组
  this.imgUrl = new Array();
  this.imgText = new Array();
  this.imgLink = new Array();
  this.imgAlt= new Array();
  this.imgCount = 0;

  //按钮对象的数组
  this.oButtons = new Array();

  //图片对象数组
  this.oImages = new Array();

  //固定初始值的属性
  this.ver = 2;
  this.curIndex = 0;
}

//画渐变线
ImageRotate.prototype.DrawLine = function()
{
  this.oInfoDiv.insertBefore(this.oLine, this.oInfoDiv.childNodes.item(0));
}

//开始轮换
ImageRotate.prototype.Start = function()
{
  //确定图片个数
  for (i = 0; i < this.imgUrl.length; i++)
  {
    if((this.imgUrl[i] != "") && (this.imgText[i] != "")&& (this.imgLink[i] != "")&& (this.imgAlt[i] != ""))
    {
      this.imgCount++;
      this.oImages[i] = document.createElement("<img src='" + this.imgUrl[i] + "' alt='" + this.imgAlt[i] + "' width='" + this.imgWidth + "' height='" + this.imgHeight + "' border='0'>");
    }
    else
    {
      break;
    }
  }

  //初始化图片和链接对象
  this.oImageLink.target = this.linkTarget;
  this.oImageLink.href = this.imgLink[this.curIndex];
  this.oImageLink.appendChild(this.oImages[this.curIndex]);
  this.oImageDiv.appendChild(this.oImageLink);

  //取得this对象
  var msobj = this;

  //数字按钮
  for (i=this.imgCount-1;i>=0;i--)
  {
    var div_bg = document.createElement("<div class='bg'></div>");
    this.oButtonDiv.appendChild(div_bg);

    this.oButtons[i] = document.createElement("a");
    this.oButtons[i].title = this.imgAlt[i];
    this.oButtons[i].innerHTML = i + 1;
    this.oButtons[i].href = "javascript:void(0)";
    eval("this.oButtons[i].onclick = function(){clearTimeout(msobj.theTimer);msobj.curIndex = " + i + ";msobj.Change();};")
    div_bg.appendChild(this.oButtons[i]);

    this.oButtonDiv.appendChild(document.createElement("div"));
  }

  //图片文字
  if (!this.imgText && this.imgText.length > 0) this.oText.innerHTML = this.imgText[this.curIndex];

  this.oImageDiv.onmouseover = function(){window.clearTimeout(msobj.theTimer);}
  this.oImageDiv.onmouseout = function(){msobj.theTimer = setTimeout(msobj.Change, msobj.timeOut / 2);}

  //检测浏览器
  try
  {
    //滤镜版本
    new ActiveXObject("DXImageTransform.Microsoft.Fade");
    this.oImageDiv.filters[0].play();
    this.ver = 1;
    this.DrawLine();
  }
  catch(e)
  {
    this.ver = 2;
  }

  //图片轮换
  msobj.Change = function()
  {
    if (msobj.ver == 1)
    {
      with(msobj.oImageDiv.filters[0])
      {
        Transition = Math.random() * 23;
        apply();
      }
    }

      msobj.oImageLink.removeChild(msobj.oImageLink.children(0));
      msobj.oImageLink.appendChild(msobj.oImages[msobj.curIndex]);
      msobj.oImageLink.href = msobj.imgLink[msobj.curIndex];
      if (msobj.imgText && msobj.imgText.length > 0) msobj.oText.innerHTML = msobj.imgText[msobj.curIndex];
  
      for (i=0;i<msobj.imgCount;i++)
      {
        msobj.oButtons[i].className = "button";
      }
      msobj.oButtons[msobj.curIndex].className = "on";

    if (msobj.ver == 1)
    {
      msobj.oImageDiv.filters[0].play();
    }

    //计算下张图的序号
    msobj.curIndex = (msobj.curIndex >= msobj.imgCount - 1) ? 0 : msobj.curIndex + 1;

    msobj.theTimer = setTimeout(msobj.Change, msobj.timeOut);
  }

  //开始
  this.theTimer = setTimeout(msobj.Change, 2);
}