// LETREIROS

//Setup Arrays that will hold the x,y,z of each element.
var x = new Array();
var y = new Array();
var z = new Array();

//Get the list of items.
var items = $('li');
var iPalavra = 0;
var palavra = items[iPalavra];
var mudaPalavra = false;

//Animate the items.
function animate()
{

    //Step through each item.
    //for(i = palavra.length - 1; i >= 0; i--){
	mudaPalavra=false;

	i = iPalavra;

        //variables for movement.
        var xVar = 0 + x[i]             // x value
        x[i] *= 1.07;
        var yVar = 15 + y[i] * z[i]++;  // y value, move towards bottom of screen
        var zVar = 30 * z[i]++;         // z value, text get larger.


        //Check to see if text position is still on the screen.
        // the #'s are %.   100 is far right or bottom, 0 is top or left.
        // for z value it's the font size in %.
        if (!xVar | xVar < 0 | xVar > 50|
            yVar < 0 | yVar > 50 |
            zVar < 0 | zVar > 500)
        {
        	if(xVar!=0  && yVar!=0 && zVar!=0) {
        		mudaPalavra = true;
        	}
            //if it's off the screen randomly pick a starting place.
//            x[i]= Math.random() * 2 - 1;
//            y[i] = Math.random() * 2 - 1;
//            x[i]= Math.random() + 1;
//            y[i] = Math.random() + 1;
            x[i] = 10;
            y[i] = 1.6;
            z[i] = 2;

        }
        else
        {
            //if it's still on the screen apply the appropiate styles.

            $(items[i]).css("position", "absolute"); // make sure we can move the text around.
            $(items[i]).css("top", yVar+"%");  // y value
            $(items[i]).css("left", xVar+"%"); // x value

            $(items[i]).css("fontSize", zVar+"%"); // font size (illusion of perspective.)
            // $(items[i]).css("opacity",(zVar)/3000); // fade in from the distance.
            $(items[i]).css("display","block");
        }
    // }

	tempoProxExec = parseFloat($(items[iPalavra]).css("top"))  * 3;
	if(mudaPalavra) {

	    $(items[iPalavra]).css("display","none");

		if(iPalavra == items.length - 1) {
			iPalavra = 0;
		} else {
			iPalavra++;
		}
		palavra = items[iPalavra];
		var mudaPalavra = false;
		tempoProcExec = 0;
	} else {
		tempoProcExec = 561;
	}
	setTimeout(animate, tempoProcExec);

}

$(function() {
animate();
});

