﻿// JScript 文件

function AutoResizeImage(maxWidth,maxHeight,objImg){
if (typeof(objImg)=='string'){
objImg = $(objImg);
}
var img = new Image();
img.onload = function(){
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
wRatio = wRatio>1?1:wRatio;
hRatio = hRatio>1?1:hRatio;
if (maxWidth ==0 && maxHeight==0){
Ratio = 1;
}else if (maxWidth==0){//
if (hRatio<1) Ratio = hRatio;
}else if (maxHeight==0){
if (wRatio<1) Ratio = wRatio;
}else {
Ratio = (wRatio<=hRatio?wRatio:hRatio);
}
if (Ratio<1){
w = w * Ratio;
h = h * Ratio;
}
objImg.height = h;
objImg.width = w;
this.onload = function(){}
}
img.src = objImg.src;
}

function getInfo(o){//取得坐标
            var to=new Object();
            to.left=to.right=to.top=to.bottom=0;
            var twidth=o.offsetWidth;
            var theight=o.offsetHeight;
            while(o!=document.body){
                to.left+=o.offsetLeft;
                to.top+=o.offsetTop;
                o=o.offsetParent;
            }
            to.right=to.left+twidth;
            to.bottom=to.top+theight;
            return to;
        }
