


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

var menuInside;
var menuOutside;



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.Style(big_taille_span, 'top', {duration: 200});
  }
  if (bigTailleDown == true) {
    fxBigTaille.stop();
  }
  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();
  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;
  }
  if (fxBigTaille == null) {
    fxBigTaille = new Fx.Style(big_taille_span, 'top', {duration: 200});
  }
  if (bigTailleUp == true) {
    fxBigTaille.stop();
  }
  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';
		}
	}
}

var lastResizeVal = 0;
var lastWasSame = false;
var resizeCounter = 0;

function resize_menu_marque() {
	real_resize_menu_marque(true);
}

function resize_menu_prods() {
	real_resize_menu_marque(false);
}

function real_resize_menu_marque(isRayon) {
	if (resizeCounter > 6) {
		return;
	}
	dl_div = $('menu-marque-dl-div');
	if (isRayon == true) {
		content_div = $('container-rayon');
	} else {
		content_div = $('container-mid-right');
	}

	dl_coords = dl_div.getCoordinates();
	dl_div.setStyle('display', 'none');
	content_coords = content_div.getCoordinates();
	dl_div.setStyle('display', 'block');

	bottom = content_coords.top + content_coords.height;
	window_height = window.getOnifinHeight() - 27;

	if (window_height > bottom) {
		bottom = window_height;
	}

	new_dl_height = (bottom - dl_coords.top).toInt();

	if (menuOutside != null) {
		menuOutside.setHeight(new_dl_height);
		menuOutside.setMaxHeight(new_dl_height);
	}

	var timeOutFunc = function() {
		real_resize_menu_marque(isRayon);
	}
	if (new_dl_height != lastResizeVal) {
		resizeCounter = resizeCounter + 1;
		lastResizeVal = new_dl_height;
		lastWasSame = false;

		window.setTimeout(timeOutFunc, 1000);
	} else {
		if (lastWasSame == false) {
			lastWasSame = true;
			window.setTimeout(timeOutFunc, 1000);
		}
	}
}


function checkPageHeight() {
	page_div = $('page1');

	window_height = window.getOnifinHeight() - 27;

	if (window.ie6) {
		return;
	}

	if (page_div != null) {
		page_div.setStyle('min-height', (window_height)+'px');
	}
	page_div = $('page2');
	if (page_div != null) {
		page_div.setStyle('min-height', (window_height)+'px');
	}
	page_div = $('page3');
	if (page_div != null) {
		page_div.setStyle('min-height', (window_height)+'px');
	}
	page_div = $('page4');
	if (page_div != null) {
		page_div.setStyle('min-height', (window_height)+'px');
	}
	page_div = $('page5');
	if (page_div != null) {
		page_div.setStyle('min-height', (window_height)+'px');
	}
	page_div = $('page6');
	if (page_div != null) {
		page_div.setStyle('min-height', (window_height - 15)+'px');
	}
}
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 Ajax('/ajax_panier', {method: 'post', data: {
		type : 'suppr',
		prod: prod,
		taille: taille
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		if (drop == null) {
			drop = $('panier1');
		}
		inner_table = $('panier_table');
		if (inner_table != null) {
			inner_table.innerHTML = result;
		}
		drop.setStyles({'visibility': 'visible'});
		inner_table.setStyles({'visibility': 'visible'});
	} }).request();
}

