jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages(
	"images/fr/menu/1-ok.png",
	"images/fr/menu/2-ok.png",
	"images/fr/menu/3-ok.png",
	"images/fr/menu/4-ok.png",
	"images/fr/menu/5-ok.png"
);

$(document).ready(function(){
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
		attribut = "style"
	}
	else {
		attribut = "src"
	}
	var nb_items_menu = 5;
	
	$("#menu_modulo>ul>li>div").mouseover(function () {
		if (typeof($(this).children().attr('href'))!="undefined") element = $(this).children().children("img");
		else element = $(this).children("img");
		imgsrc = element.attr(attribut);
        pos = ((imgsrc.indexOf('.'))-1);
        position = imgsrc.charAt(pos);
        prec = position-1;
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/.png/, "-ok.png");
            element.attr(attribut, imgsrcON);
            if ((position > 0) && (position < nb_items_menu)) {
            	$("img[id^='chmenu"+position+"']").attr(attribut, 'images/fr/menu/'+position+'b.png');
            }
            if ((position > 1) && (position <= nb_items_menu)) {
            	$("img[id^='chmenu"+prec+"']").attr(attribut, 'images/fr/menu/'+prec+'c.png');
            }
        }
	});
	
	$("#menu_modulo>ul>li>div").mouseout(function () {
        if (typeof($(this).children().attr('href'))!="undefined") element = $(this).children().children("img");
		else element = $(this).children("img");
		imgsrc = element.attr(attribut);
		pos = ((imgsrc.indexOf('.'))-4);
        position = imgsrc.charAt(pos);
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            element.attr(attribut, imgsrcON);
            $("img[id^='chmenu"+position+"']").attr(attribut, 'images/fr/menu/'+position+'a.png');
            if ((position > 1) && (position <= nb_items_menu)) {
            	$("img[id^='chmenu"+prec+"']").attr(attribut, 'images/fr/menu/'+prec+'a.png');
            }
        }
	});
	
});


