var src_aPlusPartager=new Array();
var plusPartagerData;
var Class_PlusPartager=function(_oParam, _nbRecord) {
		this.id=src_aPlusPartager.length;
		this.initState=false;
		this.isInitDisplay=true; /// utilisr seulment pour contrôler les stats [voir : onLoad,onOngletClick,onDayClick] - BRovito - 12-02-2009
		this.nbDay=0;
		this.vue=2;
		this.idBarActif="barDay_0_"+this.id;
		this.idOngletActif="onglet_0_"+this.id;
		this.aDay=[0,1,6,29];
		this.instId="blockPlusPartager_"+this.id;
		this.instIdRes="plusPartagerResult_"+this.id;
		this.oParam=$defined(_oParam)?_oParam:new Object();
		this.drawPlusPartager();
		this.init();
		this.ass=[20,21,26,229,10,11,16,129];
		this.nbRecord= _nbRecord;
		this.data=new Array();
		this.scr = null;
	};
Class_PlusPartager.prototype = {
	drawPlusPartager : function(){
		document.write('\n<div class="src_nouvellesPartager" id="'+this.instId+'">\n<ul class="onglets">\n<li><a href="javascript:;" id="onglet_0_'+this.id+'"  class="actif" >nouvelles les plus partag&eacute;es</a></li>\n<li><a href="javascript:;" id="onglet_1_'+this.id+'" >nouvelles les plus consultées</a></li></ul>\n<div class="listePartager">\n<ul class="sousOnglets">\n<li class="unjour"><a href="javascript:;"  id="barDay_0_'+this.id+'"   class="actif">24 heures</a></li>\n<li class="deuxjours"><a href="javascript:;"  id="barDay_1_'+this.id+'" >48 heures</a></li>\n<li class="septjours"><a href="javascript:;"   id="barDay_2_'+this.id+'"  >7 jours</a></li>\n<li class="trentejours"><a href="javascript:;" id="barDay_3_'+this.id+'"   >30 jours</a></li></ul>\n<div>	<ul id="'+this.instIdRes+'"><h3>Chargement...</h3></ul>	</div></div>');
	
	},
	init:function(){
		$$("#"+this.instId+" .onglets a").each(function (_oha,i){
			_oha.addEvent('click', function(e){
				var _id=this.parentNode.parentNode.parentNode.id.split("_")[1];
				src_aPlusPartager[this.id.split("_")[2]].onOngletClick(this.id,i);
				return false;
			});
		});
		$$("#"+this.instId+" .sousOnglets a").each(function (_oha,i){
			if 	(i==0)	{												 
				_oha.className="actif";
			}
			_oha.addEvent('click', function(e){
				new Event(e).stop();
				src_aPlusPartager[this.id.split("_")[2]].onDayClick(this.id,i);
			});
	   });   
	   setTimeout("src_aPlusPartager["+this.id+"].loadPlusPartager()", 500);
	   this.initState=true;
	},
	onOngletClick: function(_idOnglet,_nOnglet){
		$(this.idOngletActif).className="";
		this.idOngletActif=_idOnglet;
		$(this.idOngletActif).className="actif";
		//$("log").innerHTML+="<p>_nOnglet="+_nOnglet+"</p>";
		//2- les plus partager, 1 - les plus vue
		this.vue=(_nOnglet==0)?2:1;
		this.displayPlusPartager();
		
		/// STATS
		 if(!this.isInitDisplay) {
		  oSrc.alert("Plus Partagées", "onOngletClick() : STAT : CT()= " + ((this.vue==2)?"PlusPartagées":"PlusConsultées") );
		  CT( (this.vue==2)?"PlusPartagées":"PlusConsultées" );
		 }
	},
	onDayClick: function(_idBarDay,_nbDay){
		$(this.idBarActif).className="";
		this.idBarActif=_idBarDay;
		$(this.idBarActif).className="actif";
		this.nbDay=this.aDay[_nbDay];
		
		this.displayPlusPartager();
		
		/// STATS
		  var  _plage = "24h";
		  if(_nbDay==1) _plage = "48h";
		  else if (_nbDay==2) _plage = "7j";
		  else if (_nbDay==3) _plage = "30j";
		  if(!this.isInitDisplay) {
		 	 oSrc.alert("Plus Partagées", "onDayClick : STAT : CT()=" + ((this.vue==2)?"PlusPartagées":"PlusConsultées") + "_" + _plage );
			  CT( ((this.vue==2)?"PlusPartagées":"PlusConsultées") + "_" + _plage);
		  }
	},
	findIndex : function(){	
		var _t=(this.vue+""+this.nbDay)*1;
		for (var i=0; i< this.ass.length;i++){
			if (this.ass[i]==_t) return {start:i,end:this.oData.length/8};
		}
		return null;
	},
	loadPlusPartager: function(){
            oSrc.crossDomainAjax(
				"http://www.radio-canada.ca/ppage3/lib/v3.1/js/PlusPartager.js",
				{
				    onSucceed: "void",
				    onFailed: "void"
				}
			);
	},
	onLoad : function(_oData){
		this.oData=_oData.plusPartager;
		this.onDayClick(this.idBarActif,0);
		this.isInitDisplay = false;
	},
	getParam :	function(_param,_default){
		return  $defined(this.oParam) &&  $defined(this.oParam[_param]) ? this.oParam[_param] : _default;	
	},
	displayPlusPartager:function(){
		$(this.instIdRes).fade('out');
		var _ind=this.findIndex();
	   
	   /// STATS
		  var  _plage = "24h";
		  if(this.nbDay==this.aDay[1]) _plage = "48h";
		  else if (this.nbDay==this.aDay[2]) _plage = "7j";
		  else if (this.nbDay==this.aDay[3]) _plage = "30j";
		 
		var stat = ((this.vue==2)?"PlusPartagées":"PlusConsultées") + "_" + _plage + "_manchette" ;
		oSrc.alert("Plus Partagées", "displayPlusPartager() : STAT = " + stat );
		 
		 
		
	/// Display
	   oSrc.alert("partage", "from = " + _ind.start*_ind.end);
	   for (var i=_ind.start*_ind.end,n=0,s="";n<_ind.end;i++,n++){
		    if(n<this.nbRecord){
			//var _oTitre=getText(this.oData[i].titre);
			 s+='<li ' + ((n % 2)?' class="secondBg" ':'') + '>' + 
			 	'	<div>' + (n+1) + '</div>' + 
			 	'	<p class="SurTitre">' + 
			 			((this.oData[i].categorie != null && this.oData[i].categorie != '' && $defined(this.oData[i].categorie)) ? this.oData[i].categorie : '') + 
						(
							(
								this.oData[i].categorie != null && this.oData[i].categorie != '' && $defined(this.oData[i].categorie)
								&&
								getSurtitre(this.oData[i]) != ''
							)?' | ':''
						) + 
						((getSurtitre(this.oData[i]) != '') ? getSurtitre(this.oData[i]) : '') + 
			 	'	</p>' + 
			 	'	<h3>' + 
			 	'		<a href="' + this.oData[i].url +'" title="' + this.oData[i].description + '" >' + getTitre(this.oData[i]) + '</a>' + 
			 	'	</h3>' + 
			 	'</li>';
			 oSrc.alert("partage", 
						((this.oData[i].categorie != null && this.oData[i].categorie != '' && $defined(this.oData[i].categorie)) ? this.oData[i].categorie : '') + 
						(
							(
								this.oData[i].categorie != null && this.oData[i].categorie != '' && $defined(this.oData[i].categorie)
								&&
								getSurtitre(this.oData[i]) != ''
							)?' | ':''
						) + 
						((getSurtitre(this.oData[i]) != '') ? getSurtitre(this.oData[i]) : '') + 
						' <a href="'+this.oData[i].url +'" title="'+this.oData[i].description+'" >' + getTitre(this.oData[i]) + "</a> (" + (this.vue==2?this.oData[i].popularite:(this.oData[i].vue-this.oData[i].popularite)) + " / " + this.oData[i].vue + ")");
			}
		}
	   oSrc.alert("partage", "----------");
		var _tmp = setTimeout("$('"+this.instIdRes+"').innerHTML='" + s.replaceAll("'", "\\'") + "';$('"+this.instIdRes+"').fade('in')", 400);
		function getTitre(_o) {
			var _s = _o.titreCourt;
			if (_s == '' || _s == null || !$defined(_s)) {
				_s = _o.titre.slice( _o.titre.indexOf(":")+1, _o.titre.indexOf("|"));
			}
			return _s;
		}
		function getSurtitre(_o) {
			var _s = _o.surtitre;
			if (_s == '' || _s == null || !$defined(_s)) {
				_s = _o.titre.slice(0, _o.titre.indexOf(":"));
			}
			return _s;
		}
	}
}/*END Class_PlusPartager.prototype*/;
	
function afficherPlusPartager(_oParam){
	var _nbRecord;
	if (typeof(isTeaserInfo)!="undefined") /// voir: /ppage3/lib/v3.1/inc/teaser_information.html
		_nbRecord = (isTeaserInfo)?9:5; 
	else
		_nbRecord = 7;
	src_aPlusPartager.push(new Class_PlusPartager(_oParam, _nbRecord));
}