function commitPanier(prod_barcode){
	panier = $('panier_table');
	panier.setStyles({'visibility': 'hidden'});

	var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
			codeProd : prod_barcode
		}, onComplete: function(result) {
			//alert('complete ! '+result);
			//panier.setInnerHTML($result);
			panier.innerHTML = result;
			panier.setStyles({'visibility': 'visible'});
	} }).request();
}

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_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 = 'Available Sizes :<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.Style(sizesAssocieMessage, '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.stop();
	}
	/*fxShowSizesAssocieMessage.stop();
	fxShowSizesAssocieMessage.start(0.8);*/
	if (fxDragSizesAssocieMessage != null) {
		fxDragSizesAssocieMessage.stop();
		if (isIE6 == false) {
			fxDragSizesAssocieMessage.start(e); // start the event manual
		}
	}
}
function hideSizesAssocieMessage(ev) {
	if (sizesAssocieMessage == null) {
		return;
	}
		if (fxHideSizesAssocieMessage == null) {
		fxHideSizesAssocieMessage = new Fx.Style(sizesAssocieMessage, 'opacity', {duration:500, onComplete: function() {
							sizesAssocieMessage.remove();
							sizesAssocieMessage = null;
							fxHideSizesAssocieMessage = null;
							fxDragSizesAssocieMessage.stop();
							fxDragSizesAssocieMessage = null;
						} });
	}
	if (fxShowSizesAssocieMessage != null) {
		fxShowSizesAssocieMessage.stop();
	}
	fxHideSizesAssocieMessage.stop();
	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';
	}
}

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;
	}

	checkPageHeight();

	window.addEvent('windowResized', this.checkPageHeight);



	drop = $('panier1');
	if (drop != null) {
		var dropFx = drop.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
		effetPanier = drop.effect('opacity', {duration: 300});
		periodical;
		fxx = function() {
			effetPanier.start(0).chain(function() {
				effetPanier.start(1);
			});
		}
	}

	var current_codeProd;
	var current_taille;

	if ($('fiche_prod_pic') != null && $('drag_drop_link') != null) {
		dragables = [$('fiche_prod_pic'), $('drag_drop_link')];
	} else {
		dragables = [];
	}

	// Est-ce que le produit est epuisé ?
	epuiseSpan = $('produit_epuise');
	if (epuiseSpan != null) {
		dragables = [];
	}

	dragables.each(function(item) {
		item.addEvent('mousedown', function(e) {
			e = new Event(e).stop();
			pic_div = $('fiche_prod_pic');
			if (pic_div == null) {
				return;
			}
			pic_div_coords = pic_div.getCoordinates();
			pic_center_x = pic_div_coords.left + (pic_div_coords.width / 2) - 85;
			pic_center_y = pic_div_coords.top + (pic_div_coords.height / 2) - 30;

			var coords = this.getCoordinates();
			//topval = coords.top - 70;
			//leftval = coords.left - 40;
			topval = e.page.y - 30;
			leftval = e.page.x - 85;

			var clone = pic_div.clone()
				.setStyles({'left': leftval, 'top': topval, 'width': '170px'})
				.setStyles({'visibility': 'hidden', 'opacity': 0.7, 'position': 'absolute', 'cursor': 'move'})
				.addEvent('emptydrop', function() {
					tueEffetPanier();
					slidefx = new Fx.Styles(this, {duration: 200, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
						clone.remove();
					} });
					slidefx.start({
						'top': pic_center_y,
						'left': pic_center_x
					});

					//kwickEffectEnabled = true;
					//this.remove();
					drop.removeEvents();
				});

			clone_children = clone.getChildren();
			if (clone_children.length == 1) {
				photo_prod = clone_children[0];
				if (photo_prod != null) {
					photo_prod.setStyles({'width': '170px'});
				}
			}
			clone.inject(document.body);
			clone.setStyles({/*'left': picleftval, 'top': pictopval, */'visibility': 'visible'})
			slidefx1 = new Fx.Styles(clone, {duration: 150, transition: Fx.Transitions.linear, wait: true});
			slidefx1.start({
				'top': topval,
				'left': leftval
			});

			drop.addEvents({
				'drop': function() {
					tueEffetPanier();
					drop.removeEvents();
					clone.remove();
					this.setStyles({'visibility': 'hidden'});

					code_div = $('code_prod_div');
					if (code_div != null) {
						current_codeProd = code_div.innerHTML;
					}

					var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
	codeProd : current_codeProd
}, onComplete: function(result) {
						//alert(result);
						inner_table = $('panier_table');
						if (inner_table != null) {
							inner_table.innerHTML = result;
						}
						drop.setStyles({'visibility': 'visible', 'opacity': '1'});
						//drop.setStyles({'background-color': '#E6E6E6', 'visibility': 'visible'});
						} }).request();
					//item.clone().inject(drop);
					//dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
					kwickEffectEnabled = true;
				},
				'over': function() {
					tueEffetPanier();
					//dropFx.start('98B5C1');
					//$clear(periodical);
					this.setStyles({'opacity': '1'});
					clone.setStyles({'border': 'solid 5px ' + defaultColor1});
				},
				'leave': function() {
					demarreEffetPanier();
					//dropFx.start('ffffff');
					clone.setStyles({'border': 'none'});
				}
			});

			var drag = clone.makeDraggable({
				droppables: [drop]
			}); // this returns the dragged element
	
			drag.start(e); // start the event manual

			// Début de l'effet du panier
			demarreEffetPanier();
		});
	});

		
	$$('.span_draggable').each(function(item){
		
		item.addEvent('mousedown', function(e) {
			kwickEffectEnabled = false;
			hideDragDropMessage1(e);

			e = new Event(e).stop();

/*****************************************************************************************************************/

			found_picture = false;
			dad = this.getParent();
			if (dad != null) {
				//alert('dad : '+dad+' / '+dad.className);
				grandPa = dad.getParent();
				if (grandPa != null) {
					//alert('grandPa : '+grandPa+' / '+grandPa.className);
					grandgrandPa = grandPa.getParent();
					if (grandgrandPa != null) {
						//alert('grandgrandPa : '+grandgrandPa+' / ' + grandgrandPa.className);
						currentlyDraggedKwick = grandgrandPa;
						//currentlyDraggedKwick.setStyles({'background-color': '#c4c4c4'});
						//currentlyDraggedKwick.fireEvent('mouseout');
						/*grandPa3 = grandgrandPa.getParent();
						if (grandPa3 != null) {
							grandPa4 = grandPa3.getParent();
							if (grandPa4 != null) {
								//alert('grandPa4 : '+grandPa4+' / ' + grandPa4.className);
								currentlyDraggedKwick = grandPa4;
							}
						}*/
					}
					children = grandPa.getChildren();
					for (i=0; i<children.length; i++) {
						//alert('child : '+children[i].className);
						if (children[i].className == 'prod_and_name') {
							coordspic = children[i].getCoordinates();
							pictopval = coordspic.top;
							picleftval = coordspic.left;
							/*pictopval = children[i].getPosition().y;
							picleftval = children[i].getPosition().x;*/
							//alert('top : '+pictopval+' - left'+pictopval);

							picToDrag = children[i].clone();

							if (isSafari == true) {
								childrenBis = picToDrag.children;
								for (j = 0; j < childrenBis.length; j++) {
									//alert('child : '+childrenBis[j]+" / "+childrenBis[j].className);
									if (childrenBis[j].className != 'prod_photo') {
										if (childrenBis[j].className == 'infos-miniprod') {
											current_codeProd = childrenBis[j].innerHTML;
											current_codeProd = current_codeProd.trim();
										}
										//childrenBis[j].remove();
										childrenBis[j].setStyle('display', 'none');
									}
								}
							} else {
								childrenBis = picToDrag.getChildren();
								for (j = 0; j < childrenBis.length; j++) {
									if (childrenBis[j].className != 'prod_photo') {
										if (childrenBis[j].className == 'infos-miniprod') {
											current_codeProd = childrenBis[j].innerHTML;
											current_codeProd = current_codeProd.trim();
										}
										childrenBis[j].remove();
									}
								}
							}

							current_taille = this.innerHTML;
							current_taille = current_taille.trim();
							if (isSafari == true) {
								real_taille = '';
								for (var i = 0; i < current_taille.length; i++) {
									if (current_taille.charCodeAt(i) == 160) {
										real_taille = real_taille + " ";
									} else {
										real_taille = real_taille + String.fromCharCode(current_taille.charCodeAt(i));
									}
								}
								current_taille = real_taille;
							}
							picToDrag.appendChild(this.clone().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'}));
							//picToDrag = childrenBis[j];
							found_picture = true;
							break;
						}
					} 
				}
			}

			if (found_picture) {
/*				for (i=0; i < this.getCoordinates().getValues().length(); i++) {
					alert('test');
				}*/
				var coords = this.getCoordinates();
				//topval = coords.top - 70;
				//leftval = coords.left - 40;
				topval = e.page.y - 70;
				leftval = e.page.x - 50;

				var clone = picToDrag.clone()
					.setStyles({'left': leftval, 'top': topval})
					.setStyles({'visibility': 'hidden', 'opacity': 0.7, 'position': 'absolute', 'border': 'solid 2px black', 'cursor': 'move'})
					.addEvent('emptydrop', function() {
						tueEffetPanier();
						slidefx = new Fx.Styles(this, {duration: 200, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
							clone.remove();
							clearKwicks();
							kwickEffectEnabled = true;
						} });
						slidefx.start({
							'top': pictopval,
							'left': picleftval
						});

						//kwickEffectEnabled = true;
						//this.remove();
						drop.removeEvents();
					});
				clone.inject(document.body);
				clone.setStyles({/*'left': picleftval, 'top': pictopval, */'visibility': 'visible'})
				slidefx1 = new Fx.Styles(clone, {duration: 150, transition: Fx.Transitions.linear, wait: true});
				slidefx1.start({
					'top': topval,
					'left': leftval
				});
			} else {


/*****************************************************************************************************************/

			
				var clone = this.clone()
					.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
					.setStyles({'opacity': 0.7, 'position': 'absolute', 'border': 'solid 1px black'})
					.addEvent('emptydrop', function() {
						$clear(periodical);

						kwickEffectEnabled = true;
						this.remove();
						drop.removeEvents();
					}).inject(document.body);
			}
			
			drop.addEvents({
				'drop': function() {
					tueEffetPanier();
					drop.removeEvents();
					clone.remove();
					this.setStyles({'visibility': 'hidden'});
					var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
	codeProd : current_codeProd,
	taille : current_taille
}, onComplete: function(result) {
						//alert(result);
						drop.innerHTML = result;
						drop.setStyles({'visibility': 'visible', 'opacity': '1'});
						//drop.setStyles({'background-color': '#E6E6E6', 'visibility': 'visible'});
						} }).request();
					//item.clone().inject(drop);
					//dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
					kwickEffectEnabled = true;
				},
				'over': function() {
					tueEffetPanier();
					//dropFx.start('98B5C1');
					//$clear(periodical);
					this.setStyles({'opacity': '0'});
					clone.setStyles({'border': 'solid 5px ' + defaultColor1});
				},
				'leave': function() {
					demarreEffetPanier();
					//dropFx.start('ffffff');
					clone.setStyles({'border': 'solid 2px black'});
				}
			});
			
			var drag = clone.makeDraggable({
				droppables: [drop]
			}); // this returns the dragged element
	
			drag.start(e); // start the event manual

			// Début de l'effet du panier
			demarreEffetPanier();
		});
		
	});



	$$('.span_draggable_big').each(function(item){
		
		item.addEvent('mousedown', function(e) {
			kwickEffectEnabled = false;
			hideDragDropMessage1(e);

			e = new Event(e).stop();

/*****************************************************************************************************************/

			found_picture = false;
			dad = this.getParent();
			if (dad != null) {
				//alert('dad : '+dad+' / '+dad.className);
				grandPa = dad.getParent();
				if (grandPa != null) {
					//alert('grandPa : '+grandPa+' / '+grandPa.className);
					grandgrandPa = grandPa.getParent();
					if (grandgrandPa != null) {
						//alert('grandgrandPa : '+grandgrandPa+' / ' + grandgrandPa.className);
						currentlyDraggedKwick = grandgrandPa;
						//currentlyDraggedKwick.setStyles({'background-color': '#c4c4c4'});
						//currentlyDraggedKwick.fireEvent('mouseout');
						/*grandPa3 = grandgrandPa.getParent();
						if (grandPa3 != null) {
							grandPa4 = grandPa3.getParent();
							if (grandPa4 != null) {
								//alert('grandPa4 : '+grandPa4+' / ' + grandPa4.className);
								currentlyDraggedKwick = grandPa4;
							}
						}*/
					}
					children = grandPa.getChildren();
					for (i=0; i<children.length; i++) {
						//alert('child : '+children[i].className);
						if (children[i].className == 'big_prod_and_name') {
							coordspic = children[i].getCoordinates();
							pictopval = coordspic.top;
							picleftval = coordspic.left;
							/*pictopval = children[i].getPosition().y;
							picleftval = children[i].getPosition().x;*/
							//alert('top : '+pictopval+' - left'+pictopval);

							picToDrag = children[i].clone();

							if (isSafari == true) {
								childrenBis = picToDrag.children;
								for (j = 0; j < childrenBis.length; j++) {
									//alert('child : '+childrenBis[j]+" / "+childrenBis[j].className);
									if (childrenBis[j].className != 'big_prod_photo') {
										if (childrenBis[j].className == 'big_infos-miniprod') {
											current_codeProd = childrenBis[j].innerHTML;
											current_codeProd = current_codeProd.trim();
										}
										//childrenBis[j].remove();
										childrenBis[j].setStyle('display', 'none');
									}
								}
							} else {
								childrenBis = picToDrag.getChildren();
								for (j = 0; j < childrenBis.length; j++) {
									if (childrenBis[j].className != 'big_prod_photo') {
										if (childrenBis[j].className == 'big_infos-miniprod') {
											current_codeProd = childrenBis[j].innerHTML;
											current_codeProd = current_codeProd.trim();
										}
										childrenBis[j].remove();
									}
								}
							}

							current_taille = this.innerHTML;
							current_taille = current_taille.trim();
							if (isSafari == true) {
								real_taille = '';
								for (var i = 0; i < current_taille.length; i++) {
									if (current_taille.charCodeAt(i) == 160) {
										real_taille = real_taille + " ";
									} else {
										real_taille = real_taille + String.fromCharCode(current_taille.charCodeAt(i));
									}
								}
								current_taille = real_taille;
							}
							picToDrag.appendChild(this.clone().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'}));
							//picToDrag = childrenBis[j];
							found_picture = true;
							break;
						}
					} 
				}
			}

			if (found_picture) {
/*				for (i=0; i < this.getCoordinates().getValues().length(); i++) {
					alert('test');
				}*/
				var coords = this.getCoordinates();
				//topval = coords.top - 70;
				//leftval = coords.left - 40;
				topval = e.page.y - 140;
				leftval = e.page.x - 100;

				var clone = picToDrag.clone()
					.setStyles({'left': leftval, 'top': topval})
					.setStyles({'visibility': 'hidden', 'opacity': 0.7, 'position': 'absolute', 'border': 'solid 2px black', 'cursor': 'move'})
					.addEvent('emptydrop', function() {
						tueEffetPanier();
						slidefx = new Fx.Styles(this, {duration: 200, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
							clone.remove();
							clearKwicks();
							kwickEffectEnabled = true;
							hideBigTaille(null);
						} });
						slidefx.start({
							'top': pictopval,
							'left': picleftval
						});

						//kwickEffectEnabled = true;
						//this.remove();
						drop.removeEvents();
					});
				clone.inject(document.body);
				clone.setStyles({/*'left': picleftval, 'top': pictopval, */'visibility': 'visible', 'z-index': 2})
				slidefx1 = new Fx.Styles(clone, {duration: 150, transition: Fx.Transitions.linear, wait: true});
				slidefx1.start({
					'top': topval,
					'left': leftval
				});
			} else {


/*****************************************************************************************************************/

			
				var clone = this.clone()
					.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
					.setStyles({'opacity': 0.7, 'position': 'absolute', 'border': 'solid 1px black'})
					.addEvent('emptydrop', function() {
						$clear(periodical);

						kwickEffectEnabled = true;
						this.remove();
						drop.removeEvents();
					}).inject(document.body);
			}
			
			drop.addEvents({
				'drop': function() {
					tueEffetPanier();
					clearKwicks();
					drop.removeEvents();
					clone.remove();
					this.setStyles({'visibility': 'hidden'});
					var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
	codeProd : current_codeProd,
	taille : current_taille
}, onComplete: function(result) {
						//alert(result);
						drop.innerHTML = result;
						drop.setStyles({'visibility': 'visible', 'opacity': '1'});
						//drop.setStyles({'background-color': '#E6E6E6', 'visibility': 'visible'});
						} }).request();
					//item.clone().inject(drop);
					//dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
					kwickEffectEnabled = true;
					hideBigTaille(null);
				},
				'over': function() {
					tueEffetPanier();
					//dropFx.start('98B5C1');
					//$clear(periodical);
					this.setStyles({'opacity': '0'});
					clone.setStyles({'border': 'solid 5px ' + defaultColor1});
				},
				'leave': function() {
					demarreEffetPanier();
					//dropFx.start('ffffff');
					clone.setStyles({'border': 'solid 2px black'});
				}
			});
			
			var drag = clone.makeDraggable({
				droppables: [drop]
			}); // this returns the dragged element
	
			drag.start(e); // start the event manual

			// Début de l'effet du panier
			demarreEffetPanier();
		});
		
	});
});

