var Thumbnail = new Class( {
    _resizeImage: function() {
        if ( this.img.width >= this.img.height ) {
            w = this.maxsize;
            h = this.maxsize * this.img.height / this.img.width;
        } else {
            h = this.maxsize;
            w = this.maxsize * this.img.width / this.img.height;
        }

        if (!window.gecko) {
            this.element.width = w;
            this.element.height = h;
        }

        if(this.element.src != this.img.src){
            this.element.src = this.img.src;
        }

        if(this.callback){
            this.callback({ element: this.element, width: w, height: h, src: this.img.src });
        }

        this.element.setStyle( "display", "" );
        this.img = null;
    },

    initialize: function( _id, _url, _maxsize, _callback ) {
        this.element	= $(_id);

        if(window.gecko){
            this.element.setStyle("max-width", _maxsize + "px");
            this.element.setStyle("max-height", _maxsize + "px");
        }

        this.callback = _callback;
        this.maxsize	= _maxsize;
        this.img		= new Image();

        if(Thumbnail.errorImage){
            this.img.onerror = (function(){
                if(this.img.src != Thumbnail.errorImage){
                    this.img.src = Thumbnail.errorImage;
                }
            }).bindAsEventListener(this);
        }

        this.img.onload	= this._resizeImage.bindAsEventListener( this );
        this.img.src = (_url? _url: this.element.src);
    }
} );
