/** 
* @alias liens-sponsorisés
* @projectDescription France 2 & France 3, versions 2.0
* @author	[FTVI] Pascal Beynel
*/

// ---------------------------------------------------------------------------------------------- \\
// Jquery init event
// ---------------------------------------------------------------------------------------------- \\
$(document).ready(function()
{	
	// keywordAdLinks is defined in gestion.liens-sponsorises.php
	AjaxGetAdLinksData("#ad_links_block_01 .ctnt");
});


// ----------------------------------------------------- \\
// This function gets for each item that contains comments
// the number of comments and the url where to read them
// ----------------------------------------------------- \\
function AjaxGetAdLinksData(destinationSelector)
{
	var req = $.ajax(
	{
		url: "/appftv/liens-sponsorises/getXML-linkspots.php",
		dataType: "xml",
		success: function(data)
		{
			
			var dest = $(destinationSelector);
			var allstyle = new Array("1","2","3","4","5","6","7","8","9","10");
			var itemKeyword = "";
			var randvalue = "";
			var myclass = "";
			$("Group > keyword", data).each(function()
			{
				// Gets the data
				itemKeyword = $(this).text();
				itemKeyword = itemKeyword.substr(1, itemKeyword.length-2);
				
				// Couleur du lien
				randvalue = Math.floor(Math.random()*allstyle.length);
				myclass = 'style'+allstyle[randvalue];
				allstyle.splice(randvalue, 1);
				
				// Builds the item HTML Block
				if (ftvi_portail == "rfo_fr") ftvi_portail = "rfo";
				var newItem = '';
				newItem = '<h3 class="itemSTitle"><a href="http://recherche-yahoo.'+ftvi_portail+'.fr/index-fr.php?searchmode=linkspotssearch&KEYWORDS='+itemKeyword+'" class="'+myclass+' keywords">'+itemKeyword+'</a></h3>';
				
				// Append data to the container
				dest.append(newItem);
			});
 		},
		
		error: function(req,errorMsg,except)
		{
			if (window.console && window.console.error){ console.error(arguments); }
		}
	});
}