var browser_name = null;
var browser_version = null;
var isIE6 = false;
var isSafari = false;

var photoEffectActive = true;


var drop = null;

var kwick_div;
var kwick_div_has_fixed_width;
var kwicks;
var fx;
var currentlyDraggedKwick;
var currentlyDraggedSize;

var lastEntered = null;
var effetPanier;
var periodical;
var fxx;

var fxBigTaille = null;
var bigTailleUp = false;
var bigTailleDown = false;
/*function showBigTaille(e) {
  var big_taille_span = $('big_taille-miniprod');
  if (big_taille_span == null || (!$defined(big_taille_span))) {
    return;
  }
  if (fxBigTaille == null) {
    fxBigTaille = new Fx.Tween(big_taille_span, {property:'top', duration: 200});
  }
  if (bigTailleDown == true) {
    fxBigTaille.cancel();
  }
  bigTailleUp = true;
  bigTailleDown = false;
  if (window.ie6) {
    fxBigTaille.start(-60);
  } else {
    fxBigTaille.start(303);
  }
}
function hideBigTaille(e) {
  var big_link = $('big_kwick_link');
  if (big_link == null || (!$defined(big_link))) {
    return;
  }
  var big_taille_span = $('big_taille-miniprod');
  if (big_taille_span == null || (!$defined(big_taille_span))) {
    return;
  }
  var big_coords = big_link.getCoordinates();
  //alert('mouse : '+e.clientX+'.'+e.clientY+"\nelem : "+big_coords.left+"."+big_coords.top+"\nelemSize : "+big_coords.width+"."+big_coords.height);
  //alert(big_link.getPosition().x+"."+big_link.getPosition().y);
  var elemTop = big_coords.top;
  if (window.ie) {
    elemTop += 215;
  }
  if (e != null && e.clientX >= big_coords.left && e.clientX < big_coords.left + big_coords.width && e.clientY > big_coords.top && e.clientY < elemTop + big_coords.height) {
    return;
  }
  //alert('mouse : '+e.clientX+'.'+e.clientY+"\nelem : "+big_coords.left+"."+big_coords.top+"\nelemSize : "+big_coords.width+"."+big_coords.height);
  if (fxBigTaille == null) {
    fxBigTaille = new Fx.Tween(big_taille_span, {property:'top', duration: 200});
  }
  if (bigTailleUp == true) {
    fxBigTaille.cancel();
  }
  bigTailleUp = false;
  bigTailleDown = true;
  if (window.ie6) {
    fxBigTaille.start(0);
  } else {
    fxBigTaille.start(363);
  }
}*/

function stopPhotoEffect() {
	photoEffectActive = false;
}
function showMarque(nomMarque){
	if (photoEffectActive == false) {
		return;
	}
	img_marque = document.getElementById('photo_marque_'+nomMarque);
	all_marques = $$('.marque_img');
	if (all_marques != null) {
		for (i = 0; i < all_marques.length; i++) {
			if (all_marques[i].id != 'photo_marque_'+nomMarque) {
				all_marques[i].style.display = 'none';
			}
		}
	}

	img_princ = document.getElementById('photo_principale');
	if (img_princ != null) {
		if (img_marque != null) {
			img_princ.style.display = 'none';
			img_marque.style.display = 'block';
		} else {
			img_princ.style.display = 'block';
		}
	}
}
function showRayon(event, elem){
	myEvent = new Event(event);
	//alert(myEvent.page.y);
	myElem = new Element(elem);
	coords = myElem.getCoordinates();
	//alert('left : '+coords.left+'\ntop : '+coords.top+'\nwidth : '+coords.width+'\nheight : '+coords.height);
	// are we still inside ?
	mouseX = myEvent.page.x;
	mouseY = myEvent.page.y;
	minX = coords.left+2;
	maxX = minX + coords.width-4;
	minY = coords.top+2;
	maxY = minY + coords.height-4;
	if (mouseX > minX && mouseX < maxX && mouseY > minY && mouseY < maxY) {
		return;
	}
	if (photoEffectActive == false) {
		return;
	}
	all_marques = $$('.marque_img');
	if (all_marques != null) {
		for (i = 0; i < all_marques.length; i++) {
			all_marques[i].style.display = 'none';
		}
	}

	img_princ = document.getElementById('photo_principale');
	if (img_princ != null) {
		img_princ.style.display = 'block';
	}
}

function supprPanier(prod,taille){
	panier = $('panier_table');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Request({url: '/ajax_panier', method: 'post', data: {
		type : 'suppr',
		prod: prod,
		taille: taille
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		if (drop == null) {
			drop = $('panier_table');
		}
		drop.innerHTML = result;
		drop.setStyles({'visibility': 'visible'});
	} }).send();
}

function commitPanier(prod_barcode){
	panier = $('panier_table');
	panier.setStyles({'visibility': 'hidden'});
	prod_taille = $('taille').value;
	var myAjax = new Request({url: '/ajax_panier', method: 'post', data: {
			codeProd : prod_barcode,
			taille : prod_taille
		}, onComplete: function(result) {
			//alert('complete ! '+result);
			//panier.setInnerHTML($result);
			panier.innerHTML = result;
			panier.setStyles({'visibility': 'visible'});
	} }).send();
}

function setTab1() {
	var tab1 = $('tab1');
	var tab2 = $('tab2');

	var tab_button1 = $('tab_button1');
	var tab1_div1 = $('tab1link_div1');
	var tab1_div2 = $('tab1link_div2');
	var tab_button2 = $('tab_button2');
	var tab2_div1 = $('tab2link_div1');
	var tab2_div2 = $('tab2link_div2');

	//tab_button1.setStyles({'padding-bottom': '5px', 'background': '#e6e6e6'});
	//tab_button2.setStyles({'padding-bottom': '4px', 'background': '#fff'});

	tab_button1.setStyles({'padding-bottom': '5px'});
	tab_button2.setStyles({'padding-bottom': '4px'});

	url_bg = tab1_div1.getStyle('background-image');
	url_begin_pos = url_bg.lastIndexOf('/');
	url_begin = url_bg.substring(0, url_begin_pos);

	tab1_div1.setStyle('background-image', url_begin+'/tab_grey_left.gif)');
	tab1_div2.setStyle('background-image', url_begin+'/tab_grey_right.gif)');
	tab2_div1.setStyle('background-image', url_begin+'/tab_white_left.gif)');
	tab2_div2.setStyle('background-image', url_begin+'/tab_white_right.gif)');

	tab2.setStyles({'display': 'none'});
	tab1.setStyles({'display': 'inline'});
}
function setTab2() {
	var tab1 = $('tab1');
	var tab2 = $('tab2');

	var tab_button1 = $('tab_button1');
	var tab1_div1 = $('tab1link_div1');
	var tab1_div2 = $('tab1link_div2');
	var tab_button2 = $('tab_button2');
	var tab2_div1 = $('tab2link_div1');
	var tab2_div2 = $('tab2link_div2');

	//tab_button2.setStyles({'padding-bottom': '5px', 'background': '#e6e6e6'});
	//tab_button1.setStyles({'padding-bottom': '4px', 'background': '#fff'});

	tab_button1.setStyles({'padding-bottom': '4px'});
	tab_button2.setStyles({'padding-bottom': '5px'});

	url_bg = tab1_div1.getStyle('background-image');
	url_begin_pos = url_bg.lastIndexOf('/');
	url_begin = url_bg.substring(0, url_begin_pos);

	tab1_div1.setStyle('background-image', url_begin+'/tab_white_left.gif)');
	tab1_div2.setStyle('background-image', url_begin+'/tab_white_right.gif)');
	tab2_div1.setStyle('background-image', url_begin+'/tab_grey_left.gif)');
	tab2_div2.setStyle('background-image', url_begin+'/tab_grey_right.gif)');

	tab1.setStyles({'display': 'none'});
	tab2.setStyles({'display': 'inline'});
}

function changeImage(idImage,nbImages){
	for(i = 1 ; i <= nbImages; i++){
		tmpimg = document.getElementById('img'+i);
		if (tmpimg != null) {
			tmpimg.style.display = 'none';
		}
	}
	document.getElementById('img'+idImage).style.display = 'block';
}



var sizesAssocieMessage = null;
var fxHideSizesAssocieMessage = null;
var fxShowSizesAssocieMessage = null;
var fxDragSizesAssocieMessage = null;

