// shawl.qiu JavaScript Document
 /*-----------------------------------------------------------------------------------*\
  * shawl.qiu javascript Blink class v1.0
 \*-----------------------------------------------------------------------------------*/
 //---------------------------------begin class Blink()-------------------------------//
 function Blink()
 { // shawl.qiu code
  //------------------------------------begin public variable
  //---------------begin about
  this.auSubject = 'shawl.qiu javascript Blink class';
  this.auVersion = 'v1.0';
  this.au = 'shawl.qiu';
  this.auEmail = 'shawl.qiu@gmail.com';
  this.auBlog = 'http://blog.csdn.net/btbtd';
  this.auCreateDate = '2007-5-16';
  //---------------end about
  
  this.Debug = true;
  this.Object = null;
  
  this.Random = {}
  this.Random.ByRandom = false;
  this.Random.Set = [];
  
  this.Color = {};
  this.Color.Set =[];
  this.Color.Init = fInitColor;
  this.Color.Add = fAddColor;
  this.Color.Old = [];
  this.Color.ColorForFf = "blue";
  this.Color.BackgroundColorForFf = "transparent";
  this.Color.IsBackground = false;
  
  this.PropertyNmae = "dasdjjasdfjk";
  
  this.Interval = 300;
  //------------------------------------end public variable
  
  //------------------------------------begin private variable
  var Tl = this;
  //------------------------------------end private variable
  
  //------------------------------------begin public method
  this.Go = fGo;
  //------------------------------------end public method
 
  //------------------------------------begin private method
  function fAddColor(val)
  {
   if(val=="")
   {
    alert("颜色值不能为空!");
    return;
   }
   fInitArray(Tl.Color.Set, val);
  }
  
  function fInitColor(bClear)
  {
   fInitArray(Tl.Color.Set, "yellow");
   fInitArray(Tl.Color.Set, "fuchsia");
   fInitArray(Tl.Color.Set, "black");
   fInitArray(Tl.Color.Set, "red");
   fInitArray(Tl.Color.Set, "springgreen");
   fInitArray(Tl.Color.Set, "orange");
   fInitArray(Tl.Color.Set, "brown");
   fInitArray(Tl.Color.Set, "blue");
   
   if(bClear)Tl.Color.Set.length = 0;
  } // end function fInitColor
  
  function fGo()
  {
   var Debug = false;
   if(Debug)
   {
    alert(typeof(Tl.Object));
   }
   
   if(!Tl.Random.ByRandom)
   {
    Tl.Color.Init();
   }
   
   if(typeof(Tl.Object.length)=="number")
   {
    fBlinkArray(Tl.Object);
   }
   else
   {
    fFireEff(Tl.Object);
   }
  } // end function fGo
  
  function fBlinkArray(Set)
  {
   for(var i=0, j=Set.length; i<j; i++)
   {
    fFireEff(Set[i], i);
   } // end for
  } // end function fBlinkArray
  
  function fFireEff(Obj, i)
  {
   if(!i) i=0;
   Obj[Tl.PropertyName] = i;
   
   if(fCkBrs()!=3)
   {
    if(Tl.Color.IsBackground)
    {
     Tl.Color.Old[i] = Obj.currentStyle.backgroundColor;
    }
    else
    {
     Tl.Color.Old[i] = Obj.currentStyle.color;
    }
   }
   else
   {
    if(Tl.Color.IsBackground)
    {
     Tl.Color.Old[i] = Tl.Color.BackgroundColorForFf;
    }
    else
    {
     Tl.Color.Old[i] = Tl.Color.ColorForFf;
    }
   }
   Obj.onmouseover = function()
   {
    var Ele = this;
    sqBlinkMouseMove = setInterval
     (
      function()
      {
       var Color = "";
       
       if(Tl.Random.ByRandom)
       {
        Color = fRndCor(0, 255).replace(/\;$/,"");
       }
       else
       {
        if(Tl.Color.Set.length==0)
        {
         defaultStatus = "颜色预设值为空!";
         return;
        }
        Color = Tl.Color.Set[fRandomBy(0, Tl.Color.Set.length-1)];
       }
       if(Tl.Color.IsBackground)
       {
        Ele.style.backgroundColor = Color ;
       }
       else
       {
        Ele.style.color = Color ;
       }
      }
      ,
      Tl.Interval
     );
   } // end Obj.onmousemove
   
   Obj.onmouseout = function()
   {
    clearInterval(sqBlinkMouseMove);
    if(Tl.Color.IsBackground)
    {
     this.style.backgroundColor = Tl.Color.Old[this[Tl.PropertyName]];
    }
    else
    {
     this.style.color = Tl.Color.Old[this[Tl.PropertyName]];
    }
   } // end Obj.onmouseout
  } // end function fFireEff
  
  function fRndCor(under, over)
  {// shawl.qiu code
   if(arguments.length==1)
   {
    var over=under;
     under=0;
   }
   else if(arguments.length==0)
   {
    var under=0;
    var over=255;
   } // end if
   
   var r=fRandomBy(under, over).toString(16);
    r=fStrPadStr(r, r, 2);
   var g=fRandomBy(under, over).toString(16);
    g=fStrPadStr(g, g, 2);
   var b=fRandomBy(under, over).toString(16);
    b=fStrPadStr(b, b, 2);
    //defaultStatus=r+' '+g+' '+b
   return '#'+(r+g+b).toUpperCase()+';';
  
   function fRandomBy(under, over)
   {// shawl.qiu code
    switch(arguments.length)
    {
     case 1: return parseInt(Math.random()*under+1);
     case 2: return parseInt(Math.random()*(over-under+1) + under);
     default: return 0;
    } // end switch
   } // end function fRandomBy
   
   function fStrPadStr(sSrc, sPad, nLen)
   {
    if(!sSrc)return false;
    if(!sPad)sPad='0';
    if(!nLen)nLen=2;
    sSrc+='';
    if(sSrc.length>=nLen)return sSrc;
    sPad=new Array(nLen+1).join(sPad);
    var re=new RegExp('.*(.{'+(nLen)+'})$');
    return (sPad+sSrc).replace(re,'$1');
   } // end function fStrPadStr
  } // end function fRndCor
  
  function fRandomBy(under, over)
  {// shawl.qiu code
   switch(arguments.length)
   {
    case 1: return parseInt(Math.random()*under+1);
    case 2: return parseInt(Math.random()*(over-under+1) + under);
    default: return 0;
   } // end switch
  } // end function fRandomBy
  
  function fCkBrs()
  {
   switch (navigator.appName)
   {
    case 'Opera': return 2;
    case 'Netscape': return 3;
    default: return 1;
   }
  } // end function fCkBrs 
  
  function fInitArray(a, val)
  {
   if(a==null)
   {
    alert("输入组件不能为 null!");
    return;
   }
   
   if(typeof(val.length)!=undefined&&typeof(val)!="string")
   {
    var iTemp = a.length;
    a[iTemp] = [];
    for(var i=0, j=val.length; i<j; i++)
    {
     a[iTemp][i] = val[i]
    } // end for
    return false;
   } // end if
   a[a.length]=val;
  } // end function fInitArray
  //------------------------------------end private method
 } // shawl.qiu code
 //---------------------------------end class Blink()---------------------------------//
 var blink = new Blink();
