﻿
function img_auto_size(oldimg,maxSize,openNewWindow){
	var newimg = new Image();
	newimg.src = oldimg.src;
	if (newimg.width > 0 && newimg.height > 0) {
		if (newimg.width > maxSize){ 
			oldimg.width = maxSize;
			oldimg.height = (newimg.height * maxSize) / newimg.width;
			
			oldimg.onmouseover = function() {
				this.style.cursor= "hand";
			};
			oldimg.onmouseout = function() {
				this.style.cursor="";
			};
			if(openNewWindow){
				oldimg.onclick = function() {
					window.open(this.src, '_blank');
				};
				oldimg.alt = "点击查看原始大小 " + newimg.width + " x " + newimg.height;
			}
			
		} else {
			oldimg.width = newimg.width; 
			oldimg.height = newimg.height;
			
		}
		
	}
} 

function img_auto_size_z(oldimg,maxSize,openNewWindow){
	var newimg = new Image();
	newimg.src = oldimg.src;
	if (newimg.width > 0 && newimg.height > 0) {
		if (newimg.width > maxSize){ 
			oldimg.width = maxSize;
			oldimg.height = (newimg.height * maxSize) / newimg.width;
			
			oldimg.onmouseover = function() {
				this.style.cursor= "pointer";
			};
			oldimg.onmouseout = function() {
				this.style.cursor="";
			};
			if(openNewWindow){
				oldimg.onclick = function() {
					window.open(this.src, '_blank');
				};
				oldimg.alt = "点击查看原始大小 " + newimg.width + " x " + newimg.height;
			}
			if(oldimg.height>135){
				oldimg.height = 135;
			oldimg.width = (newimg.width * 135) / newimg.height;
				}
		} else  if(oldimg.height>135){
				oldimg.height = 135;
			oldimg.width = (newimg.width * 135) / newimg.height;
			
				}else{
			oldimg.width = newimg.width; 
			oldimg.height = newimg.height;
			
		
		}
		
	}oldimg.style.cssText  ="position:absolute;top:50%;left:50%;margin-top:-"+oldimg.height/2+"px;"+"margin-left:-"+oldimg.width/2+"px;"
} 
