function InsertTransformTo (xmlUrl, xslUrl, elementToInsert) {
  this.xmlUrl = xmlUrl;
  this.xslUrl = xslUrl;
  this.xmlLoaded = this.xslLoaded = false;
  this.elementToInsert = elementToInsert;
  this.load(xmlUrl, 'xml');
  this.load(xslUrl, 'xsl');
}

InsertTransformTo.prototype.load = function (url, propertyName) {
  var httpRequest = null;
  if (typeof XMLHttpRequest != 'undefined') {
    httpRequest = new XMLHttpRequest();
  }
  else if (typeof ActiveXObject != 'undefined') {
    try {
      httpRequest = new ActiveXObject('Msxml2.XMLHTTP.3.0');
    }
    catch (e) {}
  }
  if (httpRequest != null) {
    var thisObject = this;
    httpRequest.open('GET', url, true);
    httpRequest.onreadystatechange = function () {
      if (httpRequest.readyState == 4) {
        thisObject[propertyName + 'Loaded'] = true;
        thisObject[propertyName] = httpRequest.responseXML;
        if (thisObject.xmlLoaded && thisObject.xslLoaded) {
          thisObject.transformAndInsert();
        }
      }
    };
    httpRequest.send(null);
  }
};

InsertTransformTo.prototype.transformAndInsert = function () {
  if (typeof XSLTProcessor != 'undefined') {
    var xsltProcessor = new XSLTProcessor();
    xsltProcessor.importStylesheet(this.xsl);

    this.elementToInsert.appendChild(xsltProcessor.transformToFragment(this.xml, this.elementToInsert.ownerDocument)); 
    this.elementToInsert.removeChild(this.elementToInsert.childNodes[1]);
    
        
  }
  else if (typeof this.xml.transformNode != 'undefined') {
      this.elementToInsert.innerHTML = this.xml.transformNode(this.xsl);  
  }
  Ticker();  
};

Ticker = function () { 

    var list = $$('li.logs');
    var count = 0;
    list.each(function(li, i){
        if (i != 0)
        {
            li.setStyle('display', 'none');
            li.setStyle('opacity', '0');
        }
        count++;
    });

    var runLoopTicker = function() {
      list.each(function(li, i){
            var opacity = li.getStyle('opacity').toInt();
             
            li.setStyle('display', 'list-item');
            var fx = li.effects({duration: 2000 , transition: Fx.Transitions.Quart.easeOut});
            fx.start({

            }).chain(function(){
                this.start.delay(4000 * i, this, {
	                'opacity': 1
                });
            }).chain(function(){
                this.start.delay(0, this, {
	                'opacity': 0
                });
            }).chain(function(){
                li.setStyle('display', 'none');
            });                                                  
        });    
    }
    runLoopTicker();    
    var timer = runLoopTicker.periodical(4000 * count);
};

window.onload = function (evt) {
   var logs = document.getElementById('logs');
  new InsertTransformTo('/index.xml', '/tickerxsl.xml', logs);
};
