/* 
 *  (c) 2009 Prosoma Informatica
 */


$(function() {
    $('.thumb').wrap('<div class="thumbnail"></div>').load(function() {

        var img = $(this);
        var parent = img.parent();
        var width = img.width();
        var height = img.height();

        if(width > height) {
            if(height > parent.height()) {
                img.height(parent.height());
                width = img.width()
                if(width > parent.width()) {
                    img.css('position','absolute').css('left', '-' + ( width / 2 ) + 'px' ).css('margin-left', '50%');
                }
            }
        }
        else {
            if(width > parent.width()) {
                img.width(parent.width());
                height = img.height();
                if(height > parent.height()) {
                    img.css('position','absolute').css('top', '-' + ( height / 2 ) + 'px' ).css('margin-top', '50%');
                }
                
            }
        }

    });
});