
function GICBanner(domnode) { 

	this.domNode = domnode;
	//this.domNode.style.position = 'absolute';
	
	this.msForFadein = 500;
	this.msForFadeout = 500;
	
	this.fadeIn = fadeIn;
	this.fadeOut = fadeOut;
	
	function fadeIn() {
	
		var i;
	
		// kijken of er een img tag is
		var images = this.domNode.getElementsByTagName('IMG');
		
		for(i=0;i<images.length;i++) {
			if ($(images[i]).getProperty('rel')) {
				$(images[i]).src = $(images[i]).getProperty('rel');
				$(images[i]).removeProperty('rel');
			}		
		}
		
		// kijken of er een dd tag is
		var dds = this.domNode.getElementsByTagName('DD');
		for(i=0;i<dds.length;i++) {
			if ($(dds[i]).getProperty('movie')) {
				var FO = {movie:$(dds[i]).getProperty('movie'),majorversion:"7",width:$(dds[i]).getProperty('moviewidth'),height:$(dds[i]).getProperty('movieheight'),build:"0",bgcolor:"#FFFFFF",allowfullscreen:"false"};
				UFO.create(	FO, $(dds[i]).id);	
				$(dds[i]).removeProperty('movie');
			}		
		}
		
		this.domNode.style.display='block';
		new Fx.Style(this.domNode, 'opacity',
				{duration:this.msForFadein}
	   	).start(0,1);
	}
	
	function fadeOut() {
	
		new Fx.Style(this.domNode, 'opacity',
				{duration:this.msForFadeout,
				 onComplete:
	   				function() {
		    			this.domNode.style.display='none';
		    		}.bind(this)
		    	}
	   	).start(1,0);
	}
	
}

var GICBannerAnimation = {

	msForPause: 15000,

	bannerContainers : [],

	init: function() {

		GICBannerAnimation.bannerContainers = $$('.bannercontainer');
		
		GICBannerAnimation.bannerContainers.each(function(container) {
		
			container.style.position = 'relative';
		
			container.banners = [];
/*		
			container.getElementsByClassName('banner').each(function (domnode) {
				container.banners.push(new GICBanner(domnode));
			});
*/
			var els = container.getElementsByClassName('banner');
			for(var i = 0; i < els.length; i++)
			{
				container.banners.push(new GICBanner(els[i]));
			}

			container.currentBannerIndex = -1;
			
		});
		
		window.setTimeout("GICBannerAnimation.rotateBanners();", this.msForPause);
		
	},

	rotateBanners : function() {
	
		GICBannerAnimation.bannerContainers.each(function(container) {
		
			if (container.banners.length > 1) { // bij maximaal 1 banner hoeven we natuurlijk niet te animeren
			
				var isFirstGo = container.currentBannerIndex == -1;
			
				if (!isFirstGo) {
					// verberg de huidige banner
					container.banners[container.currentBannerIndex].fadeOut();
				} 
					
				container.currentBannerIndex++;
				if (container.currentBannerIndex == container.banners.length)
					container.currentBannerIndex = 0;
				
				if (!isFirstGo) {
				
					window.setTimeout(			
						container.banners[container.currentBannerIndex].fadeIn.bind(container.banners[container.currentBannerIndex]),
						container.banners[container.currentBannerIndex].msForFadeout
						);
				}
				
			}
			
		});
		
		window.setTimeout("GICBannerAnimation.rotateBanners();", GICBannerAnimation.msForPause);
	}

};

window.addEvent('domready', GICBannerAnimation.init);

