var WebtvClipsNav;

WebtvClipsNav = function ()
{
	this.init = function ()
	{
		this.prepare_buttons();
		Wlog('webtv.clipsnav:: init');
	};
	
	this.prepare_buttons = function ()
	{
		Event.observe('clipLeft', 'click', this.navigate.bind(this));
		Event.observe('clipRight', 'click', this.navigate.bind(this));
	};
	
	this.navigate = function (evt)
	{
		Event.stop(evt);
		var target = '';
		try{
			target = Event.element(evt).getAttribute('href');
		}catch(e){Wlog('webtv.clipsnav:: cannot retrieve href of '+Event.element(evt));}
		if(target.length > 0){
			target = (settings.base ? settings.base+'wdata'+target.substr(settings.base.length-1):target) + 'clipsnav/';
			new Ajax.Request(target, {
				method: 'get',
				onSuccess: function (tr)
				{
					var resp = tr.responseText.evalJSON();
					try{ 
						$('clips').update(resp.clips_html);
						try{
							$('clip_'+settings.curr_clip.id).parentNode.addClassName('active');
						} catch(e){}
						try{
							$('clipLeft').setAttribute('href', resp.back_link);
							$('clipRight').setAttribute('href', resp.next_link);
						} catch(e){}
					} catch(e){}
				}.bind(this),
				onFailure: function ()
				{/* handle errors */}.bind(this)
			});
		}
	};
};

try{
	Webtv.prototype.clipsnav = new WebtvClipsNav();
	Webtv_reg.push('clipsnav');
	Wlog('webtv.clipsnav:: bound');
}
catch(e){
	Wlog('webtv.clipsnav:: could not bind myself');
}
