/*
   ========================================================
        script: image-flow
        author: Gerard Ferrandez - [Ge1doot]
          date: March 15, 2008
          site: http://www.dhteumeuleu.com
       license: CC-BY-NC - do not remove this notice
   ========================================================
*/

/* ===== custom getElementsByClass ==== */
function getElementsByClass (object, tag, className) {
	var o = object.getElementsByTagName(tag);
	for ( var i = 0, n = o.length, ret = []; i < n; i++)
		if (o[i].className == className) ret.push(o[i]);
	if (ret.length == 1) ret = ret[0];
	return ret;
}

var imf = function () {
	/* //////////// ==== private methods ==== //////////// */
	var lf = 0;
	var instances = new Array();
	
	/* ===== create image reflexion ==== */
	function createReflexion (cont, img, catid) {
		var flx = false;
		if (document.createElement("canvas").getContext) {
			/* ---- canvas ---- */
			flx = document.createElement("canvas");
			flx.width = img.width;
			flx.height = img.height;
			var context = flx.getContext("2d");
			context.translate(0, img.height);
			context.scale(1, -1);
			context.drawImage(img, 0, 0, img.width, img.height);
			flx.style.opacity = '0.35';
		}
		else {
			if (typeof document.body.style.maxHeight == "undefined") {
				// IE6, et versions antérieures
				return flx;
			}
			/* ---- DXImageTransform ---- */
			flx     = document.createElement('img');
			flx.src = img.src;
			/*
			flx.style.filter =	'flipv progid:DXImageTransform.Microsoft.Alpha(' +
													'opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=' +
													(img.height * .25) + ')';
			*/
			flx.style.filter =	'flipv progid:DXImageTransform.Microsoft.Alpha(' +
													'opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=' +
													img.height+ ')';
		}
		/* ---- insert Reflexion ---- */
		flx.style.position = 'absolute';
		flx.style.left     = '-4000px';
		if(catid != '' && carrouselSelect.className != 'centre_'+catid+' select'){
			return false;
		}
		cont.appendChild(flx);
		return flx;
	}
	
	/* //////////// ==== carrousel Constructor ==== //////////// */
	function carrousel(oCont, horizon, size, zoom, border, start, interval) {
		this.diapos     = [];
		this.scr        = false;
		this.size       = size;
		this.zoom       = zoom;
		this.horizon    = horizon;
		this.bdw        = border;
		this.oCont      = oCont;
		this.oc         = document.getElementById(oCont);
		
		this.title      = getElementsByClass(this.oc.parentNode, 'div', 'carrouselTitle');
		this.price      = getElementsByClass(this.oc.parentNode, 'div', 'carrouselPrice');
		this.legend     = getElementsByClass(this.oc.parentNode, 'div', 'carrouselLegend');
		this.arL        = getElementsByClass(this.oc.parentNode, 'img', 'carrouselLeft');
		this.arR        = getElementsByClass(this.oc.parentNode, 'img', 'carrouselRight');
		
		
		this.alw        = this.arL.width - 5;
		this.arw        = this.arR.width - 5;
		this.arL.parent = this.arR.parent = this;
		this.view       = this.back       = -1;
		this.time_start = start * 62.5 || 0;
		this.time_inter = interval * 62.5 || 0;
		this.time_out   = this.time_start;
		this.time       = 0;
		this.time_dir   = 1;
		this.resize();
		this.oc.onselectstart = function () { return false; }
		/* ---- create images ---- */
		var vitrines = getElementsByClass(this.oc, 'div', 'bank').getElementsByTagName('div');
		this.NF      = vitrines.length;
		for (var i = 0, o; o = vitrines[i]; i++) {
			var src;
			var title  = '- ' + i + ' -';
			var text   = '';
			var url    = '';
			var target = '_self';
			var price  = '';
			var link   = o.getElementsByTagName('a');
			var span   = o.getElementsByTagName('span');
			var img    = o.getElementsByTagName('img');
			var sold   = '';
			var catid  = '';
			
			for (var j = 0; j<img.length; j++) {
				if(img[j].className == 'sold'){
					sold = img[j];
				}
				else if(img[j].className == 'sold2'){
					sold = img[j];
				}
				else{
					src   = img[j].src;
					catid = img[j].className;
				}
			}
			
			if(link.length > 0){
				title = link[0].innerHTML;
				//url   = link[0].href;
				url   = link[0];
				if(link[0].target != ''){
					target = link[0].target;
				}
				link = link[0];
			}
			else{
				link = '';
			}
			
			for (var j = 0; j<span.length; j++) {
				if(span[j].className == 'legend'){
					text = span[j].innerHTML;
				}
				else if(span[j].className == 'price'){
					price = span[j].innerHTML;
				}
				else if(span[j].className == 'title'){
					title = span[j].innerHTML;
				}
			}
			this.diapos[i] = new Diapo(this, i, src, title, text, link, target, price, sold, catid);
		}
		
		/* ==== right arrow ==== */
		this.arR.onclick = this.arR.ondblclick = function () {
			if (this.parent.view < this.parent.NF - 1){
				this.parent.calc(1);
			}
			else{
				this.parent.view = 0;
				this.parent.calc();
			}
		}
		
		/* ==== Left arrow ==== */
		this.arL.onclick = this.arL.ondblclick = function () {
			if (this.parent.view > 0){
				this.parent.calc(-1);
			}
			else{
				this.parent.view = this.parent.NF - 1;
				this.parent.calc();
			}
		}
		
	}
	
	/* //////////// ==== carrousel prototype ==== //////////// */
	carrousel.prototype = {
		/* ==== targets ==== */
		calc : function (inc) {
			if (inc) {
				this.view += inc;
				/* ---- stop autoscroll ---- */
				this.time = 0;
				this.time_out = this.time_start;
			}
			var tw = 0;
			var lw = 0;
			var o = this.diapos[this.view];
			if (o && o.loaded) {
				if(o.catid != '' && carrouselSelect.className != 'centre_'+o.catid+' select'){
					return false;
				}
				/* ---- reset ---- */
				var ob = this.diapos[this.back];
				if (ob && ob != o) {
					ob.img.className = 'diapo';
					ob.z1 = 1;
				}
				/* ---- update legend ---- */
				this.title.innerHTML       = o.title;
				this.legend.style.color    = '';
				this.legend.style.fontSize = '';
				this.legend.innerHTML      = o.text;
				this.price.innerHTML       = o.price;
				/*
				this.price.replaceChild(document.createTextNode(o.price), this.price.firstChild);
				*/
				/* ---- update hyperlink ---- */
				if (o.url) {
					o.img.className = 'diapo link';
					window.status = 'hyperlink: ' + o.url;
				} else {
					o.img.className = 'diapo';
					window.status = '';
				}
				/* ---- calculate target sizes & positions ---- */
				if(o.r < 1) o.w1 = Math.min(o.iw, this.wh * .8, Math.round(this.ht * this.horizon / o.r)) * o.z1;
				else o.w1 = Math.round(this.ht * this.horizon / o.r) * o.z1;
				var x0 = o.x1 = (this.wh * .5) - (o.w1 * .5);
				var x = x0 + o.w1 + this.bdw;
				for (var i = this.view + 1, o; o = this.diapos[i]; i++) {
					if (o.loaded) {
						o.x1 = x;
						o.w1 = (this.ht / o.r) * this.size;
						x   += o.w1 + this.bdw;
						tw  += o.w1 + this.bdw;
					}
				}
				x = x0 - this.bdw;
				for (var i = this.view - 1, o; o = this.diapos[i]; i--) {
					if (o.loaded) {
						o.w1 = (this.ht / o.r) * this.size;
						o.x1 = x - o.w1;
						x   -= o.w1 + this.bdw;
						tw  += o.w1 + this.bdw;
						lw  += o.w1 + this.bdw;
					}
				}
				/* ---- save preview view ---- */
				this.back = this.view;
			}
		},
		/* ==== resize  ==== */
		resize : function () {
			this.wh = this.oc.clientWidth;
			this.ht = this.oc.clientHeight;
			this.calc();
			this.run(true);
		},
		/* ==== animation loop ==== */
		run : function (res) {
			/* ---- move all images ---- */
			var i = this.NF;
			while (i--) this.diapos[i].move(res);
			/* ---- autoscroll ---- */
			if (this.time_out) {
				this.time++;
				if (this.time > this.time_out) {
					this.view += this.time_dir;
					if (this.view >= this.NF || this.view < 0) {
						this.time_dir = -this.time_dir;
						this.view += this.time_dir * 2;
					}
					this.calc();
					this.time = 0;
					this.time_out = this.time_inter;
				}
			}
		}
	}
	
	/* //////////// ==== Diapo Constructor ==== //////////// */
	Diapo = function (parent, N, src, title, text, url, target, price, sold, catid) {
		this.parent         = parent;
		this.loaded         = false;
		this.title          = title;
		this.text           = text;
		this.price          = price;
		this.sold           = ''
		this.url            = url;
		this.target         = target;
		this.N              = N;
		this.img            = document.createElement('img');
		this.img.src        = src;
		this.img.parent     = this;
		this.img.className  = 'diapo';
		this.catid          = catid;
		this.x0             = this.parent.oc.clientWidth;
		this.x1             = this.x0;
		this.w0             = 0;
		this.w1             = 0;
		this.z1             = 1;
		this.z2             = 0;
		this.img.parent     = this;
		this.img.onclick    = function() { this.parent.click(); }
		
		if(sold != ''){
			this.sold           = document.createElement('img');
			this.sold.src       = sold.src;
			this.sold.className = sold.className;
			this.sold.parent    = this;
			this.sold.onclick   = function() { this.parent.click(); }
		}
		
		this.parent.oc.appendChild(this.img);
		if(sold != ''){
			this.parent.oc.appendChild(this.sold);
		}
		/* ---- display external link ---- */
		if (url) {
			this.img.onmouseover = function () { this.className = 'diapo link';}
			this.img.onmouseout  = function () { this.className = 'diapo'; }
		}
	}
	
	/* //////////// ==== Diapo prototype ==== //////////// */
	Diapo.prototype = {
		
		/* ==== HTML rendering ==== */
		move : function (res) {
			var that = this.parent;
			if (this.loaded && this.flx) {
				var sx = this.x1 - this.x0;
				var sw = this.w1 - this.w0;
				if (Math.abs(sx) > 2 || Math.abs(sw) > 2 || res) {
					/* ---- paint only when moving ---- */
					this.x0 += sx * .1;
					this.w0 += sw * .1;
					var h = this.w0 * this.r;
					this.z2 = Math.ceil((that.ht * that.horizon + 1 - this.z2 - h) *.5);
					if (this.x0 < that.wh && this.x0 + this.w0 > 0) {
						/* ---- paint only visible images ---- */
						this.visible = true;
						var o = this.img.style;
						/* ---- diapo ---- */
						o.left   = Math.floor(this.x0) + 'px';
						o.bottom = Math.floor(that.ht * (1 - that.horizon) + this.z2) + 'px';
						o.width  = Math.floor(this.w0) + 'px';
						o.height = Math.floor(h) + 'px';
						if(this.sold){
							this.sold.style.left   = o.left;
							this.sold.style.bottom = o.bottom;
							this.sold.style.width = '';
							/*
							this.sold.style.height = Math.floor(h*this.ratioH) + 'px';
							this.sold.style.width  = Math.floor(h*this.ratioH*this.ratioW) + 'px';
							*/
						}
						/* ---- reflexion ---- */
						if (this.flx) {
							var o = this.flx.style;
							o.left   = Math.floor(this.x0) + 'px';
							o.top    = Math.ceil(that.ht * that.horizon + 1 - this.z2) + 'px';
							o.width  = Math.floor(this.w0) + 'px';
							o.height = Math.floor(h) + 'px';
						}
					}
					else {
						/* ---- disable invisible images ---- */
						if (this.visible) {
							this.visible = false;
							this.img.style.width = '0px';
							if (this.flx) this.flx.style.width = '0px';
							if(this.sold){
								this.sold.style.width = '0px';
							}
						}
					}
					if (this.parent.view == this.N) {
						if (this.flx) {
							this.flx.style.display = 'none';
						}
					}
					else if (this.flx) {
						this.flx.style.display = '';
					}
				}
			}
			else {
				/* ==== image onload ==== */
				if (this.img.complete && this.img.width) {
					/* ---- get size image ---- */
					this.iw     = this.img.width;
					this.ih     = this.img.height;
					this.r      = this.ih / this.iw;
					if(this.sold != ''){
						if(this.sold.className == 'sold'){
							this.ratioH = 57/(that.ht*that.horizon);
							this.ratioW = 78/57;
						}
						else{
							this.ratioH = 54/(that.ht*that.horizon);
							this.ratioW = 88/54;
						}
					}
					this.loaded = true;
					/* ---- create reflexion ---- */
					this.flx    = createReflexion(that.oc, this.img, this.catid);
					if (that.view < 0) that.view = this.N;
					else if (this.N == 0) that.view = this.N;
					that.calc();
				}
			}
		},
		
		/* ==== diapo onclick ==== */
		click : function () {
			/* ---- stop autoscroll ---- */
			this.parent.time = 0;
			this.parent.time_out = this.parent.time_start;
			if (this.parent.view == this.N) {
				/* ---- click on zoomed diapo ---- */
				if (this.url) {
					/* ---- open hyperlink ---- */
					if(this.url.onclick != undefined){
						this.url.onclick();
					}
					else{
						window.open(this.url, this.target);
					}
				} else {
					/* ---- zoom in/out ---- */
					this.z1 = this.z1 == 1 ? this.parent.zoom : 1;
					this.parent.calc();
				}
			}
			else {
				/* ---- select diapo ---- */
				this.parent.view = this.N;
				this.parent.calc();
			}
			return false;
		}
	}
	
	/* //////////// ==== public methods ==== //////////// */
	return {
		/* ==== initialize script ==== */
		create : function (div, horizon, size, zoom, border, start, interval) {
			/* ---- instanciate carrousel ---- */
			var load = function () {
				var loaded = false;
				// for (var divid in instances){
					// if (instances[divid].oCont == div) loaded = true;
				// }
				if (!loaded) {
					/* ---- push new carrousel instance ---- */
					instances[div] = new carrousel(div, horizon, size, zoom, border, start, interval);
					/* ---- init script (once) ---- */
					if (!imf.initialized) {
						imf.initialized = true;
						/* ---- window resize event ---- */
						addEvent(window, 'resize', function () {
							var i = instances.length; 
							while (i--) instances[i].resize(); 
						});
						/* ---- stop drag N drop ---- */
						addEvent(document.getElementById(div), 'mouseout', function (e) {
							if (!e) e = window.event;
							var tg = e.relatedTarget || e.toElement;
							if (tg && tg.tagName == 'HTML') {
								for (var divid in instances){
									instances[divid].oc.onmousemove = null;
								}
							}
							return false;
						});
						/* ---- set interval loop ---- */
						setInterval(function () {
							for (var divid in instances){
								instances[divid].run();
							}
						}, 16);
					}
				}
			}
			load();
			this.time = 0;
			this.time_out = this.time_start;
		}
	}
}();

