pudsey = {
	init:function(){
		var links = glow.dom.get(".promo-large a");
		var images = glow.dom.get(".promo-large img");
		
		pudsey.linkToUpdate = links[0];
		
		for (var i = 0; i < images.length; i++){
			pudsey.images[i] = images.slice(i, i+1).attr("src");
			pudsey.alts[i] = images.slice(i, i+1).attr("alt");
			pudsey.links[i] = links.slice(i, i+1).attr("href");			
		}
		
		
		
		pudsey.fadeImages();
		
	},
	firstImage:true,
	currentIndex:0,
	images:[],
	links:[],
	alts:[],
	fadeImages:function(){
		var events = glow.events,  
		img = glow.dom.get(".slide"),  
		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();
			pudsey.updateLink();
		}); 
		
		events.addListener(imgFadeOut, "complete", function() {
			var totalImages = pudsey.images.length;
			
			if (pudsey.currentIndex < totalImages - 1) {
				pudsey.currentIndex++
			} else {
				pudsey.currentIndex = 0;
			}
			img[0].src = pudsey.images[pudsey.currentIndex];
			img[0].alt = pudsey.alts[pudsey.currentIndex];
		}); 
		
		setInterval(function() { 
			imgFadeOut.start();
			}, 6000);
	},
	updateLink:function(){ pudsey.linkToUpdate.href = pudsey.links[pudsey.currentIndex]; }
}
glow.ready(pudsey.init);