var ImgResize = {
	Sections: ['imageSection1', 'imageSection2', 'imageSection3'],
	getStyle: function(Element, Property) {
		if (!document.getElementById(Element)) return;
		return document.getElementById(Element).style[Property.toLowerCase()];
	},
	//method
	ResizeAction: function() {
		for (var i=0; i<this.Sections.length; i++) {
			var SectionObj = this.Sections[i];
			if (!document.getElementById(this.Sections[i])) continue;			
			var WidthLimit = (SectionObj.WidthLimit) ? SectionObj.WidthLimit : (this.getStyle(SectionObj.Section, 'width')) ? parseInt(this.getStyle(SectionObj.Section, 'width'), 10) : document.getElementById(this.Sections[i]).offsetWidth;
			if (document.getElementById("content")!=null ){WidthLimit=document.getElementById("content").offsetWidth;} 
			
            this.WidthSet = WidthLimit*0.9; //抓出寬度後，顯示90%的圖片大小
			
			var GetSection = document.getElementById(this.Sections[i]);			
			var GetOImg = GetSection.getElementsByTagName('img');
			for (var j=0; j<GetOImg.length; j++) {
				var SizeArray = [GetOImg[j].width, GetOImg[j].height];
				//alert(SizeArray);
				if (SizeArray[0] > this.WidthSet) {
					GetOImg[j].style.width = this.WidthSet + 'px';
					GetOImg[j].style.height = Math.floor((this.WidthSet*SizeArray[1])/SizeArray[0]) + 'px';
				}//end if
			}//end for
		}//end for
	}
};

/* 固定寬度版
var ImgResizenew = {
	Sections: ['imageSection1', 'imageSection2', 'imageSection3'],
	WidthSet: 500,
	//method
	ResizeAction: function() {
		for (var i=0; i<this.Sections.length; i++) {
			if (!document.getElementById(this.Sections[i])) continue;
			var GetSection = document.getElementById(this.Sections[i]);
			var GetOImg = GetSection.getElementsByTagName('img');
			for (var j=0; j<GetOImg.length; j++) {
				var SizeArray = [GetOImg[j].width, GetOImg[j].height];
				//alert(SizeArray);
				if (SizeArray[0] > this.WidthSet) {
					GetOImg[j].style.width = this.WidthSet + 'px';
					GetOImg[j].style.height = Math.floor((this.WidthSet*SizeArray[1])/SizeArray[0]) + 'px';
				}//end if
			}//end for
		}//end for
	}
};
*/

var flag=false;
function DrawImage(ImgD){
    var image=new Image();
    var iwidth = 45;  //定義允許圖片寬度
    var iheight = 80;  //定義允許圖片高度
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
} 
function DrawImage_90(ImgD){
    var image=new Image();
    var iwidth = 90;  //定義允許圖片寬度
    var iheight = 150;  //定義允許圖片高度
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
} 
function DrawImage_190(ImgD){
    var image=new Image();
    var iwidth = 190;  //定義允許圖片寬度
    var iheight = 190;  //定義允許圖片高度
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
} 
/*  第二版
var ImgResize = {
	SectionInfo: [{SectionID:'imageSection1', WidthLimit:45}, {SectionID:'imageSection2', WidthLimit:45}, {SectionID:'imageSection3', WidthLimit:45}, {SectionID:'imageSection4', WidthLimit:500}],
	//method
	ResizeAction: function() {
		for (var i=0; i<this.SectionInfo.length; i++) {
			var SectionObj = this.SectionInfo[i];
			var WidthLimit = SectionObj.WidthLimit;
			if (!document.getElementById(SectionObj.SectionID)) continue;
			var GetSection = document.getElementById(SectionObj.SectionID);
			var GetOImg = GetSection.getElementsByTagName('img');
			for (var j=0; j<GetOImg.length; j++) {
				var SizeArray = [GetOImg[j].width, GetOImg[j].height];
				if (SizeArray[0] > WidthLimit && GetOImg[j].className.indexOf('ResizeObj') != -1) {
					GetOImg[j].style.width = WidthLimit + 'px';
					GetOImg[j].style.height = Math.floor((WidthLimit*SizeArray[1])/SizeArray[0]) + 'px';
				}//end if
			}//end for
		}//end for
	}
};
*/