
/*
* aulo load lazyed images,
* the id attribute of lazyed img element must meet the format 'lazyimg_imgid_uniquemark'  , ex: <img id='lazyimg_26_abcd1234' src='...defaut.jpg' />
* param urlPrefix: if uploaded file,use <c:url value='/extend/' /> ,the target url use urlPrefix+imgid
*/
function lazyLoadImages(urlPrefix) {
	var prefix = "lazyimg";
	var elements = document.getElementsByTagName("img");
	for (i = 0; i < elements.length; i++) {
		mmid = elements[i].id;
		if (mmid.indexOf(prefix) > -1) {
			fi = mmid.indexOf("_");
			si = mmid.indexOf("_", fi + 1);
			if (fi > -1 && si > fi) {
				photoId = mmid.substring(fi + 1, si);
				imgUrl = urlPrefix + photoId + '.png';
				ajaxLoadImage(elements[i], imgUrl);
			}
		}
	}
}

/*
* ajax Load imgElement element with imgUrl
*/
function ajaxLoadImage(imgElement, imgUrl) {
	//imgUrl="/houmoo-portal/images/403.jpg";
	//tmpImage=new Asset.image(imgUrl, {onload:changeImageSrc(imgElement,imgUrl)});
	//tmpImage=new Asset.image(imgUrl, {});
	//imgElement.src=tmpImage.src;
	imgElement.src=imgUrl;
}

function changeImageSrc(imgElement,imgUrl){
	imgElement.src=imgUrl;
}

function AutoResizeImage(maxWidth,maxHeight,objImg){
var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
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 if (wRatio<1 || hRatio<1){
Ratio = (wRatio<=hRatio?wRatio:hRatio);
}
if (Ratio<1){
w = w * Ratio;
h = h * Ratio;
}
objImg.height = h;
objImg.width = w;
}



