
var Twitter = Class.create();
Twitter.prototype = {

	//
	//  Setup the Variables
	//

	containerElm : null,
	errorCount : 0,


	//
	//  Initialize the accordions
	//
	initialize: function(options) {


//	    console.info(options);

	    this.options = Object.extend({
	      cid : 8,
	      containerSelector : '#twitterFeed p'
	    }, options || {});


	    document.observe('dom:loaded', this.start.bind(this));

	},



	start : function(){

	    this.containerElm = $$(this.options.containerSelector).first();

	    var url = 'index.php';
	    var params = 'eID=twitter&cid=' + this.options.cid;
	    var myAjax = new Ajax.Request(url, {method: 'get', parameters: params, onComplete: this.feedOnLoad.bindAsEventListener(this)});
	},


	feedOnLoad : function(request){

	    var json = request.responseText.evalJSON(true);


	    if(json.error != false){
		if(this.errorCount > 10) {
		    this.containerElm.innerHTML = json.error;
		} else {
		    this.errorCount++;

		    this.containerElm.innerHTML = this.containerElm.innerHTML + ' .';

		    window.setTimeout(this.start.bind(this), 1000);
		}

	    } else {
		this.containerElm.innerHTML = json.content;
	    }


	},


	dummy : function(){
	}
}








