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

cms.RC = function(div){
    this.div = div;
    this.counter = 0;
    this.config = null;
    this.lookupConfig();
};

cms.RC.prototype = {
    lookupConfig: function(){
        if(this.counter > 100) return;
        var i, el, cfg, list = this.div.childNodes;
        for (i = 0; (el = list[i]); i++) {
            if ((el.nodeName || '').toLowerCase() == 'code' &&
                (el.className || '').match(/rcb_bean_path_reload/)) {
                cfg = el; break;
            }
        }
        if (!cfg) this.destroy();
        else {
            this.config = i2rd.getInnerText(cfg).split(":");
            //log4js.logger.info("div#" +this.div.id + " config[0] = " + this.config[0] + ", config[1] = " + this.config[1]);
            window.setTimeout(i2rd.bind(this.updateContent, this), 
                parseInt(this.config[1]));
        }
    },
    updateContent: function() {
        var vc = this.div;
        while (vc) {
            if (vc.style && vc.style.display == 'none') {
                //log4js.logger.info("Not visible... waiting.");
                window.setTimeout(i2rd.bind(this.updateContent, this), 
                    parseInt(5000));
                return;
            }
            vc = vc.parentNode;
        }
        var url = this.config[0];
        //log4js.logger.log("Will update content of " + this.div.id + " with " + url);
    	var ajax = i2rd.getAjaxTransport();
        var rc = this;
        ajax.onreadystatechange = function(){
            if(ajax.readyState != 4) return;
            if ( (ajax.status == 200 || ajax.status == 0) && ajax.responseText) {
                rc.counter++;
          		//log4js.logger.info("Got response: " + ajax.responseText);
          		var tmp = document.createElement("div");
          		tmp.innerHTML = ajax.responseText;
                window.setTimeout(function() {    
                    var switcher = new cms.Switcher(rc.div, tmp.firstChild);
                    switcher.setOption('replace',true);
                    switcher.setCallback(i2rd.bind(rc.lookupConfig, rc));
                    switcher.start();
                    }, 400);
        	} else {
        		log4js.logger.warn("Didn't get the content I was expecting");
        	}
            delete ajax;
        };
    	ajax.open("GET", url);
    	//ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	ajax.send(null);
    },
    destroy: function(){
        this.div = null;
    }
};

cms.RC_Init = function(div){
    if(typeof div == 'string') div = document.getElementById(div);
    if (div.initedrc) {
        //log4js.logger.info("Skipping init of RC#" + div.id);
        return;
    }
    //log4js.logger.info("Initing RC#" + div.id);
    div.initedrc = true;
    new cms.RC(div);
};

}//End conditional eval

