/*
 * Espace curieux
 */
toutou.require("toutou.html.dom");
toutou.require("toutou.js.ajax");
toutou.require("toutou.effect.fade");

if(typeof js == "undefined") {
	js = {};
	js.imgPath = "";
}

js.curieux = new function() {
	this.requestUri	   = "/php/view_curieux.php";
	this.index = 0;	
	this.fade_duration=500;
	this.eventData = null;
	
}

js.curieux.callback_ajax = function(eventData){
	var zone_curieux = tt$('zone_curieux');

	//On active la fonctionalit� fade
	toutou.effect.fade.extend(zone_curieux);
	
	
	
	//Et on fade, en precisant o� on veux aller apr�s
	//zone_curieux.tt_effect.fade.fadeOut(this.fade_duration,function() { js.curieux.callback_fade(eventData)});
	js.curieux.callback_fade(eventData);
}

js.curieux.callback_fade = function(eventData){
	var zone_curieux = tt$('zone_curieux');
	
	//On decompact les donn�es
	var data = eval('('+ eventData.xhr.getResponseText()+')');
	
	var output = "";
	
	var i = 0;
	while(i < data.length) {
		output+="<div class='espaceCurieuxListe'>\n";
		output+="<a title='"+data[i].titre+"' href='"+data[i].nom_url+"'><img alt='"+data[i].titre+"' border='0' src='"+data[i].vignette+"'/></a>\n";
		output+="<span>"+data[i].annee+"&nbsp;-&nbsp;"+data[i].nationalite+"</span>\n";
		output+="<span class='nouveau'>";
		if (data[i].nouvaute==1){
			output+="<img class='nouveau' src='imgT/btn_nouveau_blanc.gif'/>";
		}
		output+="&nbsp;</span>";
		output+="</div>\n";
		i++;
	}
	zone_curieux.innerHTML = output;
	
	//zone_curieux.tt_effect.fade.fadeIn(1);
}

js.curieux.deplace = function(number /*int*/,is_home /*bool*/){
	//Number of elements to get
	var to_get = Math.abs(number);
	if (to_get>4){
		to_get = 4;
	}
	//update index
	this.index+=number;
	
	xhr = new toutou.js.ajax.xhr(); 
	
	xhr.asynchronous=true;
	
	//Set the url
	xhr.url = this.requestUri;
	
	xhr.method = "post";
	
	//And the parameters
	xhr.parameters = "method=view&index="+this.index+"&to_get="+to_get;
	
	//Set up a callback for onOK
	xhr.tt_eventManager.addListener("success", js.curieux.callback_ajax);
	
	
	xhr.request(); 	
}