// Javascript to scale or crop image

// Pass in the image, and desired width and height
function boposts_adjustImage(img, desWidth, desHeight) {

    img =  $(img);

    // Set the style on the wrapper div
    img.parent().parent().css({
        'height': desHeight+'px',
        'width': desWidth+'px',        
    });

    img.hide();
    
    var height = img.height();
    var width = img.width();

    // If either of them is 0 then we do nothing
    if (desWidth == 0 || desHeight == 0) {
        return;
    }
    
    // If both the height and width are bigger, than we are going to scale
    if (width > desWidth && height > desHeight) {
        if (height > width) {
            var css = {'height': desHeight+"px"};
        } else {
            var css = {'width': desWidth+"px"};
        }
        img.css(css);        
    }

    // If the width is bigger and height smaller, than we want to adjust the wrapper height
    if (width >= desWidth && height <= desHeight) {
        // We want to adjust the height of the wrapper to save space
        img.parent().parent().css({
            'height': height+'px',
        });
    }

    // If they are both smaller, than we leave it

    // Show the image
    img.show();
}