function demarreEffetPanier() {
	fxx();
	periodical = fxx.periodical(700);
}
function stopEffetPanier() {
	$clear(periodical);
	drop.setStyle('opacity', '1');
}
function tueEffetPanier() {
	$clear(periodical);
	effetPanier.stop();
	drop.setStyle('opacity', '1');
}


function clearKwicks() {
	var obj = {};
	kwicks.each(function(other, j){
		obj[j] = {'width': [other.getStyle('width').toInt(), 104]};
	});
	fx.start(obj);
	lastEntered = null;
	if (currentlyDraggedKwick != null) {
		//currentlyDraggedKwick.setStyles({'background': '#c4c4c4'});
	}
}


function chgPanierNum(prod, taille, num){
	//alert(prod+" : "+taille); return;
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Ajax('/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'});
	} }).request();
}
function supprPanier2(prod,taille){
	//alert(prod+" : "+taille); return;
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Ajax('/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'});
	} }).request();
}

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

function link_onover(link, divname) {
	link.setStyles({'background-color': 'black', 'color': 'white'});
}
function link_onout(link, divname) {
	link.setStyles({'background-color': 'transparent', 'color': 'black'})
}

function slideCmdeUp(linkname, 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();
	}
	link = $(linkname);
	if (link != null) {
		if (link.hasClass('opened')) {
			link.removeClass('opened');
		} else {
			link.addClass('opened');
		}
	}
	//link.removeClass('opened');
	slider.stop();
	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');

	if (restant > 0) {
		unchecked.each(function(avoir, i) {
				if (avoir == null) {
					return;
				}
				avoir.disabled = false;
			});

		if (totalAvoirs != 0) {
			if (reg_par != null) {
				reg_par.innerHTML = 'Proceed to payment <b>[US&#36;  '+restant+']</b></u> par';
			}
		} else {
			if (reg_par != null) {
				reg_par.innerHTML = 'Proceed to payment ';
			}
		}
		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 = 'Slide the chosen Size<br/>to the basket';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, '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.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		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>Last in stock !!!</u></font><br/>Slide to basket';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, '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.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		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">Size out of stock.</font>';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, '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.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function hideDragDropMessage1(ev) {
	if (dragDropMessage1 == null) {
		return;
	}

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

	if (fxHideMessage1 == null) {
		fxHideMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:500, onComplete: function() {
								dragDropMessage1.remove();
								dragDropMessage1 = null;
								fxHideMessage1 = null;
							} });
	}
	if (fxShowMessage1 != null) {
		fxShowMessage1.stop();
	}
	fxHideMessage1.stop();
	fxHideMessage1.start(0);
}

