/**
 * crossfade - jQuery plugin 
 *
 * Copyright (c) 2009 Attrise.Inc.
 *  http://attrise.com
 *
 * Dual licensed under the MIT and GPL licenses:
 *  http://www.opensource.org/licenses/mit-license.php
 *  http://www.gnu.org/licenses/gpl.html
 *
 * $Id: $
 */
(function($){
    jQuery.fn.crossfade = function(options) {
        // default setting sufix
        var defaults = {
            switchTarget : "#switcher img",
            fadeImage : "fadeimage",
            fadeImagePath : "share/images/",
            fadeImageWidth : 100,
            fadeImageHeight : 100,
            fadeImageMimeType : "jpg"
        };
        settings = jQuery.extend({}, defaults, options);
        
        this.each(function(i){
            var $this = jQuery(this);
            $this.hover(
                function(){
                    var src   = $this.attr("src"),
                        href  = $this.parent().attr("href"),
                        param = src.match(/([0-9]+)\_.*?.(png|jpg|gif)$/);
                       
                    $this.clone().
                        css('display', 'none').
                        attr('src',  settings.fadeImagePath + settings.fadeImage + '_' + param[1] + '.' + settings.fadeImageMimeType).
                        attr('width', settings.fadeImageWidth).
                        attr('height', settings.fadeImageHeight).
                        appendTo($(settings.switchTarget)).
                        fadeIn().
                        wrap('<a href="' + href + '"></a>');
                        
                    $(settings.switchTarget + ' a:first').remove();
                }
            );
        });
        return this;
    }
})(jQuery);