var ListeFiche;
var BaseImg="/images/skins/skin_01/images/";
var TimeEnd;
var ladate = new Date();
function ds_getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}

function Init_fond(){
	
	try{
	var Noeuds = new Array('photo_1920x1200_centre_spatial_920px_');
	var time = ladate.getMilliseconds();
	var myAjax = "";
	myAjax = new Ajax.Request(
      '/exports/xml_catalogue.asp?start=0&limit=1&sid=027424ccb7262b789ba5365d9e2be1f4&date='+time,
      {
        method: 'get',
        parameters: {},
        onSuccess: function (xhr)
          {
			ListeFiche = new Array();
			var xml = xhr.responseXML;
			var nodeExports=xml.getElementsByTagName('export')[0];
			var Fiches = nodeExports.getElementsByTagName('fiche');
			for(var i=0;i<Fiches.length;i++)
			{

				var Indice = ListeFiche.length;
				var Fiche = Fiches[i];
				var attributes = Fiche.attributes;
				ListeFiche[i] = new Array();
				for(var j=0;j<attributes.length;j++)
				{
					ListeFiche[Indice][attributes[j].name]= attributes[j].nodeValue;
				}
				for(var j=0;j<Noeuds.length;j++)
				{
					
					ListeFiche[Indice][Noeuds[j]] = typeof(Fiche.getElementsByTagName(Noeuds[j])[0].text)=="undefined"?Fiche.getElementsByTagName(Noeuds[j])[0].textContent:Fiche.getElementsByTagName(Noeuds[j])[0].text;
				}
			}

			buildIt_fond();

		 },
		onFailure: function(xhr)
		{

			buildIt_fond();
		}
      }
    );
	}catch(any){
		d(any||any.description);
	}
};

function buildIt_fond()
{
	var container = $('fond_img');
	
	container.innerHTML = "";
	
	for(var i=0;i<ListeFiche.length;i++)
	{
		try{
		   	var head = document.getElementsByTagName('head')[0];
		    var style = document.createElement('style');
		   	var rules = document.createTextNode('body { background:url(/images/catalogue/id_6/images/'+ListeFiche[i]['photo_1920x1200_centre_spatial_920px_']+') top center no-repeat; background-attachment: fixed;  }');
			style.type = 'text/css';
			if(style.styleSheet){
				style.styleSheet.cssText = rules.nodeValue;
			}
			else{
				style.appendChild(rules);
			}
			head.appendChild(style);

	 	}catch(any){
	 		d(any||any.description);
	 	}		
	}
}


function getTime()
{
	return ladate.getTime();
}

function in_array(val,array)
{
	for(var i=0;i<array.length;i++)
		if(val==array[i])
			return true;
	return false;
}

function el(type,attach)
{
	var el = document.createElement(type);
	Element.extend(el);
	if(typeof(attach)!="undefined")
		attach.appendChild(el);
	return el;
}

function d(el){
	if(typeof(console)!="undefined"){
		if(typeof(console.debug)!="undefined")
			console.debug(el);
		else if(typeof(console.log)!="undefined")
			console.log(el);
	}
}
setTimeout("Init_fond()",200);
