var FadeManager = Class.create();

FadeManager.prototype = {
	items_to_fade : null,
  current_item : null,
  previous_item : null,

	initialize : function() {
		this.items_to_fade = new Array('fade-0', 'fade-1', 'fade-2', 'fade-3', 'fade-4');
		this.current_item = 0;
		this.previous_item = 0;
		setInterval(this.swapFade.bind(this), 6000);
	},
	
	swapFade : function() {
		this.previous_item = this.current_item;
		this.current_item++;
		if (this.current_item == this.items_to_fade.length) this.current_item = 0;

		if (this.current_item == 0) {
			setTimeout(this.adjustZIndex.bind(this), 4000);
			$(this.items_to_fade[this.current_item]).style.zIndex = 10;
		}

		setTimeout(this.hideOld.bind(this), 3000);
		Effect.Appear(this.items_to_fade[this.current_item], { duration:1.5, from:0.0, to:1.0 });
	},
	
	hideOld : function(index) {
		$(this.items_to_fade[this.previous_item]).hide();
	},
	
	adjustZIndex : function(index) {
		$(this.items_to_fade[this.current_item]).style.zIndex = 2;
	}
}

function startPage() {
	var pageFadeManager = new FadeManager();
}