﻿// this requires jquery.
jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

sfHover = function() {
    $.preloadImages(
        "/images/menu/button_products_over.png",
        "/images/menu/button_wheretobuy_over.png",
        "/images/menu/button_support_over.png",
        "/images/menu/button_gallery_over.png",
        "/images/menu/button_educational_program_over.png",
        "/images/menu/button_company_over.png",
        "/images/menu/button_contact_over.png"
    );
    
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");

    for (var i = 0; i < sfEls.length; i++) {
        $(sfEls[i]).mouseenter(function() {
            $(this).addClass('sfhover');
            $(this).find("a.menu_heading > img").each(
                function(e) {
                    if (!this.src.match(/_sel\.png/)) {
                        this.src = this.src.replace(/\.png$/, '_over.png');
                    }
                }
            );
        }).mouseleave(function() {
            $(this).removeClass('sfhover');
            $(this).find("a.menu_heading > img").each(
                function(e) {
                    if (!this.src.match(/_sel\.png/)) {
                        this.src = this.src.replace(/_over\.png$/, '.png')
                    }
                }
            );
        });
    }  
}

if (window.attachEvent) {
    window.attachEvent("onload", sfHover);
} else {
    window.onload = sfHover;
}