 var xmlDoc;
 var quotesArray = new Array();
 
function loadxml()
{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = readXML;
		xmlDoc.load("/modules/quotes/quotes.xml");
}

function readXML()
{
       	var texts = xmlDoc.getElementsByTagName('quote');
       	
        for (x=0; x < (texts.length-1); x++)
        {
	        quote = new Array(2);
	        
	        quote[0] = texts[x].childNodes[1].textContent;
	        quote[1] = texts[x].childNodes[3].textContent;	
	        
	        quotesArray.push(quote);
        }
         fadeIn();
}

function fadeOut()
{
	var fadeInA = setTimeout("fadeIn()", 1000);
	opacity("quoteContainer", 100, 0, 500);
}

function fadeIn()
{
	pickQuote();
	var fadeOutA = setTimeout("fadeOut()", 6000);
	opacity("quoteContainer", 0, 100, 500);
}

function pickQuote()
{
	var choosenQuote = ((Math.random() * (quotesArray.length)));
	choosenQuote = (Math.round(choosenQuote));
	
	if (choosenQuote >= quotesArray.length)
	{
		choosenQuote = ((quotesArray.length) - 1);
	}
	
	if (choosenQuote < 0)
	{
		choosenQuote = 0;
	}
	
	var quoteDiv = document.getElementById('quoteContainer');	
	quoteDiv.innerHTML = '<div id="quoteText">'+ quotesArray[choosenQuote][0] +'</div><div id="quotePerson">'+ quotesArray[choosenQuote][1] +'</div>';
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 