﻿
function adRotator() {};
adRotator.initialize=function(o)
{
 // script by blueDestiny

 this._t = new Array();
 this._l = new Array();
 this._p = new Array();
 this._d = new Array();
 this._i = new Image();
 this._c = 0;
 this._f = false;
 this._o = o;

 this._timeout = null;
 this._html = "";

 // configration.
 // @ image width
 // @ image height
 // @ rotator speed
 // @ filter type

 this._w = 295;
 this._h = 250;
 this._s = 4;
 this._x = 23;

 return this;
};
adRotator.add=function(p,t,l,id) { with (this)
{
 _p.push(p);
 _t.push(t);
 _l.push(l);
 _d.push(id);
}};

  //firefox不支援輪撥的問題
// this.isFirefox=(!this.isIE&&navigator.userAgent.match(/firefox/gi))?true:false;
// if(this.isFirefox)
//    alert("Firefox不支援輪撥功能，請使用ie瀏覽，謝謝。");
    
adRotator.load=function() { with (adRotator)
{

 if( _i.readyState=='complete' || this.isFirefox == true )
 {
  if(_p.length-1==_c)
  {
   _f = true;
   _c = 0;
   window.clearTimeout(_timeout);
   //getRef("AdRotator").innerHTML="complete";
   adRotator.play();
  }
  else
  {
   _c++;
   //getRef(_o).innerHTML="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "...";
    getRef(_o).innerHTML="<span>Loading.....</span>";
   _timeout=window.setTimeout(adRotator.load,10)
  }
 }
 else
 {
  //getRef(_o).innerHTML="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "...";
  getRef(_o).innerHTML="<span>Loading.....</span>";
  _timeout=window.setTimeout(adRotator.load,10)
 }
}};

adRotator.play=function() { with (adRotator)
{
 if( _f )
 {
 _html = "";
 _html += '<table><tr><td style="font-size:9pt;font-family:tahoma;font-weight:bold;" valign="top">'
 _html += '<div id="rotatorPlayer"'
   + ' style="width:' + _w + ''
   + ';height:"' + _h + '"'
   + '>'
 _html += '<a href="' + ( _l[_c] ? _l[_c] : "javascript:void(0);" ) + '">';
 _html += '<img id="rotatorPic" onclick="RequestXmlHttp('+_d[_c]+')"  src="' + _p[_c] + '"'
   + ' width="' + _w + '"'
   + ' height="' + _h + '"'
   + (_t[_c]?' title="' + _t[_c] + '"':'')
   + ' style="border:1px solid #B14713;FILTER:revealTrans(transition=' + _x + ',duration=1);"'
   + ' >';
 _html += (_t[_c]?('<div align="center" style="display:none;">' + (_c+1) + '. ' + _t[_c] + '</div>'):'<p></p>');
 _html += '</a>';
 _html += "</div>";
 _html += '<div align="right">';

 for(var i=0; i<_p.length; i++)
  _html += '<span'
     + ' style="border:1px solid #333333;display:none;padding:1px 5px 1px 5px;height:20px;text-align:center;cursor:'
     + (_c==i ? ('default;background-color:red;"') : 'hand;" onclick="adRotator.select(' + i + ')"')
     + '>'
     + (i>8?(i+1):('0'+(i+1)))+ '</span> ';

 _html += "</div></td><td valign='top'><table><tr><td align='left' valign='top'>&nbsp;";
 for(var k=0;k<_p.length;k++)
    _html +='<img  src="'+_p[k]+'" alt="'+_t[k]+'" width="46px" height="34px" style="cursor:'+(_c==k ? ('default;border:1px solid #B14713;"') : 'hand;" onclick="adRotator.select(' + k + ')"')+'/>&nbsp;';
    
 _html += "</td></tr><tr><td><div id='divGoodInfo' align='left' vglign='top'>"+obj.GoodInfo+"</div></td></tr></table></td></tr></table>";
 
 getRef(_o).innerHTML = _html;

 getRef("rotatorPic").filters[0].Apply();
 getRef("rotatorPic").filters[0].Play();

 next();
 }
 else
 {
  _i.src = _p[_c];
  adRotator.load();
 }
}};
adRotator.next=function() { with (this)
{
 (_p.length-1==_c) ? _c=0 : _c++;
 _timeout=window.setTimeout(adRotator.play,_s*1000);
}};
adRotator.select=function(i) { with (this)
{
 window.clearTimeout(_timeout);
 _c=i;
 adRotator.play();
}};
adRotator.set=function(second) { with (this)
{
 window.clearTimeout(_timeout);
 if((/\d+/).test(second)==true)
 {
  _s=second;
  adRotator.play();
 }
 else
 {
  alert("must be digit!")
  adRotator.play();
 }
}};
function getRef(id)
{
// alert(id);
 return (document.all?document.all(id):document.getElementById(id));
}
adRotator.initialize("AdRotator");






