﻿var RollOver = new Class({
    initialize: function(ext) {
        this.ext = ext;
        this.update();
    },
    
    update: function() {
        var ext = this.ext;
        var images = [];

        $(document.body).getElements('img.rollover').each(function(el) {
            if (el.src.indexOf(ext) != -1) {
                el.removeEvents('mouseenter');
                el.removeEvents('mouseleave');
                el.addEvents({
                    'mouseenter': function() {
                        if (this.src.indexOf('_ov') == -1 && !this.hasClass('active')) this.src = this.src.replace(ext, '_ov' + ext);
                    },
                    'mouseleave': function() {
                        this.src = this.src.replace('_ov' + ext, ext);
                    }
                });
                images[images.length] = el.src.replace(ext, '_ov' + ext);
            }
        });

        new Asset.images(images);
    }
});

window.addEvent('domready', function() {
    new RollOver('.jpg');
    new RollOver('.png');
});
