﻿function resizeImg(el) {
    function imgRatio() {
        return (el.height / el.width);
    }
    function holderRatio() {
        return (el.parentNode.parentNode.offsetHeight / el.parentNode.parentNode.offsetWidth);
    }
    function fitToContainer() {
        if (imgRatio > holderRatio) {
            el.height = el.parentNode.parentNode.offsetHeight;
            if (el.width < el.parentNode.parentNode.offsetWidth) {
                var ratio = el.height / el.width;
                el.width = el.parentNode.parentNode.offsetWidth;
                el.height = el.height = el.parentNode.parentNode.offsetHeight * ratio;
            }
        }
        else {
            el.width = el.parentNode.parentNode.offsetWidth;
        }
    }

    this.imgRatio = imgRatio;
    this.holderRatio = holderRatio;
    this.resize = fitToContainer;
}
