if(typeof cms_switcher == 'undefined') {
cms_switcher = true;
if(typeof cms == 'undefined') {cms = {};}

cms.Switcher = function(origEl, newEl){
    // TODO (russ@i2rd.com) add auto scaling
    this.origEl=origEl;
    this.newEl=newEl;
    this.options={replace:false,callback:null,step:0.1,rate:75};
};
cms.Switcher.setOpacity = function(el, value) {
    var gecko=(/Gecko/.test(navigator.userAgent) && !/KHTML|WebKit/.test(navigator.userAgent)),
        msie=(/MSIE [678]/.test(navigator.userAgent) && !window.opera);
    if (value >= 1) {
      value = gecko ? 0.999999 : 1.0;
      if(msie) el.style.filter = el.style.filter.replace(/alpha\([^\)]*\)/gi,'');
    }else{
      if(value < 0.00001) value = 0;
      if(msie) {
    	  el.style.filter = el.style.filter.replace(/alpha\([^\)]*\)/gi,'')+'alpha(opacity='+ parseInt(value * 100) +')';
    	  if(!el.hasLayout) el.style.zoom=1.0; // MSIE Hack
      }
    }
    el.style.opacity = value;
};
cms.Switcher.getOpacity = function(el) {
	var value = el.style.opacity;
    if(el.style.filter) {
        value=/alpha\(opacity=([^\)]+)\)/gi.exec((el.style.filter||''));
        if(value && value[1]) {value=parseFloat(value[1]) / 100.0;}
    }	
	if(value) return parseFloat(value);
	return  1.0;
};
cms.Switcher.prototype = {
    setCallback:function(cb){this.options.callback=cb;},
    setOption: function(option, value){this.options[option]=value;},
    start: function(){
      this._fout();  
    },
    _fout: function(){
        var o=cms.Switcher.getOpacity(this.origEl);
        if(o>0.1) {
            cms.Switcher.setOpacity(this.origEl,(o=o-this.options.step));
            setTimeout(i2rd.bind(this._fout, this),this.options.rate);
        }else{this._foutDone();}
    },
    _foutDone: function(){
        cms.Switcher.setOpacity(this.newEl, 0);
        if (this.options.replace) {
            this.origEl.innerHTML = this.newEl.innerHTML;
            this.newEl=this.origEl;
        }
        if (this.newEl != this.origEl) {
            this.origEl.style.display = 'none';
            if (this.newEl.style.display == 'none') this.newEl.style.display = 'block';
        }
        this._fin();
    },
    _fin: function(){
        var o=cms.Switcher.getOpacity(this.newEl);
        if(o<0.91) {
            cms.Switcher.setOpacity(this.newEl,(o=o+this.options.step));
            setTimeout(i2rd.bind(this._fin, this),this.options.rate);
        }else{this._finDone();}
    },
    _finDone:function(){
        try {
            if (this.options.callback) this.options.callback.apply(this);
        }finally{
            delete this.origEl;
            delete this.newEl;
            delete this.options;
        }
    }
}; // end cms.Switcher.prototype
} //end cms_switcher conditional

