(function( $ ){
    
    $.fn.sweetappleRollovers = function( options ) {
        
        var defaults = {
            onSuffix    :   '_on',
            offSuffix   :   '_off'
        };
        // Extend our default options with those provided.
        var opts = $.extend(defaults, options);
        
        
        this.each(function(){
            var images = $("img", this);
            _preloadImages( images[0] );
            
        });
        
        //Return makes sure we can chain methods!
        return this.hover(
            function(){
                var imgArr = $(this).find("img");
                var img = imgArr[0];
                img.src = img.src.split(opts.offSuffix, 1) + opts.onSuffix + _getImageExtension(img);

            },function(){
                var imgArr = $(this).find("img");
                var img = imgArr[0];
                img.src = img.src.split(opts.onSuffix, 1) + opts.offSuffix + _getImageExtension(img);
            }
        );


        function _getImageRoot( img ) {
            return img.src.split(opts.offSuffix, 1);
        }
        
        function _preloadImages( img) {
            var imgPathOver = _getImageRoot(img) + opts.onSuffix + _getImageExtension(img);
            $('<img/>')[0].src = imgPathOver; 
        }
        
        
        function _getImageExtension(img){
            var imgPath = img.src;
            var parts = imgPath.split('.');
            var extension = "." + parts[ parts.length - 1 ];
            return extension;
        }
        
        
    }
   
})( jQuery );
