var timefade = 5000;

function nobei_loaderimages(nameclass, children) {
    var typesearch = "img";
    var timefade = 0;
    if (nameclass != "" && nameclass != undefined) {
        typesearch = nameclass;
    }
    if (children == true && nameclass != undefined) {
        $("img", typesearch).each(replace_withloader);
    } else {
        $(typesearch).each(replace_withloader);
    }
}
function nobei_rollover() {
    for (i = 0; i < document.images.length; i++) {
        if (document.images[i].src.indexOf("_off.") > 0) {
            document.images[i].onmouseover = roll_on;
            document.images[i].onmouseout = roll_off;
        }
    }
}
function roll_on() {
    this.src = this.src.replace(/_off/, "_on");
}
function roll_off() {
    this.src = this.src.replace(/_on/, "_off");
}
function replace_withloader(index) {
    var heightimg = $(this).attr("height");
    var widthimg = $(this).attr("width");
    var srcimg = $(this).attr("src");
    var classimg = $(this).attr("class");
    var idimg = $(this).attr("id");
    var styleimg = $(this).attr("style");
    if (srcimg.indexOf("_off.") == -1) {
        $(this).replaceWith('<div id="loadreplace' + index + '" class="future_loader" style="height:' + heightimg + "px; width:" + widthimg + 'px;"></div>');
        var img = new Image();
        $(img).load(function () {
            $(this).hide();
            $(this).attr("height", heightimg);
            $(this).attr("width", widthimg);
            if (classimg != "") {
                $(this).attr("class", classimg);
            }
            if (idimg != "") {
                $(this).attr("id", idimg);
            }
            $("#loadreplace" + index).replaceWith(this);
            $(this).fadeIn(timefade, function () {
                $(this).removeAttr("style");
                $(this).attr("style", styleimg);
            });
        }).error(function () {}).attr("src", srcimg);
    }
}