function displaySizesAssocieMessage(ev, sizes) {
	if (!ev) {return;}
	e = new Event(ev);
	if (sizesAssocieMessage == null) {
		sizesAssocieMessage = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	var innerContent = 'Tailles disponibles :<br/>';
	for (var i = 0; i < sizes.length; i++) {
		num_rest = sizes[i].substring(0, 1);
		taille_name = sizes[i].substring(1);
		//alert(num_rest+' : '+taille_name);
		extraStyle = '';
		if (num_rest == 0) {
			extraStyle = ' color: red; text-decoration: line-through;';
		} else if (num_rest == 1) {
			extraStyle = ' color: orange;';
		}
		innerContent = innerContent + "<span style=\"display: block; float: left; border: solid 1px #808080; background-color: #e0e0e0; padding: 0 3px 0 3px; margin: 2px;"+extraStyle+"\">"+taille_name+"</span> ";
	}
	sizesAssocieMessage.innerHTML = innerContent;
	sizesAssocieMessage.setStyles({'width': '120px', 'height': 'auto'});
	if (fxDragSizesAssocieMessage == null) {
		fxDragSizesAssocieMessage = sizesAssocieMessage.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowSizesAssocieMessage == null) {
		fxShowSizesAssocieMessage = new Fx.Tween(sizesAssocieMessage, {property:'opacity', duration:0});
	}*/
	if (isIE6 == true) {
		sizesAssocieMessage.setStyles({'top': e.page.y - 40 - sizesAssocieMessage.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		sizesAssocieMessage.setStyles({'top': e.page.y - 20 - sizesAssocieMessage.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideSizesAssocieMessage != null) {
		fxHideSizesAssocieMessage.cancel();
	}
	/*fxShowSizesAssocieMessage.cancel();
	fxShowSizesAssocieMessage.start(0.8);*/
	if (fxDragSizesAssocieMessage != null) {
		fxDragSizesAssocieMessage.cancel();
		if (isIE6 == false) {
			fxDragSizesAssocieMessage.start(e); // start the event manual
		}
	}
}
function hideSizesAssocieMessage(ev) {
	if (sizesAssocieMessage == null) {
		return;
	}
		if (fxHideSizesAssocieMessage == null) {
		fxHideSizesAssocieMessage = new Fx.Tween(sizesAssocieMessage, {property:'opacity', duration:500, onComplete: function() {
							sizesAssocieMessage.dispose();
							sizesAssocieMessage = null;
							fxHideSizesAssocieMessage = null;
							fxDragSizesAssocieMessage.cancel();
							fxDragSizesAssocieMessage = null;
						} });
	}
	if (fxShowSizesAssocieMessage != null) {
		fxShowSizesAssocieMessage.cancel();
	}
	fxHideSizesAssocieMessage.cancel();
	fxHideSizesAssocieMessage.start(0);
}

function overAssocie(ev, idImage, nbImages, sizes) {
	changeImageAss(idImage, nbImages);
	displaySizesAssocieMessage(ev, sizes);
	//alert(sizes);
}
function outAssocie(ev, nbImages) {
	hideSizesAssocieMessage(ev);
	changeImageAss(1, nbImages);
}
function changeImageAss(idImage,nbImages){
	if (idImage != 1) {
		document.getElementById('img1').style.display = 'none';
	}
	for(i = 2 ; i <= nbImages+1; i++){
		tmpimg = document.getElementById('imgAss'+i);
		if (tmpimg != null) {
			tmpimg.style.display = 'none';
		}
	}
	if (idImage == 1) {
		document.getElementById('img1').style.display = 'block';
	} else {
		document.getElementById('imgAss'+idImage).style.display = 'block';
	}
}


function header_news_letter() {
	var email_nl_input = $('newsletter_email');

	params = {};
	params['email'] = email_nl_input.value;

	var myAjax = new Request({url: '/ajax_header_connect_newsletter', method: 'post', data: params, onComplete: function(result) {
		if (result.substring(0, 2) == 'OK') {
			rescode = error_code = parseInt(result.substring(3, result.length));
			//alert(rescode);
			var nl_div = $('header_newsletter');
			if (nl_div != null) {
				nl_div.innerHTML = '<h1>NEWSLETTER</h1>\n<br/>\n<p>Votre inscription à la NewsLetter MD&nbsp;STORE a bien &eacute;t&eacute; enregistr&eacute;e.</p>';
			} else {
				alert('Votre inscription à la NewsLetter MD STORE a bien été enregistrée.');
			}
			return;
		}
		// If we get there, we add a KO
		error_code = parseInt(result.substring(3, result.length));

		error_msg = 'Erreur interne : '+error_code;
		if (error_code == 3) {
			error_msg = 'Veuillez saisir votre adresse email';
		} else if (error_code == 4) {
			error_msg = 'Email non valide';
		} else {
			error_msg = 'Erreur inconnue';
		}
		alert(error_msg);
	} }).send();	
}

function header_run_search() {
	var search_input = $('head_rech_in');
	if (search_input != null) {
		var search_val = search_input.value;
		document.location = "/recherche/"+escape(search_val);
	}
}

function browserIE6() {
	if (browser_version.indexOf('MSIE 6.0') != -1) {
		return true;
	}
	return false;
}

function validJeuTrace() {
	var inp_nom = $('jeu_trace_nom');
	var inp_prenom = $('jeu_trace_prenom');
	var inp_email = $('jeu_trace_email');
	var inp_code = $('jeu_trace_code');

	var nom = inp_nom.value;
	var prenom = inp_prenom.value;
	var email = inp_email.value;
	var code = inp_code.value;

	if(nom == '' || prenom == '' || email == '' || code == '') {
		alert('Veuillez completer le formulaire');
		return;
	}

	var trace_title_ident = $('trace_title_ident');
	var trace_table_ident = $('trace_table_ident');
	var trace_button = $('trace_accueil_form_valid_link');

	trace_button.setStyle('display', 'none');

	var myAjax = new Request({url: '/ajax_trace', method: 'post', data: {
		nom : nom,
		prenom: prenom,
		email: email,
		code: code
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		trace_title_ident.setStyle('display', 'none');
		trace_table_ident.setStyle('display', 'none');

		if (result == 'OK') {
			$('trace_insc_success').setStyle('display', 'block');
		} else {
			$('trace_insc_echec').setStyle('display', 'block');
		}
	} }).send();
}

function initJeuTrace() {
	var trace_button = $('trace_accueil_form_valid_link');
	if (trace_button == null) {
		return;
	}

	trace_button.addEvent('click', validJeuTrace);
}

window.addEvent('domready', function() {
	browser_name = new String(navigator.appName);
	browser_version = new String(navigator.appVersion);
	if (browser_version.indexOf('MSIE 6.0') != -1) {
		isIE6 = true;
	} else if (browser_version.indexOf('afari') != -1) {
		isSafari = true;
	}

	initJeuTrace();

	// Let's deal with the news-letter input.
	var nl_input = $('newsletter_email');
	if (nl_input != null) {
		nl_input.addEvent('focus', function(event) {
			var nl_color = this.getStyle('color');
			if (nl_color != '#000000') {
				this.setStyle('color', '#000000');
				this.value="";
			}
		});
	}

	var search_input = $('head_rech_in');
	if (search_input != null) {
		search_input.addEvent('keypress', function(event) {
			var myEvent = new Event(event);
			if (myEvent.key == 'enter') {
				var formular = $('search_form');
				if (formular != null) {
					formular.submit();
				}
			}
		});

		new Autocompleter.Request.JSON('head_rech_in', '/ajax_search_autocomplete', {
			'postVar': 'search'
		});
	}
});


function chgPanierNum(prod, taille, num){
	//alert(prod+" : "+taille); return;
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Request({url: '/ajax_panier2', method: 'post', data: {
		type : 'chgnum',
		prod: prod,
		taille: taille,
		num: num
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).send();
}
function panierPointClickPortOffert(val) {
	v50points = $('50points');
	v300points = $('300points');
	if (val == false) {
		setFidelite(0);
		return;
	}
	setFidelite(1);
	// val == true
	/*if (v300points != null) {
		setFidelite(1);
		if (v300points.checked == true) {
			v300points.checked = false;
			unsetRemPointsFidelite();
		}
	}*/
	if (v300points.checked == true) {
		v300points.checked = false;
	}
}
function panierPointClickRemise(val) {
	v50points = $('50points');
	v300points = $('300points');

	if (v50points != null) {
		if (v50points.checked == true) {
			v50points.checked = false;
		}
	}


	if (val == false) {
		setFidelite(0);
		//unsetRemPointsFidelite();
	} else {
		setFidelite(2);
		//setRemPointsFidelite();
	}
	// val == true
}
function setFidelite(val) {
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	/*if (isSet == true) {
		boolVal = 1;
	} else {
		boolVal = 0;
	}*/
	var myAjax = new Request({url: '/ajax_panier2', method: 'post', data: {
		type : 'chgPoints',
		val: val
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).send();
}


function recapPointClickPortOffert(val) {
	v50points = $('50points');
	v300points = $('300points');
	if (val == false) {
		setFideliteRecap(0);
		return;
	}
	setFideliteRecap(1);
	// val == true
	/*if (v300points != null) {
		setFidelite(1);
		if (v300points.checked == true) {
			v300points.checked = false;
			unsetRemPointsFidelite();
		}
	}*/
	if (v300points.checked == true) {
		v300points.checked = false;
	}
}
function recapPointClickRemise(val) {
	v50points = $('50points');
	v300points = $('300points');

	if (v50points != null) {
		if (v50points.checked == true) {
			v50points.checked = false;
		}
	}


	if (val == false) {
		setFideliteRecap(0);
		//unsetRemPointsFidelite();
	} else {
		setFideliteRecap(2);
		//setRemPointsFidelite();
	}
	// val == true
}
function setFideliteRecap(val) {
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	/*if (isSet == true) {
		boolVal = 1;
	} else {
		boolVal = 0;
	}*/
	var myAjax = new Request({url: '/ajax_recap', method: 'post', data: {
		val: val
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).send();
}
/*function setRemPointsFidelite() {
	setUnsetRemPointsFidelite(true);
}
function unsetRemPointsFidelite() {
	setUnsetRemPointsFidelite(false);
}
function setUnsetRemPointsFidelite(isSet) {
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	if (isSet == true) {
		boolVal = 1;
	} else {
		boolVal = 0;
	}
	var myAjax = new Request({url: '/ajax_panier2', method: 'post', data: {
		type : 'chgPoints',
		val: boolVal
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).send();
}*/
function supprPanier2(prod,taille){
	//alert(prod+" : "+taille); return;
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Request({url: '/ajax_panier2', method: 'post', data: {
		type : 'suppr',
		prod: prod,
		taille: taille
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).send();
}

var slidersHahsmap = {};
var fxHashmap = {};

function link_onover(link, divname) {
	if (fxHashmap == null) {
		fxHashmap = {};
	}
	if (fxHashmap[divname] == null) {
		fxHashmap[divname] = new Fx.Tween(link, {property:'background-color', duration: 500});
	} else {
		effet = fxHashmap[divname];
		effet.cancel();
	}
	link.setStyle('background-color', '#E0E0E0');
}
function link_onout(link, divname) {
	if (fxHashmap == null) {
		fxHashmap = {};
	}
	if (fxHashmap[divname] == null) {
		effet = fxHashmap[divname] = new Fx.Tween(link, {property:'background-color',duration: 500});
	} else {
		effet = fxHashmap[divname];
	}
	effet.cancel();
	effet.start('#E0E0E0', '#FFFFFF');
}

function slideCmdeUp(divname) {
	if (slidersHahsmap == null) {
		slidersHahsmap = {};
	}
	if (slidersHahsmap[divname] != null) {
		slider = slidersHahsmap[divname];
	} else {
		div = $(divname);
		if (div != null) {
			div.setStyle('display', 'block');
		}
		slider = new Fx.Slide(divname);
		slidersHahsmap[divname] = slider;
		slider.hide();
	}
	slider.toggle();
}

function changeAvoirSelect(totalAmount) {
	avoirs = $$('.avoir');
	totalAvoirs = 0;
	unchecked = new Array();
	avoirs.each(function(avoir, i) {
			if (avoir == null) {
				return;
			}
			if (avoir.checked == false) {
				unchecked.push(avoir);
				return;
			}
			avoir_num = avoir.name.substring(6);
			if (avoir_num == null) {
				return;
			}
			avoir_val = $('val_'+avoir_num);
			if (avoir_val == null || avoir_val.innerHTML == null) {
				return;
			}
			totalAvoirs += parseFloat(avoir_val.innerHTML);
		});
	totalAvoirs = Math.round(totalAvoirs * 1000) / 1000;
	restant = totalAmount - totalAvoirs;
	restant = Math.round(restant * 1000) / 1000;
	reg_par = $('reglement_para');
	reglement_div = $('reglement');
	reglement_cheque_div = $('reglement-cheque');
	reglement_cheque_impossible = $('reglement-cheque-impossible');
	cartebleue = $('cartebleue');
	cheque = $('cheque');
	
	if (restant > 0) {
		unchecked.each(function(avoir, i) {
				if (avoir == null) {
					return;
				}
				avoir.disabled = false;
			});

		if (totalAvoirs != 0) {
			if (reg_par != null) {
				// Cache le paiement par cheque si avoir utilisé
				reglement_cheque_div.setStyle('display', 'none');
				reglement_cheque_impossible.setStyle('display', 'block');
				
				// Uncheck le cheque au cas ou cheke
				cheque.checked = false;
				cartebleue.checked = true;
				
				reg_par.innerHTML = 'Vous choisissez de r&eacute;gler le <u>montant restant <b>[ '+restant+' &euro; ]</b></u> par';
			}
		} else {
			if (reg_par != null) {
				// Affiche le paiement par cheque si avoir utilisé
				reglement_cheque_div.setStyle('display', 'block');
				reglement_cheque_impossible.setStyle('display', 'none');
				reg_par.innerHTML = 'Vous choisissez de r&eacute;gler votre commande par';
			}
		}
		if (reglement_div != null) {
			reglement_div.setStyle('visibility', 'visible');
		}
	} else {
		unchecked.each(function(avoir, i) {
				if (avoir == null) {
					return;
				}
				avoir.disabled = true;
			});
		if (reglement_div != null) {
			reglement_div.setStyle('visibility', 'hidden');
		}
	}
}


var dragDropMessage1 = null;
var fxHideMessage1 = null;
var fxShowMessage1 = null;
var fxDragMessage1 = null

function displayDragDropMessage1(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = 'Glisser la taille<br/>choisie jusqu\'au<br/>panier';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Tween(dragDropMessage1, {property:'opacity', duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.cancel();
	}
	/*fxShowMessage1.cancel();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.cancel();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function displayDragDropMessage2(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = '<font color="orange"><u>Derni&egrave;re pi&egrave;ce<br/>en stock !!!</u></font><br/>Glisser jusqu\'au<br/>panier';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Tween(dragDropMessage1, {property:'opacity', duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.cancel();
	}
	/*fxShowMessage1.cancel();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.cancel();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function displayDragDropMessage3(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = '<font color="red">Cette taille n\'est<br/>plus disponible.</font>';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Tween(dragDropMessage1, {property:'opacity', duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.cancel();
	}
	/*fxShowMessage1.cancel();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.cancel();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function hideDragDropMessage1(ev) {
	if (dragDropMessage1 == null) {
		return;
	}

	if (fxHideMessage1 == null) {
		fxHideMessage1 = new Fx.Tween(dragDropMessage1, {property:'opacity', duration:500, onComplete: function() {
								dragDropMessage1.dispose();
								dragDropMessage1 = null;
								fxHideMessage1 = null;
								fxDragMessage1.cancel();
								fxDragMessage1 = null;
							} });
	}
	if (fxShowMessage1 != null) {
		fxShowMessage1.cancel();
	}
	fxHideMessage1.cancel();
	fxHideMessage1.start(0);
}
function hideDragDropMessage1IE6(ev) {
	if (dragDropMessage1 == null) {
		return;
	}
	fxDragMessage1.cancel();
	fxDragMessage1 = null;

	if (fxHideMessage1 == null) {
		fxHideMessage1 = new Fx.Tween(dragDropMessage1, {property:'opacity', duration:500, onComplete: function() {
								dragDropMessage1.dispose();
								dragDropMessage1 = null;
								fxHideMessage1 = null;
							} });
	}
	if (fxShowMessage1 != null) {
		fxShowMessage1.cancel();
	}
	fxHideMessage1.cancel();
	fxHideMessage1.start(0);
}

function disconnect(redirect_uri) {
	var myAjax = new Request({url: '/ajax_cli_disconnect', method: 'post', data: {}, onComplete: function(result) {
			//alert(result);
			if (redirect_uri != null) {
				window.location = redirect_uri;
			} else {
				window.location = window.location;
				//window.location.reload();
			}
		} }).send();
}

function scrollToTop() {
	var scroller = new Fx.Scroll(window, {
		wait: false,
		duration: 400
	});
	scroller.toTop();
}

//window.onscroll = resize_scroll;
//window.onresize = resize_scroll;

var fxPanier = null;
var fxImage = null;
function resize_scroll(e) {
	window_scroll = window.getScrollTop();
	footer_div = $('footer');
	if (footer_div == null) {
		// ERROR :
		return;
	}
	footertoppos = footer_div.getCoordinates().top;
	footermargintop = footer_div.getStyle('margin-top');
	if (footermargintop == null || footermargintop.length == 0) {
		footermargintop = 0;
	} else {
		if (footermargintop.test('px$', 'i') == true) {
			footermargintop = footermargintop.toInt();
		} else {
			// ERROR
			return;
		}
	}

	bottom_limit = footertoppos - footermargintop;
	bottom_limit -= 20; // security;

	movePanier(window_scroll, bottom_limit);
	moveImage(window_scroll, bottom_limit);
}
function movePanier(window_scroll, bottom_limit) {
	panier_div = $('right-block');
	if (panier_div == null) {
		return;
	}
	coords = panier_div.getCoordinates();

	margin_top = panier_div.getStyle('margin-top');
	if (margin_top == null || margin_top.length == 0) {
		margin_top = 0;
	} else {
		if (margin_top.test('px$', 'i') == true) {
			margin_top = margin_top.toInt();
		} else {
			// ERROR
			return;
		}
	}
	margin_bottom = panier_div.getStyle('margin-bottom');
	if (margin_bottom == null || margin_bottom.length == 0) {
		margin_bottom = 0;
	} else {
		if (margin_bottom.test('px$', 'i') == true) {
			margin_bottom = margin_bottom.toInt();
		} else {
			// ERROR
			return;
		}
	}

	zeroPos = coords.top - margin_top;
	maximumMargin = bottom_limit - coords.height - margin_bottom - zeroPos;

	if (margin_top > maximumMargin) {
		panier_div.setStyle('margin-top', maximumMargin);
		margin_top = maximumMargin;
	}

	requiredPos = window_scroll + 5;
	final_margin = requiredPos - zeroPos;

	if (final_margin > maximumMargin) {
		final_margin = maximumMargin;
	} if (final_margin < 0) {
		final_margin = 0;
	}

	if (final_margin != margin_top) {
		if (fxPanier == null) {
			fxPanier = new Fx.Tween(panier_div, {property:'margin-top', duration:600});
		}
		fxPanier.cancel();
		fxPanier.start(final_margin);
	}
}
function moveImage(window_scroll, bottom_limit) {
	time_fx = 200;
	image_div = $('fiche_prod_photo');
	if (image_div == null) {
		time_fx = 600;
		image_div = $('accueil_img1');
		if (image_div == null) {
			time_fx = 400;
			image_div = $('img_rayon');
			if (image_div == null) {
				image_div = $('rayon-spe-container');
				if (image_div == null) {
					return;
				}
			}
		}
	}
	coords = image_div.getCoordinates();

	margin_top = image_div.getStyle('margin-top');
	if (margin_top == null || margin_top.length == 0) {
		margin_top = 0;
	} else {
		if (margin_top.test('px$', 'i') == true) {
			margin_top = margin_top.toInt();
		} else {
			// ERROR
			return;
		}
	}
	margin_bottom = image_div.getStyle('margin-bottom');
	if (margin_bottom == null || margin_bottom.length == 0) {
		margin_bottom = 0;
	} else {
		if (margin_bottom.test('px$', 'i') == true) {
			margin_bottom = margin_bottom.toInt();
		} else {
			// ERROR
			return;
		}
	}

	zeroPos = coords.top - margin_top;
	maximumMargin = bottom_limit - coords.height - margin_bottom - zeroPos;

	if (margin_top > maximumMargin) {
		image_div.setStyle('margin-top', maximumMargin);
		margin_top = maximumMargin;
	}

	requiredPos = window_scroll + 5;
	final_margin = requiredPos - zeroPos;

	if (final_margin > maximumMargin) {
		final_margin = maximumMargin;
	} if (final_margin < 0) {
		final_margin = 0;
	}

	if (final_margin != margin_top) {
		if (fxImage == null) {
			fxImage = new Fx.Tween(image_div, {property:'margin-top', duration:time_fx});
		}
		fxImage.cancel();
		fxImage.start(final_margin);
	}
}


var stopFxMouseBool = false;
var fxImg1 = null;
var fxImg1txt = null;
var fxImg2 = null;
var fxImg2txt = null;
var fxImg3 = null;
var fxImg3txt = null;
var fxImg4 = null;
var fxImg4txt = null;

function stopFxMouse() {
	stopFxMouseBool = true;
}

function initMouseOnImg1() {
	div = $('pola_div_1');
	if (fxImg1 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg1 = new Fx.Tween(img, {property:'opacity', duration:300});
				txt = childrenbis[2];
				fxImg1txt = new Fx.Tween(txt, {property:'color', duration:300});
			}
		}
	}
}
function fxMouseOnImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.cancel();
		fxImg1txt.cancel();
		fxImg1.start(0);
		fxImg1txt.start('#ffffff');
	}
}
function fxMouseOutImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.cancel();
		fxImg1txt.cancel();
		fxImg1.start(1);
		fxImg1txt.start('#808080');
	}
}

function initMouseOnImg2() {
	div = $('pola_div_2');
	if (fxImg2 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg2 = new Fx.Tween(img, {property:'opacity', duration:300});
				txt = childrenbis[2];
				fxImg2txt = new Fx.Tween(txt, {property:'color', duration:300});
			}
		}
	}
}
function fxMouseOnImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.cancel();
		fxImg2txt.cancel();
		fxImg2.start(0);
		fxImg2txt.start('#ffffff');
	}
}
function fxMouseOutImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.cancel();
		fxImg2txt.cancel();
		fxImg2.start(1);
		fxImg2txt.start('#808080');
	}
}

function initMouseOnImg3() {
	div = $('pola_div_3');
	if (fxImg3 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg3 = new Fx.Tween(img, {property:'opacity', duration:300});
				txt = childrenbis[2];
				fxImg3txt = new Fx.Tween(txt, {property:'color', duration:300});
			}
		}
	}
}
function fxMouseOnImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.cancel();
		fxImg3txt.cancel();
		fxImg3.start(0);
		fxImg3txt.start('#ffffff');
	}
}
function fxMouseOutImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.cancel();
		fxImg3txt.cancel();
		fxImg3.start(1);
		fxImg3txt.start('#808080');
	}
}


function initMouseOnImg4() {
	div = $('pola_div_4');
	if (fxImg4 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg4 = new Fx.Tween(img, {property:'opacity', duration:300});
				txt = childrenbis[2];
				fxImg4txt = new Fx.Tween(txt, {property:'color', duration:300});
			}
		}
	}
}
function fxMouseOnImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.cancel();
		fxImg4txt.cancel();
		fxImg4.start(0);
		fxImg4txt.start('#ffffff');
	}
}
function fxMouseOutImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.cancel();
		fxImg4txt.cancel();
		fxImg4.start(1);
		fxImg4txt.start('#808080');
	}
}

function changeFraisPort(prix) {
	var fraisport_p = $('frais_port');
	if (fraisport_p == null) {
		return;
	}
	if (prix == 0) {
		fraisport_p.innerHTML = 'Montant des frais de ports : <b>Offert</b><input name="frais_port" value="'+prix+'" type="hidden">'
	} else {
		fraisport_p.innerHTML = 'Montant des frais de ports : <b>'+prix+' &#8364;</b><input name="frais_port" value="'+prix+'" type="hidden">'
	}
}
function changeFraisPortVal(val) {
	var fraisport_p = $('frais_port');
	if (fraisport_p == null) {
		return;
	}
	fraisport_p.innerHTML = 'Montant des frais de ports : <b>'+val+' &#8364;</b><input name="frais_port" value="'+val+'" type="hidden">'
}
function getAjaxLivraison(pays_val, code_postal_val) {
	var livr_div = $('livr_div');
	if (livr_div == null) {
		return;
	}
	if (pays_val == '0') {
		livr_div.innerHTML = '<div id="livr_div2"></div>';
		changeFraisPortVal('???');
		return;
	}
	livr_div.innerHTML = '';
	var myAjax = new Request({url: '/ajax_update_livraison', method: 'post', data: {
		'pays': pays_val,
		'code_postal': code_postal_val
	}, onComplete: function(result) {
		livr_div.innerHTML = result;
	} }).send();
}
function cpChanged($cp) {
	if ($cp == null) {
		return;
	}

	var pays = '';
	var paysInput = $('pays');

	if (paysInput != null) {
		pays = paysInput.value;
	}

	getAjaxLivraison(pays, $cp);
}
function paysChanged($pays) {
	if ($pays == null) {
		return;
	}
	validPays($pays);

	var codePostalVal = '';
	var codePostalInput = $('code_postal');

	if (codePostalInput != null) {
		codePostalVal = codePostalInput.value;
	}

	getAjaxLivraison($pays, codePostalVal);
}

function changePage(url, page, taille) {
	fullurl = url+"?page="+page;
	if (taille != null) {
		fullurl = fullurl+"&taille="+taille;
	}
	window.location = fullurl;
}

function changeNbart(url, nbart, nbart_orig, page_orig, taille) {
	fullurl = url+"?nbart="+nbart;
	page_before = page_orig - 1;
	newpage_before = (page_before * nbart_orig / nbart);
	newpage_before = Math.floor(newpage_before);
	newpage = newpage_before + 1;
	//alert("page : "+page_orig+" / nbart_orig : "+nbart_orig+" / nbart : "+nbart+"\n"+Math.floor(newpage));
	if (newpage != 1) {
		fullurl = fullurl+"&page="+newpage;
	}
	if (taille != null) {
		fullurl = fullurl+"&taille="+taille;
	}
	window.location = fullurl;
}

function changeNbLines(url, nblines, nblines_orig, page_orig, taille) {
	fullurl = url+"?nblines="+nblines;
	page_before = page_orig - 1;
	newpage_before = (page_before * nblines_orig / nblines);
	newpage_before = Math.floor(newpage_before);
	newpage = newpage_before + 1;
	//alert("page : "+page_orig+" / nblines_orig : "+nblines_orig+" / nblines : "+nblines+"\n"+Math.floor(newpage));
	if (newpage != 1) {
		fullurl = fullurl+"&page="+newpage;
	}
	if (taille != null) {
		fullurl = fullurl+"&taille="+taille;
	}
	window.location = fullurl;
}

function load_cache_images(suppImages, cat) {

	var cache_imgs = ""
	if (cat == null || cat != true) {
		cache_imgs = '<img src="/images/charte/MDStoreLogo.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_pink.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_blue.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_orange.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/menu/icone_homme.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_on.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_pink.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_blue.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_orange.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_pink.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_pink_on.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_blue.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_orange.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_on.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_pink.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_blue.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_orange.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_basket.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_on.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_pink.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_pink_on.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_blue.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_orange.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_news.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_pink.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_blue_on.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_orange.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_promos.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_pink.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_blue.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_orange_on.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_panier.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_on.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_pink.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_blue.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_orange.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_store.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_on.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_pink.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_blue.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_orange.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_aide.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_on.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_pink.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_blue.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_orange.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_contact.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_on.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_pink.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_blue.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_orange.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_compte.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_on.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_pink.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_blue.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_orange.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_pink.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_blue.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_orange.gif" alt="Parrainage" class="cache_img" />\n\n<img src="/images/charte/menu/ami.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_pink.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_blue.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_orange.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/row.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_pink.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_blue.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_orange.gif" alt="row" class="cache_img" />\n\n<img src="/images/charte/bg-header.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_pink.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_blue.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_orange.gif" alt="background" class="cache_img" />\n\n<img src="/images/img-cb.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-pink.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-blue.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-orange.gif" alt="cb" class="cache_img" />\n\n<img src="/images/charte/onifin.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-pink.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-blue.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-orange.gif" alt="onifin" class="cache_img" />\n\n<img src="/images/charte/arrow-top.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-pink.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-blue.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-orange.gif" alt="arrow" class="cache_img" />\n\n<img src="/images/charte/bg-footer.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-femme.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-news.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-promos.gif" alt="bg" class="cache_img" />\n\n<img src="/images/charte/bg_menu_marques_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/bg_menu_marques.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/bg_menu_marques_bottom.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/charte/panier_bottom.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_bottomleft.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_bottomright.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_topleft.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_topright.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/charte/pa_txt_agl_bottom_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_bottom_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_top_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_top_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_bottom_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_bottom.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_right.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/catalogue/pict-epuise.gif" alt="bg" class="cache_img" />\n<img src="/images/catalogue/pict-promo.gif" alt="bg" class="cache_img" />\n<img src="/images/catalogue/pict-new.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/metalic-bottom.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/infoline.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_logo.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_top_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_bottom_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_top_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_bottom_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_top.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom_right.gif" alt="bg" class="cache_img" />\n<img src="/images/panier/panier.gif" alt="panier" class="cache_img" />\n';
	}

	if (suppImages != null) {
		suppImages.each(function(myvar, index) {
			cache_imgs += "<img src=\""+myvar+"\" alt=\"cache\" class=\"cache_img\" />\n";
		});
	}
	imgs_div = $('cache_imgs');
	imgs_div.innerHTML = cache_imgs;
}


Element.extend({

	/*
	Property: scrollTo
		Scrolls the element to the specified coordinated (if the element has an overflow)

	Arguments:
		x - the x coordinate
		y - the y coordinate

	Example:
		>$('myElement').scrollTo(0, 100)
	*/

	scrollTo: function(x, y){
		this.scrollLeft = x;
		this.scrollTop = y;
	},

	/*
	Property: getSize
		Return an Object representing the size/scroll values of the element.

	Example:
		(start code)
		$('myElement').getSize();
		(end)

	Returns:
		(start code)
		{
			'scroll': {'x': 100, 'y': 100},
			'size': {'x': 200, 'y': 400},
			'scrollSize': {'x': 300, 'y': 500}
		}
		(end)
	*/

	getSize: function(){
		return {
			'scroll': {'x': this.scrollLeft, 'y': this.scrollTop},
			'size': {'x': this.offsetWidth, 'y': this.offsetHeight},
			'scrollSize': {'x': this.scrollWidth, 'y': this.scrollHeight}
		};
	},

	/*
	Property: getPosition
		Returns the real offsets of the element.

	Arguments:
		overflown - optional, an array of nested scrolling containers for scroll offset calculation, use this if your element is inside any element containing scrollbars

	Example:
		>$('element').getPosition();

	Returns:
		>{x: 100, y:500};
	*/

	getPosition: function(overflown){
		overflown = overflown || [];
		var el = this, left = 0, top = 0;
		do {
			//alert(el.className+" : "+el.offsetLeft+"."+el.offsetTop);
			left += el.offsetLeft || 0;
			top += el.offsetTop || 0;
			el = el.offsetParent;
		} while (el);
		overflown.each(function(element){
			left -= element.scrollLeft || 0;
			top -= element.scrollTop || 0;
		});
		return {'x': left, 'y': top};
	},

	/*
	Property: getTop
		Returns the distance from the top of the window to the Element.

	Arguments:
		overflown - optional, an array of nested scrolling containers, see Element::getPosition
	*/

	getTop: function(overflown){
		return this.getPosition(overflown).y;
	},

	/*
	Property: getLeft
		Returns the distance from the left of the window to the Element.

	Arguments:
		overflown - optional, an array of nested scrolling containers, see Element::getPosition
	*/

	getLeft: function(overflown){
		return this.getPosition(overflown).x;
	},

	/*
	Property: getCoordinates
		Returns an object with width, height, left, right, top, and bottom, representing the values of the Element

	Arguments:
		overflown - optional, an array of nested scrolling containers, see Element::getPosition

	Example:
		(start code)
		var myValues = $('myElement').getCoordinates();
		(end)

	Returns:
		(start code)
		{
			width: 200,
			height: 300,
			left: 100,
			top: 50,
			right: 300,
			bottom: 350
		}
		(end)
	*/

	getCoordinates: function(overflown){
		var position = this.getPosition(overflown);
		var obj = {
			'width': this.offsetWidth,
			'height': this.offsetHeight,
			'left': position.x,
			'top': position.y
		};
		obj.right = obj.left + obj.width;
		obj.bottom = obj.top + obj.height;
		return obj;
	}

});

function advance_search_famille_changed(newVal) {
	var access_titre = $('td_accessoires_titre');
	var access_select = $('td_accessoires_select');

	if (access_titre != null && access_select != null) {
		if (newVal == 'ACCESSOIRE') {
			access_titre.setStyle('visibility', 'visible');
			access_select.setStyle('visibility', 'visible');

		} else {
			access_titre.setStyle('visibility', 'hidden');
			access_select.setStyle('visibility', 'hidden');
		}
	}
}



var PanierElement = new Class({
	initialize: function(el) {
		this.element = el;
		this.element.setStyle('z-index', '99');

		this.droppable = null;

		this.ajaxLoader = null;

		this.minHeight = 250;
		this.bottomHeight = 60;

		var children = el.getChildren();

		this.languette = children[0];
		this.content = children[1];

		this.droppables = [this.languette, this.content];

		this.marginTop = this.element.getStyle('margin-top').toInt();
		this.width = this.element.getStyle('width').toInt();
		this.height = this.element.getStyle('height').toInt();

		var languetteChildren = this.languette.getChildren();
		var qte_div = languetteChildren[0];
		var qte_div_children = qte_div.getChildren();
		this.languetteNumProds = qte_div_children[0];
		this.languetteNumProdsS = qte_div_children[1].getChildren()[0];
		var prix_div = languetteChildren[2];
		var prix_div_children = prix_div.getChildren();
		this.languettePrix = prix_div_children[0];

		this.parseContent();

		/*this.realContent = contentChildren[0];
		this.panierBottom = contentChildren[1];
		this.bottomPriceSpan = this.panierBottom.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0];

		this.prod_containers_divs = this.realContent.getChildren();
		this.panier_prods = [];
		this.prod_containers_divs.each(function(prod_container_div, i) {
				prod_div = prod_container_div.getChildren()[0];
				tmp_panier_prod = new PanierProd(prod_div);
				tmp_panier_prod.setPanier(this);
				this.panier_prods[this.panier_prods.length] = tmp_panier_prod;
			}.bind(this));*/

		this.parent = this.element.getParent();

		this.marginRequired = 30;

		this.fxPanier = new Fx.Tween(this.element, {property: 'top', duration:300});

		this.hiddenRightPosition = this.element.getStyle('right').toInt();
		this.slideInTimeoutID = -1;
		this.blockedOut = false;

		this.slideOutFx = new Fx.Tween(el, {property: 'right', duration: 200, onComplete: this.slideOutDone.bind(this)});
		this.slideInFx = new Fx.Tween(el, {property: 'right', duration: 200, onComplete: this.slideInDone.bind(this)});

		this.slidingOut = false;
		this.slidingIn = false;

		this.languette.addEvent('mouseover', function(e) {
			ev = new Event(e);
			this.mouseEntered(ev.page.x, ev.page.y);
		}.bind(this));

		this.content.addEvent('mouseover', function(e) {
			ev = new Event(e);
			this.mouseEntered(ev.page.x, ev.page.y);
		}.bind(this));

		this.languette.addEvent('mouseout', function(e) {
			ev = new Event(e);
			if (this.checkForSlideIn(ev.page.x, ev.page.y) == true) {
				//this.slideIn();
				this.slideInWithDelay(500);
			}
		}.bind(this));

		this.content.addEvent('mouseout', function(e) {
			var ev = new Event(e);
			if (this.checkForSlideIn(ev.page.x, ev.page.y) == true) {
				//this.slideIn();
				this.slideInWithDelay(500);
			}
		}.bind(this));

		window.addEvent('windowResized', this.onWindowChanged.bind(this));
		window.addEvent('windowScrolled', this.onWindowChanged.bind(this));
	},

	parseContent: function() {
		var contentChildren = this.content.getChildren();
		this.titreDiv = contentChildren[0];
		this.container = contentChildren[1].getChildren()[0].getChildren()[0].getChildren()[0];

		var containerChildren = this.container.getChildren();
		this.panier_table_div = containerChildren[0];
		this.panier_table = this.panier_table_div.getChildren()[0];

		var panier_table_children = this.panier_table.getChildren()[0].getChildren();

		this.panier_prods = [];

		for (var i = 1; i < panier_table_children.length; i++) {
			var panier_row = panier_table_children[i];
			if (panier_row.className == 'panier_prod_tr') {
				var new_panier_prod = new PanierProd(panier_row);
				this.panier_prods[this.panier_prods.length] = new_panier_prod;
				new_panier_prod.setPanier(this);
			}
		}

		this.refreshPriceAndQuantity();
	},

	getElement: function() {
		return this.element;
	},

	getDroppables: function() {
		return this.droppables;
	},

	onWindowChanged: function() {
		var window_scroll = window.getScrollTop();

		var panierCoords = this.element.getCoordinates();
		var parentCoords = this.parent.getCoordinates();
		var panierTop = panierCoords.top;

		if (panierTop != window_scroll + this.marginRequired) {
			var requiredPos = window_scroll + this.marginRequired - this.marginTop - parentCoords.top;

			if (requiredPos + this.marginTop + this.height > parentCoords.height) {
				requiredPos = parentCoords.height - this.marginTop - this.height;
			}
			if (requiredPos < 0) {
				requiredPos = 0;
			}

			this.fxPanier.cancel();
			this.fxPanier.start(requiredPos);
		}
	},

	mouseEntered: function(mouseX, mouseY) {
		if (this.slideInTimeoutID != -1) {	
			window.clearTimeout(this.slideInTimeoutID);
			this.slideInTimeoutID = -1;
		}
		this.slideOut();
	},

	mouseOut: function(mouseX, mouseY) {
	},

	slideOut: function() {
		if (this.slidingOut == true) {
			return;
		}
		this.slideOutFx.cancel();
		this.slideInFx.cancel();

		this.slidingIn = false;
		this.slidingOut = true;

		this.slideOutFx.start(this.getOutsideRightPos());
	},

	slideIn: function() {
		if (this.blockedOut == true) {
			return;
		}
		if (this.slidingIn == true) {
			return;
		}
		this.slideOutFx.cancel();
		this.slideInFx.cancel();

		this.slidingOut = false;
		this.slidingIn = true;

		this.slideInFx.start(this.getInsideRightPos());
	},

	slideInWithDelay: function(delay) {
		if ($defined(this.objectName) && this.objectName != null) {
			if (this.slideInTimeoutID != -1) {	
				window.clearTimeout(this.slideInTimeoutID);
				this.slideInTimeoutID = -1;
			}
			this.slideInTimeoutID = window.setTimeout(this.objectName+".slideIn()", delay);
		} else {
			this.slideIn();
		}
	},

	slideOutDone: function() {
		//alert('slideOutDone');
		this.slidingOut = false;
		this.slidingIn = false;
	},

	slideInDone: function() {
		if (this.slidingIn == false) {
			return;
		}

		var rightPos = this.getElement().getStyle('right').toInt();
		if (rightPos != this.getInsideRightPos()) {
			this.getElement().setStyle('right', this.getInsideRightPos()+'px');
		}

		this.slidingOut = false;
		this.slidingIn = false;
	},

	checkForSlideIn: function(mouseX, mouseY) {
		var fullwidthcont = $('fullwidth_container');
		if (fullwidthcont != null) {
			fullwidthcont_coords = fullwidthcont.getCoordinates();
			if (mouseX > fullwidthcont_coords.left + fullwidthcont_coords.width) {
				return true;
			}
		}

		thisCoords = this.getElement().getCoordinates();

		if (mouseX-2 <= thisCoords.left || mouseX+2 >= thisCoords.left + thisCoords.width || mouseY-2 <= thisCoords.top || mouseY+2 >= thisCoords.top + thisCoords.height) {
			return true;
		}
		contentCoords = this.content.getCoordinates();
		languetteCoords = this.languette.getCoordinates();

		if (mouseX-2 <= contentCoords.left && (mouseY+2 >= languetteCoords.top + languetteCoords.height || mouseY-2 <= languetteCoords.top)) {
			return true;
		}

		if (mouseY-2 <= thisCoords.top || mouseY+2 >= thisCoords.top + thisCoords.height || mouseX-2 <= thisCoords.left || mouseX+2 >= thisCoords.left + thisCoords.width) {
			return true;
		}

		return false;
	},

	getOutsideRightPos: function() {
		return 0;
	},

	getInsideRightPos: function() {
		return this.hiddenRightPosition;
	},

	blockOut: function() {
		this.blockedOut = true;
		var rightPos = this.getElement().getStyle('right').toInt();
		if (rightPos != this.getOutsideRightPos()) {
			this.slideOut();
		}
	},

	unBlock: function() {
		this.blockedOut = false;
		this.slideInWithDelay(500);
	},

	setObjectName: function(objName) {
		this.objectName = objName;
	},

	setQuantity: function(quantity) {
		quantity = quantity.toInt();
		if (this.languetteNumProds != null) {
			this.languetteNumProds.innerHTML = quantity;
		}
		if (this.languetteNumProdsS != null) {
			if (quantity > 1) {
				this.languetteNumProdsS.setStyle('display', 'inline');
			} else {
				this.languetteNumProdsS.setStyle('display', 'none');
			}
		}
	},

	setPrice: function(price) {
		price = price.toFloat();
		price = Math.round(price * 100) / 100;
		var intPrice = Math.round(price);

		this.languettePrix.innerHTML = intPrice;
		//this.bottomPriceSpan.innerHTML = formatPrice(price);
	},

	hideContent: function() {
		if (this.ajaxLoader == null) {
			this.ajaxLoader = new Element(document.createElement('img'));
			this.ajaxLoader.src = '/images/panier_ajax_loader.gif';
		}
		var tmp_parent = this.container.getParent();
		var top_pos = Math.floor(tmp_parent.getHeight() / 2) - 20;
		this.ajaxLoader.setStyles({'position': 'absolute', 'top': top_pos+'px', 'left': '110px', 'display': 'inline'});
		this.ajaxLoader.inject(tmp_parent);
		this.container.setStyle('visibility', 'hidden');
	},

	showContent: function() {
		if (this.ajaxLoader != null) {
			this.ajaxLoader.setStyle('display', 'none');
		}
		this.container.setStyle('visibility', 'visible');
	},

	addProduct: function(barcode, taille) {
		this.hideContent();

		var real_taille = "";
		for (var i = 0; i < taille.length; i++) {
			if (taille.charCodeAt(i) == 160) {
				real_taille = real_taille + " ";
			} else {
				real_taille = real_taille + String.fromCharCode(taille.charCodeAt(i));
			}
		}
		taille = real_taille;

		var myAjax = new Request({url: '/ajax_panier_slider', method: 'post', data: {
			codeProd : barcode,
			taille : taille
		}, onComplete: function(result) {
			//alert('complete ! '+result);
			this.container.innerHTML = result;
			this.showContent();
			this.parseContent();
			this.slideInWithDelay(2000);
		}.bind(this) }).send();

		/*var tmp_panier_prod = createPanierProd(uniqueId, barcode, photo, taille, prix);
		this.addPanierProd(tmp_panier_prod);*/
	},

	addProductWithEffect: function(barcode, taille) {
		this.slideOut();
		this.addProduct(barcode, taille);
		this.slideInWithDelay(6000);
	},

	removePanierProd: function(panierProd) {
		if (panierProd == null) {
			return;
		}
		var prodId = panierProd.getProdID();
		var prodTaille = panierProd.getTaille();

		this.hideContent();

		var myAjax = new Request({url: '/ajax_panier_slider', method: 'post', data: {
			type : 'suppr',
			prod: prodId,
			taille: prodTaille
		}, onComplete: function(result) {
			//alert('complete ! '+result);
			this.container.innerHTML = result;
			this.showContent();
			this.parseContent();
		}.bind(this) }).send();
	},

	refreshSize: function() {
		var newHeight = 149 * this.prod_containers_divs.length + this.bottomHeight;
		if (newHeight < this.minHeight) {
			newHeight = this.minHeight;
		}
		this.content.setStyle('height', newHeight+'px');
		
	},

	refreshPriceAndQuantity: function() {
		var totalPrice = 0;
		var totalQuantity = 0;
		this.panier_prods.each(function(panier_prod, i) {
			var prod_prix = panier_prod.getPrix();
			var prod_qte = panier_prod.getQuantity();
			
			totalPrice = totalPrice + prod_prix.toFloat();
			totalQuantity = totalQuantity + prod_qte.toInt();
		});

		this.setPrice(totalPrice);
		this.setQuantity(totalQuantity);
	},

	refreshQuantity: function() {
		var totalQuantity = 0;
		this.panier_prods.each(function(panier_prod, i) {
			var prod_qte = panier_prod.getQuantity();
			
			totalQuantity = totalQuantity + prod_qte.toInt();
		});

		this.setQuantity(totalQuantity);
	},

	refreshPrice: function() {
		var totalPrice = 0;
		this.panier_prods.each(function(panier_prod, i) {
			var prod_prix = panier_prod.getPrix();
			
			totalPrice = totalPrice + prod_prix.toFloat();
		});

		this.setPrice(totalPrice);
	},

	refresh: function() {
		this.refreshSize();
		this.refreshPriceAndQuantity();
	}/*,

	setDroppable: function(obj) {
		this.removeTemporaryAdded();
		if (obj != null) {
			this.droppable = obj;
			this.content.addEvent('drop', function(dropElement, dragFX) {
				this.somethingDropped(dropElement, dragFX);
			}.bind(this));
			this.content.addEvent('over', function(dropElement, dragFX) {
				this.somethingOver(dropElement, dragFX);
			}.bind(this));

			this.content.addEvent('leave', function(dropElement, dragFX) {
				this.somethingLeave(dropElement, dragFX);
			}.bind(this));
		} else {
			this.content.removeEvents('drop');
			this.content.removeEvents('over');
			this.content.removeEvents('leave');
			this.droppable = null;
		}
	},

	getDroppableElement: function() {
		return this.content;
	},

	somethingDropped: function(dropElement, dragFX) {
		this.unBlock();
		if (this.temporaryAdded != null) {
			var res = this.validTemporaryAdded();
			if (res == true) {
				if (this.droppable != null) {
					this.droppable.getElement().remove();
					this.setDroppable(null);
					return;
				}
			}
		}
		if (this.droppable != null) {
			this.droppable.getElement().setStyles({'position': 'relative', 'top': 0, 'left': 0});
			this.addPanierProd(this.droppable);
		}
		this.setDroppable(null);

		dragFX.cancel();
		dragFX.remove();
	},

	somethingOver: function(dropElement, dragFX) {
		//alert(dropElement.title);
		if (this.droppable != null) {
			var clone = this.droppable.getElement().clone();
			clone.setStyles({'position': 'relative', 'top': 0, 'left': 0});
			this.temporaryAddPanierProd(new PanierProd(clone));
		}
	},

	somethingLeave: function(dropElement, dragFX) {
		this.removeTemporaryAdded();
	}*/

});

var PanierProd = new Class({
	initialize: function(el) {
		this.element = el;

		this.parent = this.element.getParent();

		this.panier = null;

		this.cols = el.getChildren();

		this.firstCol = this.cols[0];
		var firstColChildren = this.firstCol.getChildren();

		var firstColLink = firstColChildren[firstColChildren.length - 1];
		var firstColLinkChildren = firstColLink.getChildren();

		this.prodId = null;
		this.taille = null;
		this.couleur = null;

		for (var j = 0; j < firstColLinkChildren.length; j++) {
			var tmpElem = firstColLinkChildren[j];
			if (tmpElem.className == 'panier_codeProduit') {
				this.prodId = tmpElem.innerHTML;
			}
			if (tmpElem.className == 'panier_couleurProduit') {
				this.couleur = tmpElem.innerHTML;
			}
			if (tmpElem.className == 'panier_tailleProduit') {
				this.taille = tmpElem.innerHTML;
			}
		}

		this.secondCol = this.cols[1];
		this.qte = this.secondCol.getChildren()[0].innerHTML;

		this.thirdCol = this.cols[2];
		this.prix = this.thirdCol.getChildren()[0].innerHTML.replace(',', '.');

		this.forthCol = this.cols[3];
		this.imgSuppr = this.forthCol.getChildren()[0];

		this.imgSuppr.addEvent('click', function(event) {
			var panier = this.getPanier();
			if (panier != null) {
				panier.removePanierProd(this);
			}
		}.bind(this));

/*		this.prodId = this.element.title;

		var children = this.element.getChildren();
		this.title_div = children[0];
		this.title_cell = this.title_div.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0];

		this.img_prod = children[1];
		this.bottom = children[2];

		var bottom_children = this.bottom.getChildren();
		this.tailleSpan = bottom_children[1];
		this.prixSpan = bottom_children[4].getChildren()[0];

		this.closeButton = children[3];

		this.closeButton.addEvent('click', function(event) {
			if (this.getPanier() != null) {
				var panier = this.getPanier();
				if (panier != null) {
					panier.removePanierProd(this);
				}
			}
		}.bind(this));*/
	},

	getElement: function() {
		return this.element;
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	},

	getProdID: function() {
		return this.prodId;
	},

	getTaille: function() {
		return this.taille;
	},

	getCouleur: function() {
		return this.couleur;
	},

	getQuantity: function() {
		return this.qte;
	},

	getPrix: function() {
		return this.prix;
	}/*,

	getPosition: function() {
		var nb_before = -1;
		var parcours_prod = this.getElement().getParent();
		if (parcours_prod.className != 'panier_prod_container') {
			return 1;
		}
		while (parcours_prod != undefined) {
			parcours_prod = parcours_prod.getPrevious();
			nb_before++;
		}

		return nb_before + 1;
	}*/
});



var FicheProdDatas = new Class({
	initialize: function(el) {
		this.element = el;

		this.selectedTaille = null;
		this.panier = null;

		this.img_selected = 0;
		this.qte_select = 1;
		this.availableQuantity = 0;

		this.alert_window = null;

		var mainChildren = el.getChildren();

		this.real_content_div = mainChildren[0];

		this.list_tailles = $('list_tailles');
		this.tailles = [];
		this.list_tailles.getChildren().each(function(elem, i) {
			this.tailles[this.tailles.length] = new FicheProdTaille(elem, this);
		}.bind(this));

		var barCodeSpan = $('prod_barcode');
		this.barcode = barCodeSpan.innerHTML;
		
		this.bouton_acheter = $('btn_acheter');

		if (this.bouton_acheter.hasClass('btn_acheter_inact')) {
			this.bouton_acheter.addEvent('click', function(event) {
				event = new Event(event);
				this.alertTaille(null);
				event.stop();
				return false;
			}.bind(this));
		} else {
			this.bouton_acheter.addEvent('click', function(event) {
				event = new Event(event);
				this.buttonAddPressed();
				event.stop();
				return false;
			}.bind(this));
		}

		this.bouton_alerte_taille = $('alert_taille');
		if (!this.bouton_alerte_taille.hasClass('alert_taille_inact')) {
			this.bouton_alerte_taille.addEvent('click', function(event) {
				event = new Event(event);
				this.alertTaille(null);
				event.stop();
				return false;
			}.bind(this));
		}


		/*alert(this.real_content_div.innerHTML);
		var real_content_children = this.real_content_div.getChildren();
		this.fiche_prod_left = real_content_children[0];
		var fiche_prod_left_children = this.fiche_prod_left.getChildren();
		this.photo_div = fiche_prod_left_children[0];

		var list_photos = this.photo_div.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren();

		this.miniatures_div = fiche_prod_left_children[1].getChildren()[1];
		this.miniatures_list = this.miniatures_div.getChildren();

		this.photos = [];
		for (var count = 0; count < list_photos.length; count++) {
			this.photos[this.photos.length] = list_photos[count];
		}

		this.photo_file = '';
		if (this.photos.length > 0 && this.photos[0] != null) {
			var tmp_src = this.photos[0].src;
			if (tmp_src != null && tmp_src.length > 0) {
				var splitted = tmp_src.split('/');
				if (splitted != null && splitted.length > 0) {
					this.photo_file = splitted[splitted.length - 1];
				}
			}
		}

		this.miniatures_list.addEvent('mouseleave', function(event) {
			this.showPhoto(this.img_selected);
		}.bind(this));

		this.miniatures_list.each(function(min, i) {
			var num = i;
			min.addEvent('mouseenter', function(event) {
				this.showPhoto(num);
			}.bind(this));
			min.addEvent('mouseleave', function(event) {
				//alert('leave '+num);
			}.bind(this));
			min.addEvent('click', function(event) {
				this.setPhotoSelected(i);
			}.bind(this));
		}.bind(this));

		this.infos_div = real_content_children[1];

		var infos_div_children = this.infos_div.getChildren();
		this.titre_div = infos_div_children[0].getChildren()[0];
		var titre_span_children = this.titre_div.getChildren()[0].getChildren();

		this.barcode = titre_span_children[0].innerHTML;
		this.designation = titre_span_children[1].innerHTML;
		this.couleur = titre_span_children[2].innerHTML;

		this.prixdiv = titre_span_children[4];
		this.prix = this.prixdiv.getChildren()[0].innerHTML.toFloat();

		this.infos_content_div = infos_div_children[1];

		var infos_content_div_children = this.infos_content_div.getChildren();
		this.maindesc = infos_content_div_children[0];

		this.list_tailles_span = infos_content_div_children[3];
		this.tailles = [];
		this.list_tailles_span.getChildren().each(function(span, i) {
			this.tailles[this.tailles.length] = new FicheProdTaille(span, this);
		}.bind(this));

		this.qte_select = infos_content_div_children[7];

		this.bottom_div = infos_div_children[2];
		this.bottom_div_img = this.bottom_div.getChildren()[0];

		if (this.bottom_div_img.className != 'inact') {
			this.bottom_div_img.addEvent('click', function(event) {
				event = new Event(event);
				this.buttonAddPressed();
				event.stop();
				return false;
			}.bind(this));
		}

		if (infos_div_children.length > 3) {
			var infos_assoc = infos_div_children[3];
			this.assoc_div = infos_assoc.getChildren()[1];
			this.assoc_spans = this.assoc_div.getChildren();

			this.assoc_div.addEvent('mouseleave', function(event) {
				this.showPhoto(this.img_selected);
			}.bind(this));

			this.assoc_spans.addEvent('mouseleave', function(event) {
				this.showPhoto(this.img_selected);
			}.bind(this));

			this.assoc_spans.each(function(min, i) {
				var num = this.miniatures_list.length + i;
				min.addEvent('mouseenter', function(event) {
					this.showPhoto(num);
				}.bind(this));
				min.addEvent('mouseleave', function(event) {
					//alert('leave '+num);
				}.bind(this));
			}.bind(this));
		}*/
	},

	getElement: function() {
		return this.element;
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	},

	getProdBarCode: function() {
		return this.barcode;
	},

	getProdDesignation: function() {
		return this.designation;
	},

	getProdCouleur: function() {
		return this.couleur;
	},

	getPrix: function() {
		return this.prix;
	},

	getPhotoFile: function() {
		return this.photo_file;
	},

	getQuantity: function() {
		//return this.qte_select.value;
		return this.qte_select;
	},

	setPhotoSelected: function(num) {
		this.img_selected = num;
		this.miniatures_list.each(function(min, i) {
			if (i == num) {
				min.addClass('selected');
			} else {
				min.removeClass('selected');
			}
		}.bind(this));
	},

	showPhoto: function(num) {
		if (num > this.photos.length + 1) {
			num = 0;
		}
		for (var i = 0; i < this.photos.length; i++) {
			if (i != num) {
				this.photos[i].setStyle('display', 'none');
			}
		}
		this.photos[num].setStyle('display', 'block');
	},

	setSelected: function(prodTaille) {
		if (prodTaille == null) {
			return;
		}
		if (this.tailles == null) {
			return;
		}
		if (prodTaille == this.selectedTaille) {
			return;
		}
		this.tailles.each(function(ptaille, i) {
			if (ptaille != prodTaille) {
				ptaille.setSelected(false);
			}
		}.bind(this));
		prodTaille.setSelected(true);
		this.selectedTaille = prodTaille;

		this.setAvailableQuantity(prodTaille.getQuantity());
	},

	setAvailableQuantity: function(num) {
		this.availableQuantity = num;
	},

	buttonAddPressed: function() {
		if (this.selectedTaille == null) {
			alert('Veuillez sélectionner une taille');
			return;
		}
		this.addToBasket(this.selectedTaille.getTaille(), this.getQuantity());
	},

	addToBasket: function(taille, qte) {
		if (this.getPanier() == null) {
			return;
		}
		this.getPanier().addProductWithEffect(this.getProdBarCode(), taille);
		//addToBasket(this.getProdBarCode(), taille, qte);
	},

	getAllTaillesOutOfStock: function() {
		var res = [];
		for (var i = 0; i < this.tailles.length; i++) {
			var curTaille = this.tailles[i];
			if (curTaille.getQuantity() <= 0) {
				res[res.length] = curTaille;
			}
		}

		return res;
	},

	alertTaille: function(taille) {
		if (this.alert_window == null || this.alert_window.closed == true) {
			this.alert_window = window.open("","AlerteTaille","menubar=no,status=no,scrollbars=no,width=250,height=300");
		}

		var listTailles = this.getAllTaillesOutOfStock();
		var selectOptions = "";
		for (var i = 0; i < listTailles.length; i++) {
			var tmpTaille = listTailles[i];
			selectOptions = selectOptions + '<option value="'+tmpTaille.getTaille()+'"';
			if ((taille != null && taille == tmpTaille.getTaille()) || listTailles.length == 1) {
				selectOptions = selectOptions + ' selected="selected"';
			}
			selectOptions = selectOptions + '>'+tmpTaille.getTaille()+'</option>';
		}

		var inner = '<div style="text-align: center; font-family: sans-serif, Arial, Helvetica;"><form id="alert_taille_form" action=""><img src="http://www.mdstore.fr/images/charte/MDStoreLogo.gif" alt="MDStore" /><br/><p>Me pr&eacute;venir quand la taille suivante sera disponible :</p><select id="alert_taille_select"><option value="">S&eacute;lectionner une taille</option>'+selectOptions+'</select><br/><br/><span style="font-size: 12px;">Email: <input type="text" name="alert_taille_email" id="alert_taille_email" value="" style="width: 150px; font-size: 11px" /></span><br/><br/><img src="http://www.mdstore.fr/images/alerte_taille.gif" style="cursor: pointer" id="alert_taille_button" /></form></div>';

		this.alert_window.document.body.innerHTML = inner;

		var formular = this.alert_window.document.getElementById('alert_taille_form');

		if (formular != null) {
			formular.onsubmit = function(event) {
				if (event != null) {
					event = new Event(event);
				}
				this.alertTailleValidClicked();
				if (event != null) {
					event.stop();
				}
				return false;
			}.bind(this);
		}

		var button = this.alert_window.document.getElementById('alert_taille_button');
		button = new Element(button);

		button.addEvent('click', function(event) {
			this.alertTailleValidClicked();
		}.bind(this));

		this.alert_window.focus();
	},

	alertTailleValidClicked: function() {
		if (this.alert_window == null || this.alert_window.closed == true) {
			return;
		}

		var tailleSelect = this.alert_window.document.getElementById('alert_taille_select');
		var emailAdress = this.alert_window.document.getElementById('alert_taille_email');

		tailleSelect = new Element(tailleSelect);
		emailAdress = new Element(emailAdress);

		if (tailleSelect == null || emailAdress == null) {
			return;
		}

		var tailleVal = tailleSelect.value;
		var emailVal = emailAdress.value;

		var hasError = false;

		if (tailleVal == "") {
			tailleSelect.setStyles({'background-color': 'red', 'color': 'white'});
			hasError = true;
		} else {
			tailleSelect.setStyles({'background-color': 'white', 'color': 'black'});
		}

		if (valid_email(emailVal) == false) {
			emailAdress.setStyles({'background-color': 'red', 'color': 'white'});
			hasError = true;
		} else {
			emailAdress.setStyles({'background-color': 'white', 'color': 'black'});
		}

		if (hasError == true) {
			return;
		}

		var myAjax = new Request({url: '/ajax_alert_taille', method: 'post', data: {
			codeProd : this.getProdBarCode(),
			taille : tailleVal,
			email : emailVal
		}, onComplete: function(result) {
			var inner = '<div style="text-align: center; font-family: sans-serif, Arial, Helvetica;"><form id="alert_taille_form" action=""><img src="http://www.mdstore.fr/images/charte/MDStoreLogo.gif" alt="MDStore" /><br/><p>Votre requ&ecirc;te &agrave; &eacute;t&eacute; prise en compte.</form></div>';

			if (this.alert_window != null && this.alert_window.closed == false) {
				this.alert_window.document.body.innerHTML = inner;
			}
		}.bind(this) }).send();
	}
});


var FicheProdTaille = new Class({
	initialize: function(el, father) {
		this.element = el;

		this.fiche_prod_datas = father;

		var elChildren = el.getChildren();
		this.taille = elChildren[0].getChildren()[0].innerHTML;
		this.quantity = elChildren[1].innerHTML.toFloat();

		if (this.quantity > 0) {
			el.addEvent('click', function(event) {
				event = new Event(event);
				this.fiche_prod_datas.setSelected(this);
				event.stop();
				return false;
			}.bind(this));
		} else {
			el.addEvent('click', function(event) {
				event = new Event(event);
				this.fiche_prod_datas.alertTaille(this.taille);
				event.stop();
				return false;
			}.bind(this));
		}
	},

	getElement: function() {
		return this.element;
	},

	getTaille: function() {
		return this.taille;
	},

	getQuantity: function() {
		return this.quantity;
	},

	setSelected: function(is_selected) {
		if (is_selected == true) {
			this.getElement().addClass('selected');
		} else {
			this.getElement().removeClass('selected');
		}
	}
});


function valid_email(email) {
	if (!email.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
		return false;
	}

	return true;
}

var AccueilNews = new Class({
	initialize: function(el) {
		this.element = el;

		var elChildren = el.getChildren();

		this.buttonLeft = elChildren[0];
		this.contentMainDiv = elChildren[1];
		this.buttonRight = elChildren[2];

		var tableContent = this.contentMainDiv.getChildren()[0];
		this.contentVisible = tableContent.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0];

		this.contentFullWidth = this.contentVisible.getChildren()[0];
		this.currentPos = 0;
		this.goingToPos = -1;

		this.fxNews = new Fx.Tween(this.contentFullWidth, {property: 'left', duration:800, onComplete: function() {
				this.currentPos = this.goingToPos;
				this.goingToPos = -1;
			}.bind(this)});

		this.buttonLeft.addEvent('click', function(event) {
			this.goToLeft();
		}.bind(this));

		this.buttonRight.addEvent('click', function(event) {
			this.goToRight();
		}.bind(this));

		/*var elChildren = el.getChildren();
		this.taille = elChildren[0].innerHTML;
		this.quantity = elChildren[1].innerHTML.toFloat();

		if (this.quantity > 0) {
			el.addEvent('click', function(event) {
				event = new Event(event);
				this.fiche_prod_datas.setSelected(this);
				event.stop();
				return false;
			}.bind(this));
		} else {
			el.addEvent('click', function(event) {
				event = new Event(event);
				this.fiche_prod_datas.alertTaille(this.taille);
				event.stop();
				return false;
			}.bind(this));
		}*/
	},

	getElement: function() {
		return this.element;
	},

	goToLeft: function() {
		if (this.goingToPos != -1) {
			if (this.goingToPos <= 0) {
				return;
			}
			this.goToPosition(this.goingToPos - 1);
			return;
		} else {
			if (this.currentPos <= 0) {
				return;
			}
			this.goToPosition(this.currentPos - 1);
			return;
		}
	},

	goToRight: function() {
		if (this.goingToPos != -1) {
			if (this.goingToPos >= 7) {
				return;
			}
			this.goToPosition(this.goingToPos + 1);
			return;
		} else {
			if (this.currentPos >= 7) {
				return;
			}
			this.goToPosition(this.currentPos + 1);
			return;
		}
	},

	goToPosition: function(pos) {
		if (pos == this.goingToPos) {
			return;
		}

		if (this.goingToPos == -1 && pos == this.currentPos) {
			return;
		}

		this.fxNews.cancel();

		var newPos = this.getPixelsForPos(pos);

		if (newPos == this.contentFullWidth.getStyle('left').toInt()) {
			return;
		}

		this.fxNews.start(newPos);
		this.goingToPos = pos;
	},

	getPixelsForPos: function(pos) {
		var thisWidth = this.contentVisible.getWidth();
		return - pos * thisWidth;
	}
});

var AccueilTop = new Class({
	initialize: function(el) {
		this.element = el;

		var elChildren = el.getChildren();

		this.head = elChildren[0];
		this.tabs = elChildren[1];

		var tabChildren = this.tabs.getChildren();

		this.tabSearch = tabChildren[0];
		this.tabHomme = tabChildren[1];
		this.tabFemme = tabChildren[2];

		this.contentSearch = elChildren[2];
		this.contentHomme = elChildren[3];
		this.contentFemme = elChildren[4];

		this.tabSearch.addEvent('click', function(event) {
			this.setTabSearch();
		}.bind(this));
		this.tabHomme.addEvent('click', function(event) {
			this.setTabHomme();
		}.bind(this));
		this.tabFemme.addEvent('click', function(event) {
			this.setTabFemme();
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	setTabSearch: function() {
		this.tabSearch.addClass("selected");
		this.tabHomme.removeClass("selected");
		this.tabFemme.removeClass("selected");

		this.contentSearch.setStyle('display', 'block');
		this.contentHomme.setStyle('display', 'none');
		this.contentFemme.setStyle('display', 'none');
	},

	setTabHomme: function() {
		this.tabSearch.removeClass("selected");
		this.tabHomme.addClass("selected");
		this.tabFemme.removeClass("selected");

		this.contentSearch.setStyle('display', 'none');
		this.contentHomme.setStyle('display', 'block');
		this.contentFemme.setStyle('display', 'none');
	},

	setTabFemme: function() {
		this.tabSearch.removeClass("selected");
		this.tabHomme.removeClass("selected");
		this.tabFemme.addClass("selected");

		this.contentSearch.setStyle('display', 'none');
		this.contentHomme.setStyle('display', 'none');
		this.contentFemme.setStyle('display', 'block');
	}
});

var CatalogueElement = new Class({
	initialize: function(el) {
		this.element = el;

		this.initialisation = true;

		this.kwickEffectEnabled = true;
		this.panier = null;

		this.lastNumProdsSent = -1;
		this.fixedWidth = -1;
		this.arrayAccordeons = [];

		this.kwickWidth = 105;
		this.bigKwickWidth = 210;

		var elChildren = el.getChildren();

		this.nblines = elChildren[0].innerHTML;
		this.base_url = elChildren[1].innerHTML;
		this.base_url_args = elChildren[2].innerHTML;
		this.ulElem = elChildren[3];

		var ulChildren = this.ulElem.getChildren();
		this.prods = [];
		for (var i = 0; i < ulChildren.length; i++) {
			var tmpLI = ulChildren[i];
			this.prods[this.prods.length] = new CatalogueProd(tmpLI, this);
		}

		this.lastNumElems = this.getNumElemsFromWidth();

		this.refreshElemsDispo();
		/*if (browserIE6() == false) {
			this.setFixedWidth();
		}*/
		this.setFixedWidth();

		this.buildAccordeons();

		window.addEvent('windowResized', this.onWindowChanged.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	},

	getNbLines: function() {
		return this.nblines;
	},

	initialisationEnCours: function() {
		return this.initialisation;
	},

	refreshElemsDispo: function() {
		this.ajaxSetNumProdsPerLine();
	},

	getNumElemsFromWidth: function() {
		return Math.floor(this.getElement().getWidth() / 105);
	},

	forceResizeFixedWidth: function() {
		if (this.fixedWidth == -1) {
			return;
		}
		var lastFixedWidth = this.fixedWidth;

		this.removeFixedWidth();
		this.setFixedWidth();

		var newFixedWidth = this.fixedWidth;
	},

	getBestFixedWidthInPercent: function() {
		var bestWidth = this.getBestFixedWidth();
		return bestWidth * 100 / this.getElement().getWidth();
	},

	getBestFixedWidth: function() {
		if (this.fixedWidth != -1) {
			return this.fixedWidth;
		}

		var bestWidth = Math.round(this.getNumElemsFromWidth() * this.kwickWidth) + 15;
		return bestWidth;
	},

	ajaxSetNumProdsPerLine: function() {
		var numProds = this.getNumElemsFromWidth();
		if (numProds == this.lastNumProdsSent) {
			return;
		}

		var myAjax = new Request({url: '/ajax_catalogue_set_num_prods', method: 'post', data: {
			qte : numProds
		}, onComplete: function(result) {
			this.lastNumProdsSent = numProds;
			//alert(result);
		}.bind(this) }).send();
	},

	setFixedWidth: function() {
		var tmpFixedWidth = this.getBestFixedWidthInPercent();
		this.fixedWidth = tmpFixedWidth;
		this.getElement().setStyle('width', tmpFixedWidth+'%');
	},

	removeFixedWidth: function() {
		this.getElement().setStyle('width', '99.5%');
		this.fixedWidth = -1;
	},

	onWindowChanged: function(event) {
		if (this.fixedWidth != -1) {
			this.forceResizeFixedWidth();
		}

		var newNumElems = this.getNumElemsFromWidth();

		if (this.lastNumElems != newNumElems) {
			// let's deal with the elements.
			this.refreshElemsDispo();
			this.buildAccordeons();
		}

		this.lastNumElems = newNumElems;
	},

	checkNbProds: function() {
		if (this.prods.length == 0) {
			return;
		}
		var nbprods = this.prods.length;
		var firstIsBig = false;
		if (nbprods > 0) {
			// Let's check if the first one is a big one.
			var firstProd = this.prods[0];
			if (firstProd.isFirstBig() == true) {
				firstIsBig = true;
			}
		}

		var requiredNbProds = this.getNbLines() * this.getNumElemsFromWidth();
		if (firstIsBig == true) {
			requiredNbProds = requiredNbProds - 3;
		}

		for (var i = 0; i < this.prods.length; i++) {
			var prod = this.prods[i];
			if (i < requiredNbProds) {
				prod.show();
			} else {
				prod.hide();
			}
		}

		if (requiredNbProds > this.prods.length) {
			// let's check if we have the last one :
			if (this.prods[this.prods.length - 1].isLastProd() == true) {
				return;
			}
			var nbMissing = requiredNbProds - this.prods.length;
			this.ajaxAddProds(nbMissing);
		}
	},

	ajaxAddProds: function(quantity) {
		if (this.prods.length == 0) {
			return;
		}
		var lastProd = this.prods[this.prods.length - 1];

		var lastBarcode = lastProd.getBarCode();

		var myAjax = new Request({url: '/ajax_catalogue_complete_prods', method: 'post', data: {
			qte : quantity,
			last : lastBarcode
		}, onComplete: function(result) {
			var splitted = result.split('/-/-/');
			if (splitted.length > 1 && splitted[0] == 'OK') {
				for (var i = 1; i < splitted.length; i++) {
					this.addProdHTML(splitted[i]);
				}
				this.buildAccordeons();
			}
		}.bind(this) }).send();
	},

	addProdHTML: function(html) {
		var tmpContainer = new Element(document.createElement('div'));
		tmpContainer.innerHTML = html;
		var newLI = tmpContainer.getChildren()[0];
		var newLIlink = newLI.getChildren()[0];

		var tmp_splitted = newLIlink.href.split('/');
		var basename = tmp_splitted[tmp_splitted.length - 1];

		newLIlink.href = this.base_url+basename+this.base_url_args;

		newLI.inject(this.ulElem);
		this.prods[this.prods.length] = new CatalogueProd(newLI, this);
	},

	buildAccordeons: function() {
		this.initialisation = true;
		this.checkNbProds();

		for (var i = 0; i < this.arrayAccordeons.length; i++) {
			this.arrayAccordeons[i].stopAll();
		}

		for (var i = 0; i < this.prods.length; i++) {
			var prod = this.prods[i];
			if (prod.isFirstBig()) {
				continue;
			}
			prod.getElement().setStyle('width', '105px');
		}

		var tmpArrayAccordeons = [];
		var tmpProds = [];
		var lastTop = -1;
		for (var i = 0; i < this.prods.length; i++) {
			var prod = this.prods[i];
			if (prod.isFirstBig()) {
				continue;
			}
			if (prod.isHidden() == true) {
				continue;
			}
			var thisTop = prod.getCoordinates().top;
			counterWhile = 0;
			while (thisTop < 0) {
				thisTop = prod.getCoordinates().top;
				if (counterWhile > 20) {
					break;
				}
				counterWhile++;
			}
			if (lastTop != -1 && lastTop != thisTop) {
				tmpArrayAccordeons[tmpArrayAccordeons.length] = new CatalogueAccordeon(tmpProds, this);
				tmpProds = [];
			}
			lastTop = thisTop;

			tmpProds[tmpProds.length] = prod;
		}
		if (tmpProds.length > 0) {
			tmpArrayAccordeons[tmpArrayAccordeons.length] = new CatalogueAccordeon(tmpProds, this);
		}

		this.arrayAccordeons = tmpArrayAccordeons;

		this.initialisation = false;
	},

	mouseEnteredAccordeon: function(accordeon, prod, event) {
		if (this.kwickEffectEnabled == false) {
			return;
		}
		for (var i = 0; i < this.arrayAccordeons.length; i++) {
			var tmpAccordeon = this.arrayAccordeons[i];
			if (tmpAccordeon != accordeon) {
				tmpAccordeon.close();
			} else {
				tmpAccordeon.open(prod);
			}
		}
	},

	mouseLeftAccordeon: function(prod, event) {
		if (this.kwickEffectEnabled == false) {
			return;
		}
		event = new Event(event);
		var x = event.client.x;
		var y = event.client.y;

		for (var i = 0; i < this.arrayAccordeons.length; i++) {
			var tmpAccordeon = this.arrayAccordeons[i];
			if (!tmpAccordeon.isPosInside(x, y)) {
				tmpAccordeon.close();
			}
		}
	},

	disableAccordeons: function() {
		this.kwickEffectEnabled = false;
	},

	enableAccordeons: function() {
		this.kwickEffectEnabled = true;
	}
});

var CatalogueAccordeon = new Class({
	initialize: function(arrayProds, catalogueElem) {

		this.prods = arrayProds;
		this.catalogueElement = catalogueElem;

		this.prodsElems = [];

		for (var i = 0; i < this.prods.length; i++) {
			var tmpProd = this.prods[i];
			tmpProd.setAccordeon(this);

			this.prodsElems[this.prodsElems.length] = tmpProd.getElement();

			tmpProd.getElement().setStyle('width', '105px');
		}

		this.currentState = 'closed';
		this.currentProd = null;

		this.fx = new Fx.Elements(this.prodsElems, {wait: false, duration: 200, transition: Fx.Transitions.quadOut, onComplete: function(result) {
				this.transitionFinished();
			}.bind(this)});
	},

	getElement: function() {
		return this.element;
	},

	getCatalogueElement: function() {
		return this.catalogueElement;
	},

	mouseEnteredProd: function(prod, event) {
		event = new Event(event);
		this.getCatalogueElement().mouseEnteredAccordeon(this, prod, event);
		//this.open(prod);
	},

	mouseLeftProd: function(prod, event) {
		event = new Event(event);
		this.getCatalogueElement().mouseLeftAccordeon(this, event);
	},

	getCoordinates: function() {
		var top = 0;
		var left = 0;
		var bottom = 0;
		var right = 0;
		if (this.prods.length > 0) {
			var coords = this.prods[0].getCoordinates();
			top = coords.top;
			left = coords.left;

			coords = this.prods[this.prods.length - 1].getCoordinates();
			bottom = coords.bottom;
			right = coords.right;
		}

		return {'top': top, 'left': left, 'bottom': bottom, 'right': right, 'width': (right - left + 1), 'height': (bottom - top + 1)};
	},

	isPosInside: function(x, y) {
		thisCoords = this.getCoordinates();
		if (x <= thisCoords.left || x >= thisCoords.right || y <= thisCoords.top || y >= thisCoords.bottom) {
			return false;
		}
		return true;
	},

	getSmallSize: function() {
		var nbProds = this.prods.length - 1;
		var sizeEach = 80 / nbProds;
		sizeEach = Math.ceil(sizeEach);
		return (105 - sizeEach);
		//return Math.floor(105 - (80 / (this.prods.length - 1)));
	},

	getSmallSizesArray: function() {
		var nbProds = this.prods.length - 1;
		var sizeEach = 80 / nbProds;
		sizeEach = Math.ceil(sizeEach);
		var smallSize = 105 - sizeEach;

		var difference = (sizeEach * nbProds) - 80;

		var res = [];

		var i = 0;
		for (; i < difference; i++) {
			res[res.length] = smallSize + 1;
		}
		for (; i < nbProds; i++) {
			res[res.length] = smallSize;
		}
		return res;
	},

	open: function(prod) {
		if (this.getCatalogueElement() != null && this.getCatalogueElement().initialisationEnCours() == true) {
			return;
		}
		if ((this.currentState == 'opening' || this.currentState == 'opened') && this.currentProd == prod) {
			return;
		}
		this.currentProd = prod;
		this.currentState = 'opening';
		this.fx.cancel();

		var obj = {};

		//var smallSize = this.getSmallSize();
		var smallSizesArray = this.getSmallSizesArray();
		var smallSizesCounter = 0;

		for (var i = 0; i < this.prods.length; i++) {
			var tmpProd = this.prods[i];
			if (tmpProd == prod) {
				obj[i] = {
					'width': 185
				};
			} else {
				obj[i] = {
					//'width': [smallSize]
					'width': smallSizesArray[smallSizesCounter]
				};
				smallSizesCounter++;
			}
		}
		this.fx.start(obj);
	},

	close: function() {
		if (this.getCatalogueElement() != null && this.getCatalogueElement().initialisationEnCours() == true) {
			return;
		}
		if (this.currentState == 'closing' || this.currentState == 'closed') {
			return;
		}
		this.currentState = 'closing';
		this.currentProd = null;
		this.fx.cancel();

		var obj = {};

		for (var i = 0; i < this.prods.length; i++) {
			obj[i] = {
				'width': [105]
			};
		}
		this.fx.start(obj);
	},

	stopAll: function() {
		this.fx.cancel();
		for (var i = 0; i < this.prods.length; i++) {
			this.prods[i].getElement().setStyle('width', '105px');
		}
	},

	transitionFinished: function() {
		if (this.currentState == 'closing') {
			this.currentState = 'closed';
		} else if (this.currentState == 'opening') {
			this.currentState = 'opened';
		}

	}
});

var CatalogueProd = new Class({
	initialize: function(el, catalogueElem) {
		this.element = el;

		this.hidden = false;

		this.catalogueElement = catalogueElem;

		this.link = el.getChildren()[0];
		var linkChildren = this.link.getChildren();
		
		var elems = linkChildren[0].getChildren();

		var picsAndBarcode = elems[0];
		this.taillesSpan = elems[1];

		this.firstBig = false;
		if (el.hasClass('big_li') == true) {
			this.firstBig = true;
			this.big_state = 'closed';
			this.fxBigTaille = new Fx.Tween(this.taillesSpan, {property:'top', duration: 200, onComplete: function() {
					this.bigFXfinished();
				}.bind(this)
			});
		}
		this.isLast = false;
		if (el.hasClass('last_prod') == true) {
			this.isLast = true;
		}


		var picsAndBarcodeChildren = picsAndBarcode.getChildren();
		if (picsAndBarcodeChildren.length == 3) {
			this.picture = picsAndBarcodeChildren[1];
			this.barcode = picsAndBarcodeChildren[2].innerHTML.trim();
		} else {
			this.picture = picsAndBarcodeChildren[0];
			this.barcode = picsAndBarcodeChildren[1].innerHTML.trim();
		}

		this.prix = linkChildren[1].innerHTML.toFloat();

		var taillesSpanChildren = this.taillesSpan.getChildren();
		this.taillesTitleSpan = taillesSpanChildren[0];

		var classNameForTailles = "taille_span";
		if (this.firstBig) {
			classNameForTailles = "big_taille_span";
		}
		this.tailles = [];
		for (var i = 1;  i < taillesSpanChildren.length; i++) {
			var tmpElem = taillesSpanChildren[i];
			if (tmpElem.hasClass(classNameForTailles)) {
				this.tailles[this.tailles.length] = new TailleProdElem(tmpElem, this);
			}
		}

		var counter = 0;
		if (elems[0].className == 'picto') {
			counter = 1;
		}
		//alert(elems[1].className);

		this.accordeon = null;

		this.element.addEvent('mousemove', function(event) {
			this.mouseEntered(event);
		}.bind(this));

		this.element.addEvent('mouseleave', function(event) {
			this.mouseLeave(event);
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	getCatalogueElement: function() {
		return this.catalogueElement;
	},

	isLastProd: function() {
		return this.isLast;
	},

	isHidden: function() {
		return this.hidden;
	},

	hide: function() {
		this.hidden = true;
		this.getElement().setStyle('display', 'none');
	},

	show: function() {
		this.hidden = false;
		this.getElement().setStyle('display', 'block');
	},

	getBarCode: function() {
		return this.barcode;
	},

	getPicture: function() {
		return this.picture;
	},

	getCoordinates: function() {
		return this.getElement().getCoordinates();
	},

	isFirstBig: function() {
		if ($defined(this.firstBig)) {
			return this.firstBig;
		}
		return false;
	},

	setAccordeon: function(accord) {
		this.accordeon = accord;
	},

	getAccordeon: function() {
		return this.accordeon;
	},

	removeAccordeon: function() {
		this.accordeon = null;
	},

	mouseEntered: function(event) {
		if (this.isFirstBig() == true) {
			this.bigElemShowTailles();
			return;
		}
		var acc = this.getAccordeon();
		if (acc != null) {
			acc.mouseEnteredProd(this, event);
		}
	},

	mouseLeave: function(event) {
		if (this.isFirstBig() == true) {
			this.bigElemHideTailles();
			return;
		}
		var acc = this.getAccordeon();
		if (acc != null) {
			acc.mouseLeftProd(this, event);
		}
	},

	tailleDisplaysMessage: function(tailleElem, event) {
		for (var i = 0; i < this.tailles.length; i++) {
			var tmpTaille = this.tailles[i];
			if (tmpTaille != tailleElem) {
				tmpTaille.realHideDragDropMessage();
			}
		}
		tailleElem.displayDragDropMessage(event);
	},

	tailleStartDrag: function(tailleElem, event) {
		this.getCatalogueElement().disableAccordeons();
		var panier = this.getCatalogueElement().getPanier();
		if (panier != null) {
			panier.blockOut();
		}
		for (var i = 0; i < this.tailles.length; i++) {
			var tmpTaille = this.tailles[i];
			tmpTaille.realHideDragDropMessage();
		}
	},

	tailleStopDrag: function(tailleElem) {
		this.getCatalogueElement().enableAccordeons();
		var panier = this.getCatalogueElement().getPanier();
		if (panier != null) {
			panier.unBlock();
		}
	},

	bigElemShowTailles: function() {
		if (this.big_state == 'opening' || this.big_state == 'opened') {
			return;
		}
		this.big_state = 'opening';
		this.fxBigTaille.cancel();
		this.fxBigTaille.start(303);
	},

	bigElemHideTailles: function() {
		if (this.big_state == 'closing' || this.big_state == 'closed') {
			return;
		}
		this.big_state = 'closing';
		this.fxBigTaille.cancel();
		this.fxBigTaille.start(363);
	},

	bigFXfinished: function() {
		if (this.big_state == 'opening') {
			this.big_state = 'opened';
		}
		if (this.big_state == 'closing') {
			this.big_state = 'closed';
		}
	}
});

var TailleProdElem = new Class({
	initialize: function(el, catProd) {
		this.element = el;
		this.catalogueProd = catProd;

		this.taille = el.innerHTML.trim().replace('&nbsp;', ' ');

		this.drag = null;

		if (this.element.hasClass('full')) {
			this.full = true;
		} else {
			this.full = false;
		}

		if (this.element.hasClass('last')) {
			this.last = true;
		} else {
			this.last = false;
		}

		if (this.element.hasClass('finished')) {
			this.finished = true;
		} else {
			this.finished = false;
		}

		this.dragDropMessage = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);


		if (this.full == true) {
			this.dragDropMessage.innerHTML = 'Glisser la taille<br/>choisie jusqu\'au<br/>panier';
		}
		if (this.last == true) {
			this.dragDropMessage.innerHTML = '<font color="orange"><u>Derni&egrave;re pi&egrave;ce<br/>en stock !!!</u></font><br/>Glisser jusqu\'au<br/>panier';
		}
		if (this.finished == true) {
			this.dragDropMessage.innerHTML = '<font color="red">Cette taille n\'est<br/>plus disponible.</font>';
		}

		this.fxDragMessage = null;
		this.fxHideMessage = null;

		this.element.addEvent('mouseenter', function(event) {
			this.mouseEntered(event);
		}.bind(this));

		this.element.addEvent('mouseout', function(event) {
			this.hideDragDropMessage(event);
		}.bind(this));

		if (this.finished == false) {
			this.element.addEvent('mousedown', function(event) {
				this.mouseDown(event);
			}.bind(this));
		}
	},

	getElement: function() {
		return this.element;
	},

	getCatalogueProd: function() {
		return this.catalogueProd;
	},

	getTaille: function() {
		return this.taille;
	},

	mouseEntered: function(event) {
		this.getCatalogueProd().tailleDisplaysMessage(this, event);
	},

	displayDragDropMessage: function(event) {
		event = new Event(event);
		if (this.fxDragMessage == null) {
			this.fxDragMessage = this.dragDropMessage.makeDraggable(); // this returns the dragged element
		}

		this.dragDropMessage.setStyle('display', 'block');
		this.dragDropMessage.setStyles({'top': event.page.y - 20 - this.dragDropMessage.getCoordinates().height, 'left': event.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});

		if (this.fxHideMessage != null) {
			this.fxHideMessage.cancel();
		}

		if (this.fxDragMessage != null) {
			this.fxDragMessage.cancel();
			this.fxDragMessage.start(event);
		}

	},

	hideDragDropMessage: function(event) {
		if (this.dragDropMessage == null) {
			return;
		}

		if (this.fxHideMessage == null) {
			this.fxHideMessage = new Fx.Tween(this.dragDropMessage, {property:'opacity', duration:500, onComplete: function() {
				this.realHideDragDropMessage();
			}.bind(this) });
		}
		this.fxHideMessage.cancel();
		this.fxHideMessage.start(0);
	},

	realHideDragDropMessage: function() {
		this.dragDropMessage.setStyle('display', 'none');
		if (this.fxHideMessage != null) {
			this.fxHideMessage.cancel();
			this.fxHideMessage = null;
		}
		if (this.fxDragMessage != null) {
			this.fxDragMessage.cancel();
			this.fxDragMessage = null;
		}
	},

	mouseDown: function(event) {
		event = new Event(event);

		this.getCatalogueProd().tailleStartDrag(this, event);

		var pic = this.getCatalogueProd().getPicture();
		var coordspic = pic.getCoordinates();
		var pictopval = coordspic.top;
		var picleftval = coordspic.left;

		topval = Math.round(event.page.y - (coordspic.height / 2) + 10);
		leftval = Math.round(event.page.x - (coordspic.width / 2));

		var clone = new Element(document.createElement('span'));
		var cloneImg = new Element(document.createElement('img'));
		var cloneTaille = new Element(document.createElement('span'));

		cloneImg.src = pic.src;
		cloneImg.inject(clone);

		cloneTaille.innerHTML = this.getTaille();
		cloneTaille.setStyles({'position': 'absolute',
			'top': '5px',
			'left': '5px',
			'background-color': 'white',
			'padding-left': '5px',
			'padding-right': '5px',
			'font-weight': 'bold',
			'font-size': '1.5em',
			'border': 'solid 1px black',
			'font-family': 'Arial,Helvetica,sans-serif'});
		cloneTaille.inject(clone);

		clone.setStyles({'left': leftval, 'top': topval})
			.setStyles({'visibility': 'hidden', 'opacity': 0.7, 'position': 'absolute', 'border': 'solid 2px #888', 'cursor': 'move'});

		clone.inject(document.body);
		clone.setStyles({'visibility': 'visible', 'z-index': '99999'});

		var droppables = [];
		var panier = this.getCatalogueProd().getCatalogueElement().getPanier();
		if (panier != null) {
			droppables = panier.getDroppables();
		}

		this.drag = new Drag.Move(clone, {droppables: droppables, snap: 0,
				onDrop: function(element, droppable, event) {
					this.drag.cancel();
					this.drag = null;
					if (droppable == null) {
						slidefx = new Fx.Morph(clone, {duration: 200, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
							cloneTaille.dispose();
							cloneImg.dispose();
							clone.dispose();
							this.getCatalogueProd().tailleStopDrag(this);
						}.bind(this) });
						slidefx.start({
							'top': pictopval,
							'left': picleftval
						});
					} else {
						// We got it !
						cloneTaille.dispose();
						cloneImg.dispose();
						clone.dispose();
						this.getCatalogueProd().tailleStopDrag(this);

						if (panier != null) {
							panier.addProduct(this.getCatalogueProd().getBarCode(), this.getTaille());
						}
					}
				}.bind(this),
				onEnter: function(element, droppable) {
					clone.setStyles({'opacity': 1, 'border': 'solid 3px #000'});
				}.bind(this),
				onLeave: function(element, droppable) {
					clone.setStyles({'opacity': .7, 'border': 'solid 2px #888'});
				}.bind(this)
			 });
		this.drag.start(event);

		event.stop();

		return false;
	}
});
