window.addEvent('domready', function() {

	// Gestion de l'avant match
	var am = new Request.HTML({url:'score_am.txt',
		method: 'get',
		noCache: 'true',

		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('log').set('text', '');
			//Inject the new DOM elements into the results div.
			$('log').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('log').set('text', 'Erreur de la requête Avant Match.');
		}
	});

	// Gestion de la feuille de partie
	var fp = new Request.HTML({url:'score_fp.txt',
		method: 'get',
		noCache: 'true',
		initialDelay: 0,
		delay: 30000,
		limit: 45000,

		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('log').set('text', '');
			//Inject the new DOM elements into the results div.
			$('log').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('log').set('text', 'Erreur de la requête Feuille de Partie.');
		}
	});

	// Gestion de la partie en cours
	/*
	var pc = new Request.HTML({url:'content_pc.txt',
		method: 'get',
		noCache: 'true',
		initialDelay: 0,
		delay: 5000,
		limit: 15000,

		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('log').set('text', '');
			//Inject the new DOM elements into the results div.
			$('log').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('log').set('text', 'Erreur de la requête Partie en cours.');
		}
	});
	*/
	
	// Tabs management: Avant match
	$('tab_1').addEvent('click', function(event){
    	event.stop(); //Prevents the browser from following the link.
    	fp.stopTimer();
    	//pc.stopTimer();
    	am.send();
	});

	// Tabs management: Feuille de partie
	$('tab_2').addEvent('click', function(event){
    	event.stop(); //Prevents the browser from following the link.
    	//pc.stopTimer();
    	fp.startTimer();
	});

	// Tabs management: Partie en cours
	/*
	$('tab_3').addEvent('click', function(event){
    	event.stop(); //Prevents the browser from following the link.
    	fp.stopTimer();
    	pc.startTimer();
	});
    */
    
	// Affichage de l'Avant Match
	am.send();

});
