jQuery(function($) {
    $(document).ready(function(){
        // WORK PAGE
        $("#content ul.workcat>li>img").each(function () {
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/gi, "_o.gif");
            $("<img>").attr("src", rollON);
        });

        $("#content ul.workcat>li>a").mouseover(function () {
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_o/);
            if (!matches) {
                imgsrcON = imgsrc.replace(/.gif$/gi, "_o.gif");
                $(this).children("img").attr("src", imgsrcON);
            }
        });

        $("#content ul.workcat>li>a").mouseout(function () {
            $(this).children("img").attr("src", imgsrc);
        });

        // FRIENDS PAGE
        $("#content a.roll>img").each(function () {
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.png$/gi, "_o.png");
            $("<img>").attr("src", rollON);
        });

        $("#content p>a.roll").mouseover(function () {
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_o/);
            if (!matches) {
                imgsrcON = imgsrc.replace(/.png$/gi, "_o.png");
                $(this).children("img").attr("src", imgsrcON);
            }
        });

        $("#content p>a.roll").mouseout(function () {
            $(this).children("img").attr("src", imgsrc);
        });
        
        // HOMEPAGE
        $("div.homepage p>a>roll>img").each(function () {
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/gi, "_o.gif");
            $("<img>").attr("src", rollON);
        });

        $("div.homepage p>a").mouseover(function () {
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_o/);
            if (!matches) {
                imgsrcON = imgsrc.replace(/.gif$/gi, "_o.gif");
                $(this).children("img").attr("src", imgsrcON);
            }
        });

        $("div.homepage p>a").mouseout(function () {
            $(this).children("img").attr("src", imgsrc);
        });
        
        // SIDEBAR LOGO
        $("#logo img").each(function () {
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/gi, "_o.gif");
            $("<img>").attr("src", rollON);
        });

        $("#logo a").mouseover(function () {
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_o/);
            if (!matches) {
                imgsrcON = imgsrc.replace(/.gif$/gi, "_o.gif");
                $(this).children("img").attr("src", imgsrcON);
            }
        });

        $("#logo a").mouseout(function () {
            $(this).children("img").attr("src", imgsrc);
        });
    });
});
