var promos = new Array(
    ["images/promos/envirothon_padre.jpg", "The Envirothon club visited Padre Island in March 2009 to compete and clean the beaches."],
    ["images/promos/wethepeople.jpg", "John Tyler Students compete in Austin for &quot;We The People&quot; in December 2009."],
    ["images/promos/physicsday_reaction.jpg", "John Tyler students react to the Runaway Mine train during Physics Day at Six Flags Over Texas."],
    ["images/promos/tisdfound_jt.jpg", "John Tyler's Jim Bybee, Jimmie Osteen, and Linda Boyter win TISD Foundation grants for their proposals to improve student education."],
    ["images/promos/henry_todd_dedicate.jpg", "In loving memory of Todd Henry, John Tyler Teacher, 1959 - 2009"],
    ["images/promos/slaughter_totm.jpg", "James Slaughter chosen as Teacher of the Month for Tyler ISD."],
    ["images/promos/jrotc_field.png", "John Tyler JROTC serving at a local football game."],
    ["images/promos/luiscierra_honored.jpg", "John Tyler Seniors, Luis Tierrablanca and Cierra Thomas, are pictured with Rotarian, Mr. Jim Robertson."],
    ["images/promos/cleanup_envirothon.jpg", "Envirothon Club cleans up local creeks and roadways."],
    ["images/promos/GoBus_UTT.jpg", "UT Tyler Go Bus visits campus to help AVID students prepare for college."]
    // Please omit the final comma after the ] from the last line above unless you are going to add another event at this time.
);

var currentPromoIndex = Math.round(Math.random()*(promos.length-1));
var promoPreload = null;
function prepPromos(){
	promoPreload = new Array(promos.length);
	for (var i = 0; i < promoPreload.length; i++){
		var img = new Image();
		img.src = promos[i][0];
		promoPreload[i] = img;
	}
}

function cyclepromo() {
	if (promoPreload == null) prepPromos();
	
    if (currentPromoIndex > promos.length-1)
      currentPromoIndex = 0;
      
    var speed = 10; 
    var timer = 0; 
     
    var imageDiv = document.getElementById('promoImage');
    
    if (imageDiv.innerHTML != '') {
        //set the current image as background 
        imageDiv.style.backgroundImage = "url(" + document.getElementById('promoImageImg').src + ")"; 
        
        //make image transparent 
        changeOpacity('promoImageImg', 0); 

        //make new image 
        document.getElementById('promoImageImg').src = promos[currentPromoIndex][0]; 
        
        //fade in image 
        for(i = 0; i <= 99; i++) { 
            setTimeout("changeOpacity('promoImageImg', " + i + ")",(timer * speed)); 
            timer++; 
        }        
    } else {
        imageDiv.innerHTML = '<img style="z-index:0" id="promoImageImg" src="'+promos[currentPromoIndex][0]+'" />';
    }
    
    document.getElementById('promoCaption').innerHTML = promos[currentPromoIndex][1];
    currentPromoIndex++;
}




