var xsltSheet;

// show Indicator
function showIndicator()
{
	with($('indicator'))
	{
		update('');
		show();
	}
}

//hide Indicator
function hideIndicator()
{
	$('indicator').hide();
}
// initpage
function initPage()
{
	new Ajax.Request('Flux_Audetperle/xsl/breves.xsl', {
		method: 'get',
		indicator: 'indicator',
		onSuccess: function(requester) {
			xsltSheet = xmlParse(requester.responseText);
			getFeed();
		}
	});
}

FEED_URL = 'http://www.audetperle.fr/flux.xml';

function getFeed()
{
	$('conteneur_actu_audetperle').update('');
	showIndicator();
	new Ajax.Request('Flux_Audetperle/getrss.php', {
		method: 'get',
		parameters: 'url=' +encodeURIComponent(FEED_URL),
		onFailure: hideIndicator,
		onSuccess: function(requester) {
			$('indicator').update('Mise en forme&#8230;');
			var tmr = window.setTimeout(function(){
				window.clearTimeout(tmr);
				var data = xmlParse(requester.responseText);
				var html = xsltProcess(data, xsltSheet);
				$('conteneur_actu_audetperle').update(html);
				hideIndicator();
			}, 10);
		}
	});
}
RE_TITLE = '(<a .*?>)Client Web\\s*(.*?)(</a>)';
RE_TIMESTAMP = '(<span class="timestamp">)(.*?)(</span>)';

function adjustData(html)
{
	var html = html.gsub(RE_TIMESTAMP, function(match)
		{
			match[2] = new Date(match[2]).toLocalString();
			return match[1] + match[2] + match[3];
		});
	html = html.replace(new RegExp(RE_TITLE, 'img'), '$1$2$3');
	return html;

}
 function closeWindow()
 {
	new Effect.toggle('text_audetperle_flux','blind');
 }

Ajax.Responders.register({onException: function(requester, e) {
	$('indicator').hide();
	alert(e);
}});


Event.observe(window, 'load', initPage);

