/**
 * Simple rollover
 * 
 * Copyright (c) 2009 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

$(function() {
    var targetElem = $('.roll');

    $('.roll').each(function() {
        this.originalSrc = $(this).attr('src');
        this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)(\?\d+)?$/, '_on'+"$1");
        this.rolloverImg = new Image();
        this.rolloverImg.src = this.rolloverSrc;
    });

    if ($('.roll').parent('button').length) targetElem = $('.roll').parent('button');

    targetElem.hover(function() {
        var elem = $(this).attr('src') ? $(this) : $('img', this);
        elem.attr('src', elem.get(0).rolloverSrc);
    }, function() {
        var elem = $(this).attr('src') ? $(this) : $('img', this);
        elem.attr('src', elem.get(0).originalSrc);
    });
});

