var Catalogues = new Array();
var indiceCat;
var enCours=false;
var Auto = true;//mode automatique
var DefaultDelai = 5;//délai en mode auto (en seconde)
var currentDelai;
function Init_cat(){
	var ladate = new Date();
	var time = ladate.getMilliseconds();
	var myAjax = "";
	myAjax = new Ajax.Request(
      '/catalogue.xml',
      {
        method: 'get',
        parameters: {},
        onSuccess: function (xhr)
          {
			Catalogues = new Array();
			var xml = xhr.responseXML;
			
			var nodeCats=xml.getElementsByTagName('catalogues')[0];
			var Cats = nodeCats.getElementsByTagName('catalogue');

			for(var i=0;i<Cats.length;i++)
			{
				//Indice du produit dans tableau Products
				var Indice = Catalogues.length;
				var Cat = Cats[i];
				var attributes = Cat.attributes;
				Catalogues[Indice] = new Array();
				for(var j=0;j<attributes.length;j++)
				{
					Catalogues[Indice][attributes[j].name]= attributes[j].nodeValue;
				}
				Catalogues[Indice]['image'] = Cat.getElementsByTagName("image")[0].firstChild.nodeValue;
				Catalogues[Indice]['lienconsultez'] = Cat.getElementsByTagName("lienconsultez")[0].firstChild.nodeValue;
				Catalogues[Indice]['lienrecevoir'] = Cat.getElementsByTagName("lienrecevoir")[0].firstChild.nodeValue;
			}
			initSlideCat();
		 },
		onFailure: function(xhr)
		{
		}
      }
    );
};

document.observe("dom:loaded", function() {
	Init_cat();
});

function initSlideCat()
{
	afficheCat(0);
}

function previous()
{
	if(indiceCat!=0)
		afficheCat(indiceCat-1);
	else
		afficheCat(Catalogues.length-1);
}

function next()
{
	if(indiceCat!=Catalogues.length-1)
		afficheCat(indiceCat+1);
	else
		afficheCat(0);
}

function count()
{
	currentDelai--;
	if(currentDelai==0)
	{
		if(indiceCat==Catalogues.length-1)
			afficheCat(0);
		else
			afficheCat(indiceCat+1);
		currentDelai = DefaultDelai;
	}
	setTimeout("count()",1000);
}

function afficheCat(id)
{
	indiceCat = id;
	if(typeof(Catalogues[id]['image'])!="undefined")
		$('imageCatalogue').src = Catalogues[id]['image'];
	if(typeof(Catalogues[id]['lienconsultez']!="undefined"))
		$('consultezCat').href = Catalogues[id]['lienconsultez'];
	if(typeof(Catalogues[id]['lienrecevoir']!="undefined"))
		$('recevezCat').href = Catalogues[id]['lienrecevoir'];
}

function main(path)
{
	$('mainImg').src=path;
}
