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/1b.png",
	"images/fr/menu/1c.png",
	"images/fr/menu/2-ok.png",
	"images/fr/menu/2b.png",
	"images/fr/menu/2c.png",
	"images/fr/menu/3-ok.png",
	"images/fr/menu/3b.png",
	"images/fr/menu/3c.png",
	"images/fr/menu/4-ok.png",
	"images/fr/menu/4b.png",
	"images/fr/menu/4c.png",
	"images/fr/menu/5-ok.png",
	"images/fr/menu/5b.png",
	"images/fr/menu/5c.png",
	"images/fr/menu/6-ok.png",
	"images/fr/menu/6b.png",
	"images/fr/interface/valider-ok.png",
	"images/fr/menubas/accueil-ok.png",
	"images/fr/menubas/ajouter-aux-favoris-ok.png",
	"images/fr/menubas/plan-du-site-ok.png",
	"images/fr/menubas/haut-de-page-ok.png",
	"images/fr/menubas/mentions-legales-ok.png",
	"images/fr/menubas/liens-ok.png",
	"images/fr/menubas/partenaires-ok.png",
	"images/fr/menubas/contact-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"
	}
	
	$("#sample-menu-5 >li[id^='roll'] >a").mouseover(function () {
        imgsrc = $(this).children("img").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");
            $(this).children("img").attr(attribut, imgsrcON);
            if ((position > 0) && (position < 6)) {
            	$("img[id^='chmenu"+position+"']").attr(attribut, 'images/fr/menu/'+position+'b.png');
            }
            if ((position > 1) && (position < 7)) {
            	$("img[id^='chmenu"+prec+"']").attr(attribut, 'images/fr/menu/'+prec+'c.png');
            }
        }
	});
	
	$("#sample-menu-5 >li[id^='roll'] >a").mouseout(function () {
        imgsrc = $(this).children("img").attr(attribut);
        pos = ((imgsrc.indexOf('.'))-4);
        position = imgsrc.charAt(pos);
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            $(this).children("img").attr(attribut, imgsrcON);
            $("img[id^='chmenu"+position+"']").attr(attribut, 'images/fr/menu/'+position+'a.png');
            if ((position > 1) && (position < 7)) {
            	$("img[id^='chmenu"+prec+"']").attr(attribut, 'images/fr/menu/'+prec+'a.png');
            }
        }
	});
	
	$("#menu-bas >li >a").mouseover(function () {
        imgsrc = $(this).children("img").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");
            $(this).children("img").attr(attribut, imgsrcON);
        }
	});
	
	$("#menu-bas >li >a").mouseout(function () {
        imgsrc = $(this).children("img").attr(attribut);
        pos = ((imgsrc.indexOf('.'))-4);
        position = imgsrc.charAt(pos);
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            $(this).children("img").attr(attribut, imgsrcON);
        }
	});
	
	// bouton valider formulaire de contact
	$("div >input[id^='valider']").mouseover(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/.png/, "-ok.png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	$("div >input[id^='valider']").mouseout(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	
});


