// Freestyler Breaking News Widget

// Custom transition...
Effect.Transitions.slowstop = function(pos) {
  return 1-Math.pow(0.5,20*pos);
}

var fs_breakingNews = Class.create();
fs_breakingNews.prototype = {
	initialize: function(sourceId,outputId) {
	    // Where we are soucing the headlines themselves
		this.sourceId=sourceId;
		// Where we want to output them
		this.outputId=outputId;
		// Headline class...
		this.headlineClass="fs_bnHeadline";
		this.headlinePos=0;
		this.headlinesArray=new Array;
		this.headlinesArray=document.getElementsByClassName(this.headlineClass,this.sourceId);
	},

	animateIn: function() {
		// Move in from the right
	    new Effect.MoveBy(this.outputId,0,-800,{duration:2,transition:Effect.Transitions.slowstop,fps:60});
	},

	animateOut: function() {
	    // Once the animate out is complete, remember to call the updateOutput
		// function to replace the current headline with a new one...
	    // Move out to the right;
		new Effect.MoveBy(this.outputId,0,800,{duration:.5,afterFinish:this.updateOutput.bind(this),fps:60});
	},

	animate: function() {
	    // Fade out first...
		this.animateOut();
  	},
  	
  	updateOutput: function() {
  	    // Get our headline
  		headline=this.headlinesArray[this.headlinePos].innerHTML;
		// Update the output div
		Element.update(this.outputId,headline);
		// Move to the next headline
		this.headlinePos++;
		if (this.headlinePos>=this.headlinesArray.length) {
		    this.headlinePos=0;
		}
		this.animateIn();
	}
};