﻿$(function() {

    $(".rollover").each(
        function() {
            var overSrc = "";
            if (this.src.endsWith(".gif"))
                overSrc = this.src.replace(".gif", "-over.gif");
            if (this.src.endsWith(".jpg"))
                overSrc = this.src.replace(".jpg", "-over.jpg");
            if (this.src.endsWith(".png"))
                overSrc = this.src.replace(".png", "-over.png");

            jQuery("<img>").attr("src", overSrc);
        }
    );

    $(".rollover").hover(
        function() {
            if (this.src.search("-over") < 0) {
                var overSrc = "";
                if (this.src.endsWith(".gif"))
                    overSrc = this.src.replace(".gif", "-over.gif");
                if (this.src.endsWith(".jpg"))
                    overSrc = this.src.replace(".jpg", "-over.jpg");
                if (this.src.endsWith(".png"))
                    overSrc = this.src.replace(".png", "-over.png");

                this.src = overSrc;
            }
        },
        function() {
            this.src = this.src.replace("-over", "");
        }
    );

});