function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest) {// Firefox et autres
		xhr = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject){ // Internet Explorer 
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false; 
	} 
	return xhr
}

/* ==== create carrousel ==== */
//          div ID, horizon, size, zoom, border, autoscroll_start, autoscroll_interval
/*imf.create("carrousel", 0.75, 0.15, 1.8, 10, 8, 4);*/
// imf.create("carrousel", 0.5, 0.15, 1.8, 10, 8, 4);

var carrouselSelect = '';
var carrouselMenuSize = '';
var bank     = '';
var pays     = '';
var language = '';
function launchCarrousel(catid,lien){
	if(carrouselSelect == ''){
		carrouselSelect = document.getElementById('carrouselSelect');
	}
	
	if(bank != ''){
		var container = bank.parentNode.parentNode;
		bank.parentNode.removeChild(bank);
		document.getElementById('carrouselPromo').innerHTML = '';
		getElementsByClass(container, 'div', 'carrouselTitle').innerHTML = 'Chargement...';
		getElementsByClass(container, 'div', 'carrouselPrice').innerHTML = '&nbsp;';
		getElementsByClass(container, 'div', 'carrouselLegend').innerHTML = 'Veuillez patienter...';
		getElementsByClass(container, 'div', 'carrouselLegend').style.color = 'black';
		getElementsByClass(container, 'div', 'carrouselLegend').style.fontSize = '1em';
	}
	
	bank           = document.createElement("div");
	bank.id        = 'carrouselBank';
	bank.className = 'bank';
	document.getElementById('carrouselPromo').appendChild(bank);
	
	var xhr = getXhr();
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200){
			lien = lien.replace(/\/category\//,'/promo/');
			document.getElementById('carrouselBank').innerHTML = xhr.responseText;
			imf.create("carrouselPromo", 0.5, 0.5, 1, 10, 2, 2);
			// create : function (div, horizon, size, zoom, border, start, interval) {
		}
		else if (xhr.readyState == 4 && 400 <= xhr.status && xhr.status <= 499){
		}
		else if (xhr.readyState == 4 && 500 <= xhr.status && xhr.status <= 599){
		}
		else if (xhr.readyState == 4){
		}
	}
	
	time    = new Date();
	time    = time.getTime();
	var url = "/cgi/promo.cgi?centreid="+catid;
	if(pays != ''){
		url = url+"&pays="+pays;
	}
	if(language != ''){
		url = url+"&language="+language;
	}
	if(typeof(category) !== 'undefined' && category != ''){
		url = url+"&category="+category;
	}
	url = url+"&time="+time;
	xhr.open("GET",url,true);
	xhr.send(null);
	
	return false;
}

