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

TRPADV.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 d\'avis pour le moment !');
				}
			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+'_title"></strong></a><br /><span id="'+this.name+'_description"></span></p>';
				this.setFirstItem();
				}
			}
		};

TRPADV.loadCurrentItem = function()
		{
		// title
		document.getElementById(this.name+'_title').innerHTML=this.data[this.current].title;
		// navigation
		document.getElementById(this.name+'_prev').setAttribute('href','javascript:TRPADV.goPreviousItem();');
		document.getElementById(this.name+'_next').setAttribute('href','javascript:TRPADV.goNextItem();');
		document.getElementById(this.name+'_count').innerHTML=this.getCurrentCount();
		// description
		document.getElementById(this.name+'_description').innerHTML=this.data[this.current].description;
		// link
		document.getElementById(this.name+'_link').setAttribute('href',this.data[this.current].link);
		};

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