$.namespace("ui.rollover");

// preload rollover images for smoother effect
$(window).bind('load', function() {
    // check to see if rollovers are needed
    var testClass = $("img").hasClass('.rollover');

    if (testClass == false) {
        // do nothing
        return;
    } else {
        var aPreload = new Array();
        $(".rollover").each(function() {
            oS = $(this).attr("src").replace(/\.(.+)$/i, "_on.$1");
            console.log(oS);
            aPreload.push(oS)
        });

        // create the IMGs to load in the DOM
        var img = document.createElement('img');
        $(img).bind('load', function() {
            if (aPreload[0]) {
                this.src = aPreload.shift();
            }
        }).trigger('load');
    } //end conditional
}); //end bind

ui.rollover = function(config) {

    // validate config
    if (!config || !config.classRef) return;
    $(config.classRef).each(function(i) {
        $(this).bind("mouseenter", function() {

            // assumes no multiple "." in filename
            var fileExt = $(this).attr("src").split(".")[1];

            // e.g. splits out "filename".gif
            var newSrc = $(this).attr("src").split("." + fileExt)[0];

            // concatenate new src e.g. <filename> + "_on" + "." + ".gif"
            $(this).attr("src", newSrc + config.onState + "." + fileExt);

        }); // end bind


        $(this).bind