﻿/*
scale image to size
xtrung.net@gmail.com 19/08/2009
update on 20/08/2009
*/

    function loadResize() {

        var imageClass = ".img";
        var scaleWidth = 81;
        var scaleHeight = 81;
        resizeImage(imageClass, scaleWidth, scaleHeight);
        imageClass = ".ad img";
        scaleWidth = 230;
        scaleHeight=177;
        resizeImage(imageClass, scaleWidth, scaleHeight);

    }
    function resizeImage(imageClass,scaleWidth,scaleHeight) {
        $(imageClass).each(function() {
            var width = $(this).width();
            var height = $(this).height();
            //Lấy tỉ lệ co giãn của chiều rộng
            var rWidth = width / scaleWidth;
            //Lấy tỉ lệ co giãn của chiều cao
            var rHeight = height / scaleHeight;
            //Tỉ số giữa 2 tỉ lệ
            var r = rWidth > rHeight;
            //Tỉ lệ giữa chiều rộng và chiều cao
            var ratio = width / height;
            if (r) {
                $(this).width(scaleWidth);
                $(this).height(scaleWidth / ratio);
            }
            else {
                $(this).height(scaleHeight);
                $(this).width(scaleHeight * ratio);
            }

        }

        )
    }