window.addEvent('domready', function(){
	
	initImages();
	initSavoirfaire();
});

function initSavoirfaire(){
	
	if( $('tab_avant70') && $('tab_apres70') ){
		$('tab_avant70').addEvent('click', function(){
			new Fx.Slide('avant70').slideIn();
			new Fx.Slide('apres70').slideOut();
			
			return false;
		});
		$('tab_apres70').addEvent('click', function(){
			$('apres70').setStyle('display', 'block');
			new Fx.Slide('avant70').slideOut();
			new Fx.Slide('apres70').slideIn();
			$('bt_apres70gif').src='/naturana/www/images/bt_apres70_o.gif';			
			return false;
		});
	}
	
}

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;
				}
			}
		}
	});
}

// Mise à jour du nombre de produits dans le panier
function updateBasketNbArticles() {
	if( $('headerbasketarticlesinfo') ) {
		new Request.HTML({
			url : Site.Page.getBaseUrl + '/js/updatebasketarticles.js.php',
			update: $('headerbasketarticlesinfo')
			// onComplete: function() {
			// }
		}).post();
	}
}

sfHover = function() {
	// On applique une pseudo class :hover sur tous les li contenu dans #nav pour IE6
	var tmp = $("nav-wrap");
	if(tmp != null)
	{
		var sfEls = $("nav-wrap").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);
