var  TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function  animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}



if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.open("GET","quotes.xml",false);
 xmlhttp.send();
 xmlDoc=xmlhttp.responseXML;


var Quotation=new Array()
var Author=new Array()


var x=xmlDoc.getElementsByTagName("item");
 for (i=0;i<x.length;i++)
   { 
   
	Quotation[i] = x[i].getElementsByTagName("quote")[0].childNodes[0].nodeValue;
	Author[i] = x[i].getElementsByTagName("author")[0].childNodes[0].nodeValue;

   }




var Q = Quotation.length;


var infLoopStop=false;
var infLoop=null;
var quoteblock = document.getElementById('quote');

quoteblock.style.opacity = 0/10;


var whichQuotation=Math.round(Math.random()*(Q-1));

var quoteCount=x.length-1;

infLoop=function(){
 
//var whichQuotation=Math.round(Math.random()*(Q-1));

var replace = "<i>" + '"' +  Quotation[whichQuotation] + '"' + "</i><br><b>&mdash;" + Author[whichQuotation] + "</b>";

function showQuotation(){quoteblock.innerHTML = replace}

showQuotation();

setTimeout("fade('quote')", 1000);

setTimeout("fade('quote')", 12000);

if (whichQuotation<quoteCount){
whichQuotation++;
}else{
whichQuotation=0;
};
setTimeout('infLoop()', 13000);

};

infLoop();