function disconnect(redirect_uri) {
	var myAjax = new Ajax('/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();
			}
		} }).request();
}

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

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

window.addEvent('windowResized', resize_scroll);
window.addEvent('windowScrolled', 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 && margin_top > 0) {
		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.Style(panier_div, 'margin-top', {duration:600});
		}
		fxPanier.stop();
		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 && margin_top > 0) {
		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.Style(image_div, 'margin-top', {duration:time_fx});
		}
		fxImage.stop();
		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.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg1txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.stop();
		fxImg1txt.stop();
		fxImg1.start(0);
		fxImg1txt.start('#ffffff');
	}
}
function fxMouseOutImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.stop();
		fxImg1txt.stop();
		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.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg2txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.stop();
		fxImg2txt.stop();
		fxImg2.start(0);
		fxImg2txt.start('#ffffff');
	}
}
function fxMouseOutImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.stop();
		fxImg2txt.stop();
		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.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg3txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.stop();
		fxImg3txt.stop();
		fxImg3.start(0);
		fxImg3txt.start('#ffffff');
	}
}
function fxMouseOutImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.stop();
		fxImg3txt.stop();
		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.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg4txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.stop();
		fxImg4txt.stop();
		fxImg4.start(0);
		fxImg4txt.start('#ffffff');
	}
}
function fxMouseOutImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.stop();
		fxImg4txt.stop();
		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 Ajax('/ajax_update_livraison', {method: 'post', data: {
		'pays': pays_val,
		'code_postal': code_postal_val
	}, onComplete: function(result) {
		livr_div.innerHTML = result;
	} }).request();
}
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 load_cache_images(suppImages, cat) {

	var cache_imgs = ""
	if (cat == null || cat != true) {
		cache_imgs = '<img src="/images/plus.png" class="cache_img" />\n<img src="/images/plus2.gif" class="cache_img" />\n<img src="/images/moins2.gif" class="cache_img" />\n<img src="/images/arrow_left.png" class="cache_img" />\n<img src="/images/arrow_right.png" class="cache_img" />\n<img src="/images/refresh_arrow.png" class="cache_img" />\n<img src="/images/delete.png" class="cache_img" /><img src="/images/charte/cadre_black_bottom.png" class="cache_img" />\n<img src="/images/charte/cadre_black_bottom_left.gif" class="cache_img" />\n<img src="/images/charte/cadre_black_bottom_left.png" class="cache_img" />\n<img src="/images/charte/cadre_black_bottom_right.gif" class="cache_img" />\n<img src="/images/charte/cadre_black_bottom_right.png" class="cache_img" />\n<img src="/images/charte/cadre_black_full_bottom_left.png" class="cache_img" />\n<img src="/images/charte/cadre_black_full_bottom_right.png" class="cache_img" />\n<img src="/images/charte/cadre_black_left.png" class="cache_img" />\n<img src="/images/charte/cadre_black_right.png" class="cache_img" />\n<img src="/images/charte/cadre_black_top.png" class="cache_img" />\n<img src="/images/charte/cadre_black_top_left.gif" class="cache_img" />\n<img src="/images/charte/cadre_black_top_left.png" class="cache_img" />\n<img src="/images/charte/cadre_black_top_left_black.jpg" class="cache_img" />\n<img src="/images/charte/cadre_black_top_right.gif" class="cache_img" />\n<img src="/images/charte/cadre_black_top_right.png" class="cache_img" />\n<img src="/images/charte/cadre_black_top_right_black.jpg" class="cache_img" />\n<img src="/images/charte/degrade_bg_half_top.jpg" class="cache_img" />\n<img src="/images/charte/degrade_bg_half_top2.jpg" class="cache_img" />\n<img src="/images/charte/degrade_bg_small.jpg" class="cache_img" />\n<img src="/images/charte/page_bg.jpg" class="cache_img" />\n<img src="/images/charte/page_bg_repeat.jpg" class="cache_img" />\n<img src="/images/charte/menu/account.png" class="cache_img" />\n<img src="/images/charte/menu/basket.png" class="cache_img" />\n<img src="/images/charte/menu/collectors.png" class="cache_img" />\n<img src="/images/charte/menu/contact.png" class="cache_img" />\n<img src="/images/charte/menu/optic_couture.png" class="cache_img" />\n<img src="/images/charte/menu/revolutionary_correct.png" class="cache_img" />\n<img src="/images/charte/menu/specials.png" 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 submitForm(formID) {
	formular = $(formID);
	if (formular != null) {
		formular.submit();
	}
}



var JeeviceVerticalAutoMouseFloatingBlockElement = VerticalAutoMouseFloatingBlockElement.oniExtend({

	initialize: function(el, insideLinkedBlockElement, btn_top, btn_bottom) {
		this.getCurrentOniClass(arguments.callee).parentProto.initialize.bind(this)(el, insideLinkedBlockElement);

		this.lastHeight = this.insideBlock.getHeight();

		window.setTimeout(this.timeOutHack.bind(this), 1000);
	},

	timeOutHack: function() {
		var timeOutFunc = function() {
			this.timeOutHack();
		}

		var tmp_height = this.insideBlock.getElement().getStyle('height').toInt();
		if (tmp_height != this.lastHeight) {
			this.insideBlock.setHeight(tmp_height);
			if ($defined(this.maxHeight) && this.maxHeight < this.getHeight()) {
				this.setHeight(this.maxHeight);
			}
			this.checkRatio();

			this.lastHeight = tmp_height;

			window.setTimeout(timeOutFunc.bind(this), 1000);
			return;
		}
	},

	setMaxHeight: function(maxHeight) {
		this.maxHeight = maxHeight;
	}

});
