/* vers 1.0.1.15173 */
var blockScroll = new Class({
	/**
			init() :
				- showElms : recupere la classe place sur le blockScroll permettant de savoir combien d'elements doivent etre affiche
				- scrollWidth : recupere la largeur du body du blockScroll sans les paddings
				- sep : recupere la largeur des separateur (ici, la marge placee sur les li);
				- totalElms : recupere le nombre d'element constituant le scroll
			
			clone():
				- cloner en fonction du nombre d'element visible, les derniers element du ul en les plaeants au debut et les premiers element e la fin, pour simuler un scroll continue
				- totalElms += showElms*2;
			
			sizing()
				- blockWidth : calcule la taille d'un block en fonction de (scrollWidth/showElms)-sep;
				- appliquer blockWidth sur tous les li
				- ulWidth : calcule la taille total du UL, connaissant la taille de chaque li + le separateur = ((blockWidth+sep)*totalElms)-sep;
			
			createButton()
				- creation des element div(left | right)>a>span pour les boutons de scroll injectInside(body)
			
			plugEvents()
				- ajout des evenement au click sur les boutons (1 parametre peut specifier de combien je me depace d'element en cliquant)
				- on click e gauche je scroll vers la gauche de 1 element e chaque fois ou de param elements
				- on click e droite je scroll vers la droite de 1 element e chaque fois ou de param elements
	**/
	options:{
		type:'H', //type du scroll, H=Horizontal, V=Vertical
		infinity:'true' //is the scroll is a loop ?
	},
	
	initialize: function(blockScroll,options){
		this.setOptions(options);
		if (!blockScroll) return;
		this.block = blockScroll;

		this.type = this.options.type;
		this.moveBlocks = 1;

		['scroll1','scroll2','scroll3','scroll4','scroll5'].each(function(cn,i){
			if (this.block.hasClass(cn)){
				this.showElms = i+1;
			}
		},this);

		['move2','move3','move4','move5'].each(function(cn,i){
			if (this.block.hasClass(cn)){
//				this.moveBlocks = i+2;
			}
		},this);

		this.blockBody = this.block.getElement('.body');
		this.ul =  this.block.getElement('ul');
		this.lis = this.block.getElements('li');
		this.scrollMask = this.block.getElement('.scrollMask');
		this.scrollWidth = this.scrollMask.offsetWidth;
		this.sep = this.lis[0].getFirst()?this.lis[0].getFirst().getStyle('margin-right').toInt():0;
		this.totalElms = this.lis.length;
		if (this.lis.length>this.showElms){
			if (this.lis.length>this.showElms) this.createButton();
			if (this.type=='H'){
				this.sizingH();
				this.plugEventH();
			}else if(this.type=='V'){
				this.sizingV();
				this.plugEventV();
			}
		}else{
			this.showElms = this.lis.length;
		}
	},
	createButton:function(){
		/*
		- creation des element div(left | right)>a>span pour les boutons de scroll injectInside(body)
		*/
		var btnLeft = new Element('div',{'class':'btnLeft'}).adopt(
			new Element('a').adopt(
				new Element('span').setText('pr\351c\351dent')
			)
		);
		
		var btnRight = new Element('div',{'class':'btnRight'}).adopt(
			new Element('a').adopt(
				new Element('span').setText('Suivant')
			)
		);
		
		this.btnLeft = btnLeft.injectBefore(this.blockBody.getFirst());
		this.btnRight = btnRight.injectInside(this.blockBody);
	},

	sizingH:function(){
		/*
		- block: calcule la taille d'un block en fonction de (scrollWidth/showElms)-sep;
		- appliquer blockWidth sur tous les li
		- ulWidth : calcule la taille total du UL, connaissant la taille de chaque li + le separateur = ((blockWidth+sep)*totalElms)-sep;
		*/
		this.fx = new Fx.Style(
			this.ul,
			'left',
			{
				duration: 300,
				wait: true
			}
		);

		this.liWidth = this.lis[0].offsetWidth;
		if (this.options.infinity){
			this.startPos = this.currentLeft = -(this.liWidth*this.showElms);
			this.endPos = -(this.liWidth*(this.totalElms-(this.showElms*2)));
			this.maxPos = -this.liWidth*(this.totalElms-this.showElms);
		}else{
			this.startPos = this.currentLeft = 0;
			this.endPos = this.maxPos = -this.liWidth*(this.totalElms-this.showElms);
		}

		this.ul.setStyle('left', this.startPos);
	},
	
	plugEventH:function(){
		/*
		- ajout des evenement au click sur les boutons (1 parametre peut specifier de combien je me depace d'element en cliquant)
		- on click e gauche je scroll vers la gauche de 1 element e chaque fois ou de param elements
		- on click e droite je scroll vers la droite de 1 element e chaque fois ou de param elements
		*/
		
		this.btnLeft.setStyles({
			'height':this.scrollMask.offsetHeight,
			'display': !this.options.infinity ?'none':''
		});
		this.btnRight.setStyle('height',this.scrollMask.offsetHeight);

		
		this.ok=true;
		
		this.fx.setOptions({
				onComplete:function(){
					if (this.options.infinity){
						if (this.currentLeft<=this.maxPos) {
							this.ul.setStyle('left',this.startPos);
							this.currentLeft = this.startPos;
						}else if (this.currentLeft>=0){
							this.ul.setStyle('left',this.endPos);
							this.currentLeft = this.endPos;
						}
					}else{
						switch(this.currentLeft){
							case this.endPos:
								this.btnRight.setStyle('display','none');
								this.btnLeft.setStyle('display','');
							break;
							case this.startPos:
								this.btnLeft.setStyle('display','none');
								this.btnRight.setStyle('display','');
							break;
							default:
								this.btnLeft.setStyle('display','');
								this.btnRight.setStyle('display','');
							break;
						}
					}
					this.ok = true;
				}.bind(this)
			});
		
		this.btnRight.addEvent('click', function(e){
			e = new Event(e); e.stop();
			if (this.ok){
				this.currentLeft = this.currentLeft-(this.liWidth*this.moveBlocks);
				this.ok = false;
				this.fx.start(this.currentLeft);
			}
		}.bind(this));
		
		this.btnLeft.addEvent('click', function(e){
			e = new Event(e); e.stop();
			if (this.ok){
				this.currentLeft = this.currentLeft+(this.liWidth*this.moveBlocks);
				this.ok = false;
				this.fx.start(this.currentLeft);
			}
		}.bind(this));
	},
	
	sizingV:function(){
		/*
		- blockWidth : calcule la taille d'un block en fonction de (scrollWidth/showElms)-sep;
		- appliquer blockWidth sur tous les li
		- ulWidth : calcule la taille total du UL, connaissant la taille de chaque li + le separateur = ((blockWidth+sep)*totalElms)-sep;
		*/
		
		this.fx = new Fx.Style(this.ul,'top',{duration:500,wait:true});
		
		if (window.ie){
			this.lis.each(function(li,i){
				li.setStyle('margin-bottom',-3);
			});
		}
		this.liHeight = /*window.ie?this.lis[this.showElms].offsetHeight-3:*/this.lis[this.showElms].offsetHeight;
		this.scrollMask.setStyle('height',(this.liHeight*this.showElms));
		
		if (this.options.infinity){
			this.startPos = this.currentTop = -(this.liHeight*this.showElms);
			this.endPos = -(this.liHeight*(this.totalElms-(this.showElms*2)));
			this.maxPos = -this.liHeight*(this.totalElms-this.showElms);
		}else{
			this.startPos = this.currentTop = 0;
			this.endPos = this.maxPos = -this.liHeight*(this.totalElms-this.showElms);
		}
		
		this.ul.setStyle('top', this.startPos);
	},
	
	plugEventV:function(){
		/*
		- ajout des evenement au click sur les boutons (1 parametre peut specifier de combien je me depace d'element en cliquant)
		- on click e gauche je scroll vers la gauche de 1 element e chaque fois ou de param elements
		- on click e droite je scroll vers la droite de 1 element e chaque fois ou de param elements
		*/
		
		if (!this.options.infinity) this.btnLeft.setStyle('visibility', 'hidden');
		this.ok=true;
		
		this.fx.setOptions({
				onComplete:function(){
					if (this.options.infinity){
						if (this.currentTop<=this.maxPos) {
							this.ul.setStyle('top',this.startPos);
							this.currentTop = this.startPos;
						}else if (this.currentTop>=0){
							this.ul.setStyle('top',this.endPos);
							this.currentTop = this.endPos;
						}
					}else{
						switch(this.currentTop){
							case this.endPos:
								this.btnRight.setStyle('visibility','hidden');
								this.btnLeft.setStyle('visibility','');
							break;
							case this.startPos:
								this.btnLeft.setStyle('visibility','hidden');
								this.btnRight.setStyle('visibility','');
							break;
							default:
								this.btnLeft.setStyle('visibility','');
								this.btnRight.setStyle('visibility','');
							break;
						}
					}
					this.ok = true;
				}.bind(this)
		});
		
		this.btnRight.addEvent('click', function(e){
			e = new Event(e); e.stop();
			if (this.ok && this.btnRight.getStyle('visibility') != 'hidden'){
				this.currentTop = this.currentTop-(this.liHeight*this.moveBlocks);
				this.ok = false;
				this.fx.start(this.currentTop);
			}
		}.bind(this));
		
		this.btnLeft.addEvent('click', function(e){
			e = new Event(e); e.stop();
			if (this.ok && this.btnLeft.getStyle('visibility') != 'hidden'){
				this.currentTop = this.currentTop+(this.liHeight*this.moveBlocks);
				this.ok = false;
				this.fx.start(this.currentTop);
			}
		}.bind(this));
	}
});
blockScroll.implement(new Options);

