function fDelete(){
	$$('.fDelete').each(function(el){
		el.addEvent('click', function(e){
			e = new Event(e);
			if( !confirm(el.title ? el.title : 'Etes vous sûr de vouloir supprimer cet élément ?')){
				e.stop();
			}
		});
	});
}

function fFlashMessage() {
	new mooFlashMessage($$('.flash'));
}

function fMarquee() {
	if($('marqueebox')){
		new mooMarquee($('marqueebox'), $$('#marqueebox .marquee'), {'waitDuration': 10000});
	}
}

function fInit(){
	fMarquee();
	fFlashMessage();
	fDelete();
}
window.addEvent('domready', fInit);

function popup(href, name, h, l) {
	var hauteur = Math.round((screen.availHeight - h) / 2);
	var largeur = Math.round((screen.availWidth - l) / 2);
	var popup = window.open(href, name, 'toolbar=0,location=0,directories=0,status=0, scrollbars=1,resizable=1,menubar=0,top='+hauteur+',left='+largeur+',width='+l+',height='+h);
	popup.focus();
	return false;	
}

function popupOrder(Obj) {
	return popup(Obj.href, 'order', 600, 680);
}
/* Function image hover */

function initImages() {	
	document.imageOut = new Object();
	document.imageOver = new Object();

	var imageArray = $$("img", "input");
	imageArray.each(function(item){
		var image = item.src.substr(item.src.lastIndexOf("/")+1);
		var id = item.id || image.replace("_n.", "").replace("_N.", "");
		var hover = (image.toLowerCase().lastIndexOf("_n.") !=-1);
		//
		if (hover && document.imageOut && document.imageOver) {
			document.imageOut[id] = new Image();
			document.imageOut[id].src = item.src;
			document.imageOver[id] = new Image();
			document.imageOver[id].src = item.src.substr(0, item.src.lastIndexOf("/")+1)+image.replace("_n.", "_o.").replace("_N.", "_O.");
		}

		if (hover && document.imageOut && document.imageOver) {
			item.onmouseover = function(){
				//alert("mouseover");
				if (document.imageOver && document.imageOver[this.id]) setImage(this, document.imageOver[this.id].src);
			}
			item.onmouseout = function(){
				if (document.imageOut && document.imageOut[this.id]) setImage(this, document.imageOut[this.id].src);
			}
			item.id = id;
			//
			function setImage(imageObject, src) {
				/*if (window.ie && !window.ie7) {
					if (imageObject.filters[f] && imageObject.filters[f].src.test(pngRegExp)) {
						imageObject.filters[f].src = src;
					} else {
						imageObject.src = src;
					}
				} else {*/
					imageObject.src = src;
				/*}*/
			}
		}
	});
}
window.addEvent('domready', initImages);

/* change la value du champs de recherche */
window.addEvent('domready', function(){
	$$('.inputsearch').addEvent('click', function(){
		this.set('value', '');	});
});
window.addEvent('domready', function(){
	$$('.adresse-email').addEvent('click', function(){
		this.set('value', '');	});
});
window.addEvent('domready', function(){
	$$('input[name="email"]').addEvent('click', function(){
		this.set('value', '');	});
});

/* menu SuckerFish*/
sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*opacité*/
function set_opacity()
{
	if ($('menu-logged') != null) {
       $('menu-logged').setStyle('opacity', 0.8);
	}
}
window.addEvent('domready', set_opacity);

/**
 * Fonction qui permet de changer l'image principale en cliquant sur les miniatures (utilisée sur la fiche produit notamment)
 * #wrapPrincipal : div principal contenant les images
 * miniatures : classe sur les liens des miniatures (a.miniatures)
 * #productPrincipale : id de l'image principale
 */
/*
function fChangeImage() {
	var productImages = $$('#wrapPrincipal a.miniatures');
	if( productImages.length > 0 ) {
		productImages.each( function(el, index) {
			el.addEvent('click', function(e) {
				e.stop(); 
				var currentImageHref = el.getProperty('href');
				var currentWidth = 225;//el.getProperty('width')
				var currentHeight = ''//auto;
				var currentImageSrc = el.getElement('img').getProperty('src').replace(/_thumb_/,"_full_");
				$('productPrincipale').getParent().set('href', currentImageHref);				
				$('productPrincipale').set('width',currentWidth);
				$('productPrincipale').set('height',currentHeight);
				$('productPrincipale').set('src',currentImageSrc).setStyle('opacity','0');
				$('productPrincipale').set('tween', {duration:1000});
				$('productPrincipale').tween('opacity', [0, 1]);
			});
		});
	}
}
*/
function fChangeImage() {
	var productImages = $$('#wrapPrincipal a.img-principale');
	var productImagesThumbs = $$('#wrapPrincipal a.miniatures');
	if(productImages.length == productImagesThumbs.length) {
		productImagesThumbs.each(function(el, index) {
			el.addEvent('click', function(e) {
				productImages.setStyle('display', 'none');
				productImages[index].setStyle('display', '').tween('opacity', [0, 1]);
				e.stop(); 
			});
			if (index != 0) {
				productImages[index].setStyle('display', 'none');
			}
		});
	}
}
window.addEvent('domready', fChangeImage);

/* gérer l'opacité des images produits */

