
function init()
{
    RsizeAllImageById("imgProductItem", 114, 96);
}

function init1()
{
    RsizeAllImageById("imgProductItem1", 139, 113);
}

function init2()
{
    RsizeAllImageById("imgProductItem2", 129, 47);
}
function init3() {
    RsizeAllImageById("imgp1", 163, 186);
}
function init4() {
    RsizeAllImageById("imgp2", 169, 193);
}
function init5() {
    RsizeAllImageById("imgp5", 200, 215);
}

function init6() {
    RsizeAllImageById("imgp6", 210, 210);
}

function init7() {
    RsizeAllImageById("imgp7", 150, 150);
}

function init8() {
    RsizeAllImageById("bigimg", 353, 380);
}
function init9() {
    RsizeAllImageById("imgp9", 100, 100);
}
//将imageDest图片的大小按比例缩放,适合显示在宽W和高H的区域内
function ResizeImage(imageDest, W, H) {
    //显示框宽度W,高度H 
    var image = new Image();
    image.src = imageDest.src;
    if (image.width > 0 && image.height > 0) {
        //比较纵横比
        if (image.width / image.height >= W / H)//相对显示框：宽>高
        {
            if (image.width > W) //宽度大于显示框宽度W，应压缩高度
            {
                imageDest.width = W;
                imageDest.height = (image.height * W) / image.width;
            }
            else //宽度少于或等于显示框宽度W，图片完全显示
            {
                imageDest.width = image.width;
                imageDest.height = image.height;
            }
        }
        else//同理
        {
            if (image.height > H) {
                imageDest.height = H;
                imageDest.width = (image.width * H) / image.height;
            }
            else {
                imageDest.width = image.width;
                imageDest.height = image.height;
            }
        }
        imageDest.style.marginTop = (H - imageDest.height) / 2 + "px";
    }
}
//将页面内所有指定id的图片按比例缩放
function RsizeAllImageById(id, W, H)
{
var imgs = document.getElementsByTagName("img");
for(var i=0; i<imgs.length; i++)
{
   if(imgs[i].id == id)
   {
    ResizeImage(imgs[i], W, H);
   }
}
}