/*******************************************************************************************************************
/ ------------------------------------------		layer
********************************************************************************************************************/

var Layer = new Class({
	initialize : function() {
		if(!$('layer')) return;
		this.targetBKG = $('layerMask');
		this.targetBKG.setStyle('width', document.documentElement.scrollWidth);
		this.targetBKG.setStyle('height', document.documentElement.scrollHeight);
		this.targetBKG.setOpacity(0.8);
	},
	show : function(obj){
		if ($(obj) && $(obj).hasClass('hidden')){
			$(obj).removeClass('hidden');
		}
	},
	hide : function(obj){
		if ($(obj) && !$(obj).hasClass('hidden')){
			$(obj).addClass('hidden');
		}
	}
});

/** 23/12/2008 - CFT bouton +/- */
/*var setProduct = {
	init: function(){
	  var iTimeLineSetProduct1 = new Date().getTime();
//		var inputs = $$('input.nbrProduit');
    var oMain = $("main");// s stocker quelque part car recurent
		if(!oMain){return}
		var inputs = $("main").getElements('input.nbrProduit');
		if(inputs.length==0){return}
		var _span = new Element(
			'span',
			{
				'class': 'txtM'
			}
		);
		inputs.each(
			function(input) {
				var _oPrevious = input.getPrevious();
				if(_oPrevious && _oPrevious.className == 'txtM btnMoinsProduit') {
					_oPrevious.remove();
				}
				var _oNext = input.getNext();
				if(_oNext && _oNext.className == 'txtM btnPlusProduit') {
					_oNext.remove();
				}
				_span.clone().setHTML("<a href='#'>+</a>").addClass('btnPlusProduit').addEvent(
					'click',
					function(e) {
						e = new Event(e);
						e.stop();
						input.value < 20 ?
							input.value++:
							popLayer.openTag(
								{
									content: 'layer_upMaxArt'
								}
							);
					}
				).injectAfter(input);
				_span.clone().setHTML("<a href='#'>-</a>").addClass('btnMoinsProduit').addEvent(
					'click',
					function(e) {
						e = new Event(e);
						e.stop();
						input.value > 1 ?
							input.value--:
							popLayer.openTag(
								{
									content: 'layer_upMinArt'
								}
							);
					}
				).injectBefore(input);
			}
		);
	  var iTimeLineSetProduct2 = new Date().getTime();
  	logs("setPrTotal : " + (iTimeLineSetProduct1-iTimeLineSetProduct2));
	}
}*/
var setProduct = {
    btnPlus: function(element){
                var input = element.parentNode.parentNode.getElementsByTagName("INPUT")[0];
				if (input.value<20){
					input.value++;
				}
				else
				{
				    popLayer.openTag({content:'layer_upMaxArt'})
				}
			},

     btnMoins: function(element){
                var input = element.parentNode.parentNode.getElementsByTagName("INPUT")[0];
				if (input.value>1){
					input.value--;
				}
				else
				{
				    popLayer.openTag({content:'layer_upMinArt'})
				}
			},
	
	init: function(){
	}
}
/* FIN MODIF CFT */