var first;
var last;
function menuCarrousel(centreId,lien){
	var menu;
	var className = 'centre_'+centreId
	
	var select = document.getElementById('carrouselSelect');
	
	if(select != undefined && select.className == className+' select'){
		return false;
	}
	
	var newSelect = '';
	
	var liste = document.getElementById('carrouselMenu').getElementsByTagName('LI');
	for(var index=0;index<liste.length;index++){
		if(liste[index].className == className){
			newSelect = liste[index];
			index     = liste.length;
		}
	}
	
	
	if(newSelect == ''){
		return false;
	}
	if(select != undefined){
		select.id           = '';
		select.className    = select.className.replace(/ select$/,'');
	}
	
	newSelect.id        = 'carrouselSelect';
	newSelect.className = newSelect.className+' select';
	var link = newSelect.getElementsByTagName('SPAN')[0];
	/*
	var lien = link.href;
	*/
	
	var catLink = document.getElementById('catLink');
	catLink.href = lien;
	catLink.innerHTML = link.innerHTML;
	
	var promoLink  = document.getElementById('promoLink');
	promoLink.href = lien.replace(/\/category\//,'/promo/');
	
	carrouselSelect = newSelect;
	launchCarrousel(centreId,lien);
	
	return false;
}

var moveProductTimer;
function moveProduct(id,deplacement){
	if(deplacement != 'left' && deplacement != 'right'){
		return false;
	}
	clearMoveProduct();
	
	var product = document.getElementById(id+'Product');
	var container = product.parentNode;
	
	if(product.offsetWidth <= container.offsetWidth){
		return;
	}
	
	var productLeft  = parseInt(product.style.left);
	if(isNaN(productLeft)){
		productLeft = 0;
	}
	var productRight = productLeft+product.offsetWidth;
	
	containerWidth = container.offsetWidth-2*13;
	
	if(deplacement == 'right'){
		if(productRight<=containerWidth){
			product.style.left = (containerWidth-product.offsetWidth)+'px';
			document.getElementById(id+'Right').src = '/images/noGoRight.gif';
			document.getElementById(id+'Right').className = 'noGoRight';
		}
		else {
			if(productRight-100<containerWidth){
				product.style.left = (containerWidth-product.offsetWidth)+'px';
				document.getElementById(id+'Right').src = '/images/noGoRight.gif';
				document.getElementById(id+'Right').className = 'noGoRight';
			}
			else{
				product.style.left = (productLeft-100)+'px';
				moveProductTimer = setTimeout(function(){moveProduct(id,deplacement);},50);
			}
			document.getElementById(id+'Left').src = '/images/goLeft.gif';
			document.getElementById(id+'Left').className = 'goLeft';
		}
	}
	else{
		if(productLeft>=0){
			product.style.left = '0px';
			document.getElementById(id+'Left').src = '/images/noGoLeft.gif';
			document.getElementById(id+'Left').className = 'noGoLeft';
		}
		else {
			if(productLeft+100>=0){
				product.style.left = '0px';
				document.getElementById(id+'Left').src = '/images/noGoLeft.gif';
				document.getElementById(id+'Left').className = 'noGoLeft';
			}
			else{
				product.style.left = (productLeft+100)+'px';
				moveProductTimer = setTimeout(function(){moveProduct(id,deplacement);},50);
			}
			document.getElementById(id+'Right').src = '/images/goRight.gif';
			document.getElementById(id+'Right').className = 'goRight';
		}
	}
}

function clearMoveProduct(){
	clearTimeout(moveProductTimer);
}

function calculMoveProduct(){
	for (var i=0; i < listProduct.length; ++i){
		var id = listProduct[i];
		var product = document.getElementById(id+'Product');
		if(product !== 'undefined' && product != null){
			var container = product.parentNode;
			
			if(product.offsetWidth <= container.offsetWidth){
				document.getElementById(id+'Left').src = '/images/noGoLeft.gif';
				document.getElementById(id+'Left').className = 'noGoLeft';
				document.getElementById(id+'Right').src = '/images/noGoRight.gif';
				document.getElementById(id+'Right').className = 'noGoRight';
			}
			else{
				var productLeft  = parseInt(product.style.left);
				if(isNaN(productLeft)){
					productLeft = 0;
				}
				var productRight = productLeft+product.offsetWidth;
				var containerWidth = container.offsetWidth-2*13;
				document.getElementById(id+'Left').src = '/images/goLeft.gif';
				document.getElementById(id+'Left').className = 'goLeft';
				document.getElementById(id+'Right').src = '/images/goRight.gif';
				document.getElementById(id+'Right').className = 'goRight';
				
				if(productRight<=containerWidth){
					product.style.left = (containerWidth-product.offsetWidth)+'px';
					document.getElementById(id+'Right').src = '/images/noGoRight.gif';
					document.getElementById(id+'Right').className = 'noGoRight';
				}
				if(productLeft>=0){
					product.style.left = '0px';
					document.getElementById(id+'Left').src = '/images/noGoLeft.gif';
					document.getElementById(id+'Left').className = 'noGoLeft';
				}
			}
		}
	}
}

function bestPromo(){
	var xhr = getXhr();
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200){
			var reponse = xhr.responseText.split('</td>');
			var bestSalesProduct = document.getElementById('bestPromoProduct').rows[0];
			for(var i=0;i<reponse.length-1;i++){
				var TD = bestSalesProduct.insertCell(-1);
				if(i<reponse.length-2){
					TD.className = 'case orangeRightBorder';
				}
				else{
					TD.className = 'case';
				}
				TD.innerHTML = reponse[i].replace(/<td[^>]*>/,'');
			}
		}
		else if (xhr.readyState == 4 && 400 <= xhr.status && xhr.status <= 499){
		}
		else if (xhr.readyState == 4 && 500 <= xhr.status && xhr.status <= 599){
		}
		else if (xhr.readyState == 4){
		}
	}
	time    = new Date();
	time    = time.getTime();
	var url = "/cgi/promo.cgi?tab=1";
	url = url+"&time="+time;
	xhr.open("GET",url,true);
	xhr.send(null);
}

