var xmlhttp = null;
var fadingElement = null;

//XMLHttpRequest - initialization
if (window.XMLHttpRequest)  {  // Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

//main function
function doCitationLoop(url) {
  fadingElement = document.getElementById('citation_container');
  if(fadingElement != null && xmlhttp!=null ) {
  window.setInterval("loadXMLDoc('"+url+"')", 9000);
  }
}

//get contents
function loadXMLDoc(url) {
  if (xmlhttp!=null)  {
    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=state_Change;
    xmlhttp.send(null);
  }
}

//callback
function state_Change() {
  if (xmlhttp.readyState==4) {  //state 4 == 'loaded'
    if (xmlhttp.status==200) {
      //alert(xmlhttp.responseText);
      changeByFading(fadingElement ,xmlhttp.responseText);
    }
    /* else { alert("Problem retrieving XML data");  }  */
  }
}


//change contents (scriptaculous library) 
function changeByFading(target, content){
  Effect.Fade(
    target, {
      duration:1,
      afterFinish: function() {
        target.innerHTML = content;
        Effect.Appear(target, { duration: 2.5, to: 0.9 } );
      }
    }
  );
}