  // Wave filter animation script (requires Internet Explorer 5.5+ browsers)
  //
  // F. Permadi 2005.
  // (C) F. Permadi
  //
  // If you use this script, please provide credit to F. Permadi; and 
  //   also provide a linkback to www.permadi.com
  //
  // This script is provided "as is" and without warranty whatsoever.
  // Use at your own risk.


  // global objects for storing all objects that needs the wave animation
  var wavers=new Array();
  var c=0;
  function waveAnimate(myElement, 
     freq, freqSpeed, minFreq, maxFreq, 
     strength, strengthSpeed, minStrength, maxStrength ,
     phase, phaseSpeed, minPhase, maxPhase,
     applyRotation)
  {
     // make sure that the element is valid
     if (!myElement)
       return;

     // Creates the object and store it
     wavers[c]=new initWave(myElement,
       freq, freqSpeed, minFreq, maxFreq, 
       strength, strengthSpeed, minStrength, maxStrength ,
       phase, phaseSpeed, minPhase, maxPhase,
       applyRotation);
       
     // This is the animation timer
     setInterval("wavers["+c+"].doWave()", 40);
     c++;
  }
  
  ////////////////////////////////////////////////////
  // This function takes an element (normally an IMG, a DIV, or a SPAN)
  // and applies the wave filter to the element.
  // 
  // The additional parameters are the wave filter parameters:
  //   freq, strength, and phase
  //   xyzSpeed is the velocity of the animation, 
  //   minxyz is the min value for the parameter
  //   maxxyz is the min value for the parameter
  //   applyRotation: if true, the wave filter is also applied horizontally
  ////////////////////////////////////////////////////
  function initWave(myElement, 
     freq, freqSpeed, minFreq, maxFreq, 
     strength, strengthSpeed, minStrength, maxStrength ,
     phase, phaseSpeed, minPhase, maxPhase,
     applyRotation)
  {
    this.element=myElement;
    this.applyRotation=applyRotation; 
    
    this.strengthSpeed=strengthSpeed;
    this.freqSpeed=freqSpeed;       
    this.phaseSpeed=phaseSpeed;
       
    this.minStrength=minStrength;    
    this.minFreq=minFreq;    
    this.minPhase=minPhase;    
       
    this.maxStrength=maxStrength;    
    this.maxFreq=maxFreq;    
    this.maxPhase=maxPhase;
       
    this.freq=freq;   
    this.phase=phase;
    this.strength=strength;
     
    this.doWave=function()
    {
      this.freq+=this.freqSpeed;
      this.phase+=this.phaseSpeed;
      this.strength+=this.strengthSpeed;
     
      if (this.freq>this.maxFreq)
      {
         this.freqSpeed=-Math.abs(this.freqSpeed);
      }
      else if (this.freq<this.minFreq)
      {
         this.freqSpeed=Math.abs(this.freqSpeed);
      }     

      if (this.phase>this.maxPhase)
      {
        this.phaseSpeed=-Math.abs(this.phaseSpeed);
      }
      else if (this.phase<this.minPhase)
      {
        this.phaseSpeed=Math.abs(this.phaseSpeed);
      }     

      if (this.strength>this.maxStrength)
      {
        this.strengthSpeed=-Math.abs(this.strengthSpeed);
      }
      else if (this.strength<this.minStrength)
      {
        this.strengthSpeed=Math.abs(this.strengthSpeed);
      }             
      var filterString=
        " progid:DXImageTransform.Microsoft.wave("+
          "lightStrength=30"+ 
          ", strength="+this.strength+ 
          ", phase="+this.phase+ 
          ", freq= "+this.freq +  
          ")";
      if (this.applyRotation)
      {
        filterString+=
          " progid:DXImageTransform.Microsoft.BasicImage(rotation=1)"+
          " progid:DXImageTransform.Microsoft.Wave("+
          "lightStrength=30"+
          ", strength="+this.strength+ 
          ", phase="+this.phase+
          ", freq= "+this.freq+
          ")"+
          " progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";
      }
      if (this.element.style)
        this.element.style.filter=filterString;
   }
 }
