ALGetAjax = Class.create();

ALGetAjax.prototype = {
	
	initialize : function(ln) {
				
		this.rand = Math.floor(Math.random()*10000);
		this.lang = ln;
		this.url = 'ice2_status_new.php?random=' + this.rand;
//		this.url = 'http://www.radiotangra.com/ice2_status_new.php?random=' + Math.floor(Math.random()*101);
	  	this.init();
  	},
  	
  	init: function()
  	{
  		this.ajaxRequest('init');
  		
  	},
  	
  	ajaxRequest: function(command)
  	{
  		this.command = command;
  		$('bandName').innerHTML = "";
  		new Ajax.PeriodicalUpdater('', this.url,   
  		{     
  			method: 'post',     
  			insertion: Insertion.Bottom,     
  			frequency: 15,     
  			decay: 1,
  			onSuccess: this.succFunc.bind(this),
  			onFailure: this.failFunc.bind(this) 
  		});
  		 
 	},
	
  	succFunc: function (transport) 
	{
		var self = this;
		var json = eval(''+transport.responseText+'');

		if (!json)
		{	
			$('bandName').innerHTML = "<b>&nbsp;Tangra</b>";
			$('songName').innerHTML = "<b>&nbsp;Mega Rock</b>";
//			this.errMsg("No JSON Object!");
			return 0;		
		}

		$('bandName').innerHTML = "<b>&nbsp;"+json.band+"</b>";
		$('songName').innerHTML = "<b>&nbsp;"+json.title+"</b>";
		
	},

	failFunc: function ()
	{ 	
//		alert('fail');
		$('bandName').innerHTML = "<b>&nbsp;Tangra</b>";
		$('songName').innerHTML = "<b>&nbsp;Mega Rock</b>";
		
//		this.errMsg('Ajax Request Failed!');
	},
	
	errMsg: function (text)
	{ 	
		alert(text);
	}
}