function variousOpacity() {
	var miniatures = $$('#wrapPrincipal .miniatures');
	
	miniatures.setStyle('opacity', 0.7);
	
	miniatures.each(function(el, index){
			el.addEvent('click', function(){
				if (this.getProperty('href') == $$('.img-principale').getProperty('href')) {
					miniatures.setStyle('opacity', 0.7);
					this.setStyle('opacity', 1);
					this.setStyle('border-color', '#707070');
				}
			});
	});
}
window.addEvent('domready', variousOpacity);
/*
---
description:     Equalizer

authors:
  - David Walsh (http://davidwalsh.name)

license:
  - MIT-style license

requires:
  core/1.2.1:   '*'

provides:
  - Equalizer
...
*/
var Equalizer = new Class({
	initialize: function(elements) {
		this.elements = $$(elements);
	},
	equalize: function(hw) {
		if(!hw) { hw = 'height'; }
		var max = 0,
			prop = (typeof document.body.style.maxHeight != 'undefined' ? 'min-' : '') + hw; //ie6 ftl
			offset = 'offset' + hw.capitalize();
		this.elements.each(function(element,i) {
			var calc = element[offset];
			if(calc > max) { max = calc; }
		},this);
		this.elements.each(function(element,i) {
			element.setStyle(prop,max - (element[offset] - element.getStyle(hw).toInt()));
		});
		return max;
	}
});

/* equalize heights */
function equalizeColumn() {
	var columnizer = new Equalizer('.column-actu').equalize('height'); //call .equalize() as often as you want! 
	var columnizer = new Equalizer('.cat-column').equalize('height'); 
	var columnizer = new Equalizer('.wrap-products').equalize('height');
	var columnizer = new Equalizer('.blocmentions').equalize('height');
	var columnizer = new Equalizer('.wrap-products-video h3').equalize('height');
	var columnizer = new Equalizer('.actu .corps-actu').equalize('height')
	
}
window.addEvent('domready', equalizeColumn);

/* fonction IE 6 correction menu */
function iframeMenu() {
	if (Browser.Engine.trident4) {
				var elem = $$('.menu-produits');
				var iframe  = new Element('iframe');
				var elemNiv1 = elem.getElement('ul');
				var elemNiv2 = elemNiv1.getElement('ul');
				iframe.setStyles({
					position:'absolute',
					left:'-999em',
					border: 'none',
					zIndex:16,
					width:'350px',
					height: '400px'
				});
				iframe.setProperty('frameborder','0')
				iframe.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
				elem.adopt(iframe);
				//iframe.getElement('body').setStyle('background','#0055A6');
	
		elem.addEvents({
		'mouseenter':function(){
			iframe.setStyle('left','0');
			elemNiv1.setStyle('left','0');
		}, 'mouseleave':function(){
			iframe.setStyle('left','-999em');
			elemNiv1.setStyle('left','-999em');
		}
		});
	}
}
window.addEvent('domready', iframeMenu);

/*quantité dans le panier */

window.addEvent('domready',function() {
	$$('form .product-quantity').each(function(div) {
		var input = div.getFirst('input');
		var upButton = new Element('div',{
			'class': 'btn-plus',
			events: {
				click: function() {
					input.value = input.value.toInt() + 1;
				}
			}
		}).inject(div);
		var downButton = new Element('div',{
			'class': 'btn-minus',
			events: {
				click:function() {
					var val = input.value.toInt();
					if(val != 0) {
						input.value = val - 1;
					}
				}
			}
		}).inject(div, 'top');
	});
});


/* modification de l'image de fond de l'entête */

window.addEvent('domready',function() {
var header = $('wrap-header');
	new Element ('div',{
		id: 'wrap-img-header'
	}).inject(header, 'top');
	new Element ('div',{
		id: 'progress'
	}).inject(header, 'top');

	/* preloading */
	var imagesDir = 'images/';
	var images = ['bgd_wrapper2.jpg','bgd_wrapper3.jpg','bgd_wrapper4.jpg','bgd_wrapper5.jpg','bgd_wrapper6.jpg','bgd_wrapper7.jpg','bgd_wrapper8.jpg','bgd_wrapper9.jpg'];
	var holder = $('wrap-img-header');
	images.each(function(img,i){ images[i] = imagesDir + '' + img; }); //add dir to images
	var progressTemplate = 'Loading image {x} of ' + images.length;
	var updateProgress = function(num) {
		progress.set('text',progressTemplate.replace('{x}',num));
	};
	var progress = $('progress');
	updateProgress('text','0');
	var loader = new Asset.images(images, {
		onProgress: function(c,index) {
			updateProgress('text',index + 1);
		},
		onComplete: function() {
			var slides = [];
			/* put images into page */
			images.each(function(im) {
				slides.push(new Element('img',{
					src:im,
					width: 1200,
					height: 151,
					styles: {
						opacity:0,
						top:'112px',
						left:0,
						position:'absolute',
						'z-index': 14
					}
				}).inject(holder));

			});
			var showInterval = 6000;
			var index = 0;
			progress.set('text','');
			(function() {slides[index].tween('opacity',1); }).delay(3000);
			var start = function() {
				(function() {
					holder.setStyle('background','');
					slides[index].fade(0);
					++index;
					index = (slides[index] ? index : 0);
					slides[index].fade(1);
				}).periodical(showInterval);
			};

			/* start the show */
			start();
		}
	});
});


