
//照片加载尺寸处理
var setPhotoSize = function(oImg,iWidth,iHeight,bHMargin,bVMargin)
{
	if(!iWidth)
		return;
	if(!iHeight)
		iHeight = iWidth;
		
	var e = oImg;
	if(e.tagName != "IMG")
		return;
		
	var f = iWidth / iHeight;
	var f2 = e.width / e.height
	if(f2 > f)
	{
		if(e.width > iWidth)
			e.width = iWidth;
		e.height = e.width/f2;
	}
	else
	{
		if(e.height > iHeight)
			e.height = iHeight;
		e.width = e.height*f2;
	}
	
	if(bHMargin&&bVMargin)
		e.style.margin = Math.floor((iHeight - e.height)/2) + "px " + Math.floor((iWidth - e.width)/2) +"px";
	else
	{
		if(bHMargin)
			e.style.margin = "0px "+ Math.floor((iWidth - e.width)/2) + "px";
		else
		{
			if(bVMargin)
				e.style.margin = Math.floor((iHeight - e.height)/2) + "px 0px";
		}
	}
}

var setAllPhotoSize = function()
{
	var oImgs = document.getElementsByTagName("img");
	for(var i=0;i< oImgs.length;i++)
	{
		if(oImgs[i].attributes["isphoto"])
		{
			var iWidth = oImgs[i].attributes["photowidth"]?oImgs[i].attributes["photowidth"].value:null;
			var iHeight = oImgs[i].attributes["photoheight"]?oImgs[i].attributes["photoheight"].value:null;
			var bHMargin = oImgs[i].attributes["hmargin"]?oImgs[i].attributes["hmargin"].value=="1":true;
			var bVMargin = oImgs[i].attributes["vmargin"]?oImgs[i].attributes["vmargin"].value=="1":true;
			setPhotoSize(oImgs[i],iWidth,iHeight,bHMargin,bVMargin);
		}
	}
	oImgs = null;
	//限制图片不超过宽度
	for(var i=0;i<LOA.length;i++)
	{
		if(LOA[i].container)
		{
			
			var oImgs = LOA[i].container.getElementsByTagName("img");
			for(var j = 0;j<oImgs.length;j++)
			{
				if(oImgs[j].width>LOA[i].width)
				{
					var iHeight = oImgs[j].height;
					oImgs[j].height = LOA[i].width/(oImgs[j].width/oImgs[j].height);
					oImgs[j].width = LOA[i].width;
				}
			}
			oImgs = null;
		}
	}
}

var LimitObject = function(oCon,iWidth)
{
	this.container = oCon;
	this.width = iWidth
}
var LOA = new Array();
var LimitImgSize = function(oCon,iWidth)
{
	if(oCon&&iWidth>0)
	{
		LOA[LOA.length] = new LimitObject(oCon,iWidth);
	}
}