function switchForm(aToActiv,aToHide){
// aFrom = elements de formulaire activant les elements : utile ?
// aToActiv = tableau d'elements e montrer
// aToHide = tableau d'elements e cacher
	if(aToActiv==null){}
	else{
		for(var i=0;aToActiv.length>i;i++){
			if(aToActiv[i].className.match(/hide/)){
				removeClass(aToActiv[i], "hide");

			}
		}
	}
	if(aToHide==null){}
	else{
		for(i=0;aToHide.length>i;i++){
			aToHide[i].className+=" hide";
		}
	}
}


function resultsMDR(){
	if($$('.triage').length==0)return false;
	var arrCheck=$$('.triage input[type^=check]');
	var arrBlocks=$$('.displayArticles');
	arrCheck.each(function(elm,i){
		elm.checked=true;
		elm.addEvent('click',function(){
			if(elm.checked){
				arrBlocks[i].removeClass('hidden');
			}else{
				arrBlocks[i].addClass('hidden');
				if (arrBlocks[i].hasClass('toggleClosed')){
					arrBlocks[i].getElement('.head a').onclick();
				}
			}
		})
	})
}

function fixHeightBlocks(){
// gourmandise
	var arr=[".modeVignette ul.line li.unit", "div.blockAlign"];
	arr.each(function(el,i){
		str=arr[i];
		if(!$$(str).length==0) minHeightBlocks(str);
	});
}
function minHeightBlocks(str){
	var arrBlocks=$$(str);
	var h=0;// declare Height pour faire comparatif entre blocks
	arrBlocks.each(function(el,i){
		var eachHeight=el.getCoordinates().height;
		if(eachHeight>h){
			h=eachHeight;
		}
	});
	arrBlocks.each(function(el,i){
		el.setStyle('height',h);
	});
}

