/* Datalinks Fader Widget */
var fader = Class.create();
fader.prototype = {
	initialize: function(fact1,image1,fact2,image2,fact3,image3) {
		this.facts=new Array;
		this.images=new Array;
		// Excuse this...
		this.facts[0]=fact1;
		this.facts[1]=fact2;
		this.facts[2]=fact3;
		this.images[0]=image1;
		this.images[1]=image2;
		this.images[2]=image3;
		this.currentImgFact=0;
		// And this...
		this.imageId=$("kv_mainImage");
		this.factId=$("kv_fact");
	},
	animate: function() {
	    // Step 1
	    // Start the animate out, update, animate in process...
	    this.animateOut();
	},
	animateOut: function() {
	    // Step 2
	    // Fade out and then call updateOutputs
	    new Effect.Opacity(this.factId,{duration:.5,from:1.0,to:0.0,fps:60});
	    new Effect.Opacity(this.imageId,{duration:.5,from:1.0,to:0.0,afterFinish:this.updateOutputs.bind(this),fps:60});
	},
	updateOutputs: function() {
	    // Step 3
	    fact=this.facts[this.currentImgFact];
	    image=this.images[this.currentImgFact];
	    Element.update(this.factId,fact);
	    Element.update(this.imageId,image);
	    this.currentImgFact++;
	    if (this.currentImgFact>=this.facts.length) {
			this.currentImgFact=0;
		}
		// Finally, animate it back in
		this.animateIn();
	},
	animateIn: function() {
	    // Step 4
   	    new Effect.Opacity(this.factId,{duration:.5,from:0.0,to:1.0,fps:60});
   	    new Effect.Opacity(this.imageId,{duration:.5,from:0.0,to:1.0,fps:60});
	}
};