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",
	"images/fr/menu/6-ok.png",
	"images/interface/fond-item-ok.png",
	"images/fr/menu-secondaire/louer-un-bien-immobilier-ok.png",
	"images/fr/menu-secondaire/acheter-un-bien-immobilier-ok.png",
	"images/fr/menu-secondaire/vendre-un-bien-immobilier-ok.png",
	"images/fr/menu-secondaire/bouton-retour-liste-ok.png",
	"images/fr/menu-secondaire/bouton-renseignements-ok.png",
	"images/fr/menu-secondaire/bouton-impression-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 = 7;
	var nb_items_menu2 = 10;
	
	$("#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 < 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');
            }
        }
	});
	
	$("#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 <= nb_items_menu)) {
            	$("img[id^='chmenu"+prec+"']").attr(attribut, 'images/fr/menu/'+prec+'a.png');
            }
        }
	});
	
	$("#anim-flash >ul >li[id^='menu'] >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);
        }
	});
	
	$("#anim-flash >ul >li[id^='menu'] >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);
        }
	});
	
	// images menu gauche
	$("img.louer-acheter-vendre").mouseover(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/.png/, "-ok.png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	$("img.louer-acheter-vendre").mouseout(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	// images Fiche Bien
	$("img[class=bt_fiche]").mouseover(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/.png/, "-ok.png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	$("img[class=bt_fiche]").mouseout(function () {
        imgsrc = $(this).attr('src');
        matches = imgsrc.match(/.png/);
        if (matches) {
            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
            $(this).attr('src', imgsrcON);
        }
	});
	
	// images de fond menu de gauche
	$("ul.treeview li ul li").mouseover(function () {
        imgsrc = $(this).attr('style');
        if(imgsrc) {
	        matches = imgsrc.match(/.png/);
	        if (matches) {
	            imgsrcON = imgsrc.replace(/.png/, "-ok.png");
	            $(this).attr('style', imgsrcON);
	        }
        }
	});
	
	$("ul.treeview li ul li").mouseout(function () {
        imgsrc = $(this).attr('style');
        if(imgsrc) {
	        matches = imgsrc.match(/.png/);
	        if (matches) {
	            imgsrcON = imgsrc.replace(/-ok.png/, ".png");
	            $(this).attr('style', 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);
        }
	});
	
	
});


