heroes = {
	init:function(){
		
		var links = glow.dom.get("#main-promo a");
		var images = glow.dom.get("#main-promo img");
		
		heroes.linkToUpdate = links[0];
		
		for (var i = 0; i < images.length; i++){
			heroes.images[i] = images.slice(i, i+1).attr("src");
			heroes.alts[i] = images.slice(i, i+1).attr("alt");
			heroes.links[i] = links.slice(i, i+1).attr("href");			
		}
		
		
		
		heroes.fadeImages();
		
	},
	firstImage:true,
	currentIndex:0,
	images:[],
	links:[],
	alts:[],
	fadeImages:function(){
		var events = glow.events,  
		img = glow.dom.get("#promo, #promo2, promo2"),  
		imgFadeIn = glow.anim.css(img, 1, {opacity: {from:0, to:1}}),
		imgFadeOut = glow.anim.css(img, 1, {opacity: {from:1, to:0}});


		
		events.addListener(img, "load", function() {  
			imgFadeIn.start();
			heroes.updateLink();
		}); 
		
		events.addListener(imgFadeOut, "complete", function() {
			var totalImages = heroes.images.length;
			
			if (heroes.currentIndex < totalImages - 1) {
				heroes.currentIndex++
			} else {
				heroes.currentIndex = 0;
			}
			img[0].src = heroes.images[heroes.currentIndex];
			img[0].alt = heroes.alts[heroes.currentIndex];
		}); 
		
		
		setInterval(function() { 
			imgFadeOut.start();
			}, 6000);
			
			
	},
	
	updateLink:function(){
			heroes.linkToUpdate.href = heroes.links[heroes.currentIndex];
		
		

	
	}
}
glow.ready(heroes.init);