var GetLiveData = new Class ({


	initialize: function (el, dataURL, options) {
		this.boolFlag = 1;
		this.element 	= el;
		this.dataURL	= dataURL;
		this.options = {
			linkPrefix 			: '',
			loadingMinHeight	: '',
			loadingBgImage		: ''
			};
		Object.extend(this.options, options || {});

		// start refreshing data
		//{$clear (this.refreshDataTimer);}
		//this.idxCount=0;
		this.refreshData();
		//if(this.idxCount < 6){
			this.refreshDataTimer = this.refreshData.periodical (10000, this);
		//}
		},


	refreshData: function () {
		// clean up the list
		//this.idxCount++;
		if(this.boolFlag!=1){
			return false;
		}

		this.boolFlag=0;
		this.blank ();
/*
		new Element ('div').setStyles({
			height				: this.options.loadingMinHeight,
			backgroundImage		: this.options.loadingBgImage
		});
*/

		var populateLists = this.populateLists.bind(this);
		var showError = this.showError.bind(this);

		this.getJSON = new Ajax (
			this.dataURL,
			{
			onComplete: populateLists,
			onFailure: showError,
			onStateChange: showError,
			headers: {'Referer': 'http://www.1001homes.co.uk'}
			}).request();
	},


	populateLists: function (responseText, responseXML) {

		var oListJSON;

		this.boolFlag=1;

		try {
			oListJSON = Json.evaluate(responseText);
		} catch (err) {
			oListJSON = Json.evaluate('[]');
		}

		// clean up the loading animation
		this.blank ();

		// see if we don't have any data and display an error
		if (!oListJSON[0]) { this.showError(); return false; }

		// populate the list
		oListJSON.each (
			function (li) {
				new Element('a').setHTML(li['Expression'] || li['Name']).setProperty(
						'href', (li['URL']) ? li['URL'] : this.options.linkPrefix + escape(li['Expression'])
					).injectInside(
							new Element('li').injectInside (this.element)
						);
			}.bind(this)
		);

		this.getJSON = null;
	},

	showError: function () {

		try {
			if((this.getJSON.transport.readyState != 4) || (this.getJSON.transport.status == 200)) return;
		} catch(e) {}

	},

	blank: function () {
		this.element.setHTML ('');
	}
});