/*  liveHeadline Class, version 1
 *   Lambert Torres
 * modified from the original liveData Class	
 *  (c) 2005 Andrew Weir <andrew@ajaxlessons.com>
 *
 *  For details, visit Ajax Lessons: http://ajaxlessons.com
 *
/*--------------------------------------------------------------------------*/
PeriodicalExecuter.prototype.registerCallback = function() {
	this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
}
var num =0;
var liveHeadline = Class.create();
liveHeadline.prototype = {
	pe: 0,
	headLineId : 0,
	url    : '/frags/finals2006/finals2006LiveHeadline.html',
	interval: 60,
	initialize: function () {
		this.getData();
		this.pe = new PeriodicalExecuter(this.getNewData.bind(this), this.interval);
	},
	fillHolder: function (request) {
		$('liveHeadline').innerHTML = request.responseText;
	},
	getData: function(){
		var rand   = Math.random(9999);
		var pars   = 'rand=' + rand;
		new Ajax.Updater('liveHeadline', this.url, {method:'get', parameters: pars, evalScripts : true} );
		new Effect.Highlight('liveHeadline',{startcolor:'#ffff99',endcolor:'#E29E00'}); 
		
	},
	getNewData: function () {
		var showNewData = this.showNewData.bind(this);
		var rand   = Math.random(9999);
		var pars   = 'rand=' + rand;
		var myAjax = new Ajax.Updater( { success: null }, this.url, {method: 'get', parameters: pars, onComplete: showNewData, evalScripts :true} );
	},
	showNewData: function (originalRequest) {
		var newHeadLine = originalRequest.responseText;
        if (this.headLineId != num){
			$('liveHeadline').innerHTML = originalRequest.responseText;
			Element.setOpacity('liveHeadline', 0.0);  
        	Effect.Appear('liveHeadline', { duration: 0.7 });				
			new Effect.Highlight('liveHeadline', {startcolor:'#ffff99',endcolor:'#E29E00'}); 
		}
		this.headLineId = num;
	}
};

var manualUpdate = function(){
	//console.log('manual update');
	var rand   = Math.random(9999);
	var pars   = 'rand=' + rand;
    Element.setOpacity('liveHeadline', 0.0);  
    Effect.Appear('liveHeadline', { duration: 0.7 });				
	new Ajax.Updater('liveHeadline', '/frags/finals2006/finals2006LiveHeadline.html', 
	{	method:'get', parameters: pars, evalScripts : true });
	new Effect.Highlight('liveHeadline',{startcolor:'#ffff99',endcolor:'#E29E00'});
};