function switchForm(aToActiv,aToHide){
// aFrom = elements de formulaire activant les elements : utile ?
// aToActiv = tableau d'elements e montrer
// aToHide = tableau d'elements e cacher
	if(aToActiv==null){}
	else{
		for(var i=0;aToActiv.length>i;i++){
			if(aToActiv[i].className.match(/hide/)){
				removeClass(aToActiv[i], "hide");

			}
		}
	}
	if(aToHide==null){}
	else{
		for(i=0;aToHide.length>i;i++){
			aToHide[i].className+=" hide";
		}
	}
}

/************
* 3.2.1 GO !
************/
$e.add(window,'resize',function(){
	popLayer.refixSize();
});

window.addEvent('load', function() {
});

window.addEvent('domready', function() {
	if(document.getElementById('cDirect')) {
		//installe les iframe necessaire pour passer devant les select
			if(/MSIE [56]/.test(navigator.userAgent))
			{
        setTimeout("lunchFrame();",1000);
			}
	}
	setTimeout("generateElements();",500);
	resultsMDR();
	fixHeightBlocks()
});

function majDetailPanierQta(pArticleQtaUniqueId, pQta){
    var tbArticleQta = document.getElementById(pArticleQtaUniqueId);
    if (tbArticleQta != null)
    {
        tbArticleQta.value = pQta;
    }
}

function majDetailPanierPrice(pMajDetailPanierPrice, pPrice){
    var divArticlePrice = document.getElementById(pMajDetailPanierPrice);
    if (divArticlePrice != null)
    {
        divArticlePrice.innerHTML = '' + pPrice;
    }
}
function sendInfoToGoogle()
{    
    try
    {
        var limitationGoogleAnalytics = true;
        if (!limitationGoogleAnalytics)
        {
            var pageTracker = _gat._getTracker("UA-3928615-3");
            pageTracker._initData();
            pageTracker._trackPageview();
        }
    }
    catch(err){}
}

