var Image = {};

Image.Resize = function(image, width, height)
{
	/// <summary>根据指定宽度和高度按比例缩放图片, 在图片的onload事件中调用此方法</summary>	
	/// <param name="image" type="Image" mayBeNull="false">要缩放的图片</param>
	/// <param name="width" type="Integer">允许的最大宽度</param>
	/// <param name="height" type="Integer">允许的最大高度</param>
	
	image.removeAttribute('width');
	image.removeAttribute('height');
	
	var w = image.width, h = image.height;
	var scaling = w / h;
	
	if(width != null)
	{	
		w = image.width;
		if(w > width)
		{
			image.width = width;
			image.height = width / scaling;
			//h * width / w;
		}
	}
	
	if(height != null)
	{	
		h = image.height;
		if(h > height)
		{
			//w * height / h;
			image.width = height * scaling;			
			image.height = height;
		}
	}
}
Image.Resize = function(image, width, height,debug)
{
	/// <summary>根据指定宽度和高度按比例缩放图片, 在图片的onload事件中调用此方法</summary>	
	/// <param name="image" type="Image" mayBeNull="false">要缩放的图片</param>
	/// <param name="width" type="Integer">允许的最大宽度</param>
	/// <param name="height" type="Integer">允许的最大高度</param>
	if(debug == 1)
	{
	    debugger;
	}
	
	image.removeAttribute('width');
	image.removeAttribute('height');
	
	var w = image.width, h = image.height;
	var scaling = w / h;
	
	if(width != null)
	{	
		w = image.width;
		if(w > width)
		{
			image.width = width;
			image.height = width / scaling;
			//h * width / w;
		}
	}
	
	if(height != null)
	{	
		h = image.height;
		if(h > height)
		{
			//w * height / h;
			image.width = height * scaling;			
			image.height = height;
		}
	}
}

Image.Resize1=function(image,width,height)
{
    if(width==null||height==null)
    return;
    image.removeAttribute('width');
	image.removeAttribute('height');
	var w = image.width, h = image.height;
	var scalingW=w/width,scalingH=h/height;
	var scaling = w / h;
	if(scalingW>=scalingH)
	{
	image.width=width;
	image.height = width / scaling;
	}
	else
	{
	image.height=height;
	image.width = height*scaling;
	}
}

Image.Resize1=function(image,width,height,d)
{
    if(d==1)
     debugger;
    if(width==null||height==null)
    return;
    image.removeAttribute('width');
	image.removeAttribute('height');
	var w = image.width, h = image.height;
	var scalingW=w/width,scalingH=h/height;
	var scaling = w / h;
	if(scalingW>=scalingH)
	{
	image.width=width;
	image.height = width / scaling;
	}
	else
	{
	image.height=height;
	image.width = height*scaling;
	}
}

function SetMiddle(image, height)
{
	/// <summary>重设图片大小后让图片相对于DIV居中</summary>
	
	if (typeof(image) == 'string') image = document.images[image] || document.getElementById(image);
	var div = image.parentNode;
	
	if(div.nodeName != "DIV")
	{

	    div = div.parentNode;
	}
	if(image.height > 0 && image.height < height)
	{
	   var marginTopVal= (height - image.height) / 2;
		image.style.marginTop =parseInt(marginTopVal)+"px";
		///不加px,在火狐下不支持！
	}
	else
	{
	    image.height = height;
		image.style.marginTop = "0px";
	}


}

function GetPictureThumbnailUrl(url, formatName)
{	
	if (url == null || url == '' || url.lastIndexOf('.') == -1)
	{
		return '';
	}
	else
	{
		var extend = url.substring(url.lastIndexOf('.'));
		url = url.replace(extend, '_' + formatName + extend);
		return url;
	}
}