var TWT = new ajax_widget();
TWT.initWidget = function()
	{
	this.container=document.getElementById('twitter');
	this.name='twitadv';
	this.content=document.getElementById(this.name);
	};
TWT.initConfig = function(values)
		{
		this.config['source_url']= (values[0]?values[0]:'');
		this.config['update_browser'] = (values[1]&&values[1]!='false'?values[1]:false);
		};
TWT.requestData = function()
		{
		var path = "http://pipes.yahoo.com/pipes/pipe.run?_cmd=Run+Pipe&_run=1&_render=json&_callback=TWT.handleResponse";
		path += "&_id=fGioS5Nv3BGXpvaGxAnzeQ&url=" + escape(this.config['source_url']);
		this.requestJSonData(path);
		};

TWT.handleResponse = function(rsp)
		{
		if ((!rsp.count)&&rsp.count!==0)
			{
			this.error(rsp);
			}
		else
			{
			if(rsp.count>0)
				{
				this.data = rsp.value.items;
				}
			else
				{
				this.notice('Pas de twitt pour le moment, ajoutez-en !');
				}
			if(this.data)
				{
				this.content.innerHTML='<p><span id="'+this.name+'_nav"><a href="#" id="'+this.name+'_prev">&lt;</a> <span id="'+this.name+'_count">0/0</span> <a href="#" id="'+this.name+'_next">&gt;</a></span><br /><a href="#" id="'+this.name+'_link" onclick="window.open(this.href); return false;"><strong id="'+this.name+'_author"></strong></a> : <span id="'+this.name+'_message"></span></p>';
				this.setFirstItem();
				}
			}
		};

TWT.loadCurrentItem = function()
		{
		// title
		document.getElementById(this.name+'_author').innerHTML='@'+this.data[this.current].author.name.split(' ')[0];
		// navigation
		document.getElementById(this.name+'_prev').setAttribute('href','javascript:TWT.goPreviousItem();');
		document.getElementById(this.name+'_next').setAttribute('href','javascript:TWT.goNextItem();');
		document.getElementById(this.name+'_count').innerHTML=this.getCurrentCount();
		// description
		document.getElementById(this.name+'_message').innerHTML=this.data[this.current].description;
		// link
		document.getElementById(this.name+'_link').setAttribute('href',this.data[this.current].author.uri);
		};

if(window.addEventListener)
	{
	window.addEventListener('load', function() { TWT.init(); }, false);
	}
else if(window.attachEvent)
	{
	window.attachEvent('onload', function() { TWT.init(); }, false);
	}