function selectMonthShop(id){
	id = id -1;
	
	var span = document.getElementById('listMonthShop').getElementsByTagName('SPAN');
	var table = document.getElementById('monthShop').getElementsByTagName('TABLE');
	for(var i=0;i<table.length;i++){
		if(table[i].style.display != 'none'){
			table[i].style.display   = 'none';
			i=table.length;
		}
	}
	
	for(var i=0;i<span.length;i++){
		if(span[i].style.backgroundColor != ''){
			span[i].style.backgroundColor = '';
			i=span.length;
		}
	}
	
	
	span[id].style.backgroundColor = '#C45E29';
	
	
	if(document.getElementById('monthShop_'+id) != undefined){
		document.getElementById('monthShop_'+id).style.display = '';
	}
	else{
		var xhr = getXhr();
		// On défini ce qu'on va faire quand on aura la réponse
		xhr.onreadystatechange = function(){
			// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
			if (xhr.readyState == 4 && xhr.status == 200){
				document.getElementById('monthShop').innerHTML += xhr.responseText;
			}
		}
		time    = new Date();
		time    = time.getTime();
		var url = "/cgi/monthShop.cgi?p="+id;
		url = url+"&time="+time;
		xhr.open("GET",url,true);
		xhr.send(null);
	}
}

/*
function showCoords(evt){
	alert(
		"clientX value: " + evt.clientX + "\n" +
		"clientY value: " + evt.clientY + "\n"
	);
}
addEvent(document.body, 'mousedown', function(event){showCoords(event);});
*/

function initMoveProduct(){
	//addEvent(document.getElementsByTagName("body")[0], 'load', function(){calculMoveProduct()});
	addEvent(window, 'load', function(){calculMoveProduct()});
	addEvent(window, 'resize', function(){calculMoveProduct();});
	/*addEvent(window, 'resize', calculMoveProduct());*/
}

function launchCarrouselAleatoire(){
	var span   = document.getElementById('carrouselMenu').getElementsByTagName('span');
	var id     = parseInt(Math.random()*span.length);
	var toCall = span[id].getAttribute('onClick').toString();
	
	var tmp   = toCall.split('menuCarrousel(');
	toCall    = tmp[1];
	var tmp   = toCall.split(')');
	toCall    = 'menuCarrousel('+tmp[0]+')';
	
	eval(toCall);
}

/* ===== crossbrowsers addEvent ==== */
function addEvent (o, e, f) {
	if (window.addEventListener) o.addEventListener(e, f, false);
	else if (window.attachEvent) r = o.attachEvent('on' + e, f);
}


