﻿$(document).ready(function()
{
    $('.Thumbnails').each(function()
    {
        var t = $(this);
        function resize()
        {
            var maxSize = t.attr("maxsize");
            var maxWidth = maxSize; // 图片最大宽度
            var maxHeight = maxSize; // 图片最大高度
            var ratio = 0; // 缩放比例
            var width = t.width(); // 图片实际宽度
            var height = t.height(); // 图片实际高度
            // 检查图片是否超宽或超高
            if(width > maxWidth || height > maxHeight)
            {
                // 检查图片是横的还是竖的
                if(width > height)
                {
                    t.css("width", maxWidth); // 设定实际显示宽度
                    height = height * maxWidth / width; // 计算等比例缩放后的高度
                    t.css("height", height); // 设定等比例缩放后的高度
                } // 检查图片是否超高
                else
                {
                    t.css("height", maxHeight); // 设定实际显示高度
                    width = width * maxHeight / height; // 计算等比例缩放后的宽度
                    t.css("width", width); // 设定等比例缩放后的宽度
                }
            }
        }
        resize();
        setTimeout(resize, 200);
    });
    
    $('.ThumbFigure11').each(function()
    {
        // maxWidth图片最大宽度
        var maxWidth = 300;
        // maxHeight图片最大高度
        var maxHeight = 225;
        
        var oldImage = new Image();
        oldImage.src = $(this).attr("src");
        
        var ratio = 0; // 缩放比例
        var width = $(this).width(); // 图片实际宽度
        var height = $(this).height(); // 图片实际高度
        // 检查图片是否超宽
        if (width > maxWidth)
        {
            $(this).css("width", maxWidth);
        }
        else
        {
            $(this).css("width", oldImage.width);
        }
        //var newWidth = $(this).width();
        var newHeight = $(this).height();
        if (newHeight > maxHeight)
        {
            $(this).css("height", maxHeight);
            var newWidth = width * maxHeight / height;
            $(this).css("width", newWidth);
        }
    });
});

function ResizeImg(obj, maxWidth, maxHeight)
{
    // maxWidth图片最大宽度
    // maxHeight图片最大高度
    var width = $(obj).width(); // 图片实际宽度
    var height = $(obj).height(); // 图片实际高度
    // 检查图片是否超宽或超高
    if(width > maxWidth || height > maxHeight)
    {
        // 检查图片是横的还是竖的
        if(width > height)
        {
            $(this).css("width", maxWidth); // 设定实际显示宽度
            height = height * maxWidth / width; // 计算等比例缩放后的高度
            $(this).css("height", height); // 设定等比例缩放后的高度
        } // 检查图片是否超高
        else
        {
            $(this).css("height", maxHeight); // 设定实际显示高度
            width = width * maxHeight / height; // 计算等比例缩放后的宽度
            $(this).css("width", width); // 设定等比例缩放后的宽度
        }
    }
}

var imageObject;
function ResizeImage2(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state = imageObject.readyState;
    if (state != 'complete')
    {
        setTimeout("ResizeImage2(null," + MaxW + "," + MaxH + ")", 50);
        return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW = oldImage.width;
    var dH = oldImage.height;
    if (dW > MaxW || dH > MaxH)
    {
        a = dW / MaxW;
        b = dH / MaxH;
        if (b > a) a = b;
        dW = dW / a;
        dH = dH / a;
    }
    if (dW > 0 && dH > 0)
    {
        imageObject.width = dW;
        imageObject.height = dH;
    }
    var dtop = MaxH / 2 - dH;
}

var flag = false;
function DrawImage(ImgD, MaxW, MaxH)
{
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0)
    {
        flag = true;
        if (image.width / image.height >= MaxW / MaxH)
        {
            if (image.width > MaxW)
            {
                ImgD.width = MaxW;
                ImgD.height = (image.height * MaxH) / image.width;
            } else
            {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            /*ImgD.alt="bigpic"  */
        }
        else
        {
            if (image.height > MaxH)
            {
                ImgD.height = MaxH;
                ImgD.width = (image.width * MaxH) / image.height;
            } else
            {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            /*ImgD.alt="bigpic"  */
        }
    }
}