/* js/jquery-1.4.2.min.js  js/jquery.ae.image.resize.min.js  js/image.js -----*/


/*四捨五入-------------*/
function round(value,num){
	return parseInt(value * Math.pow(10,num) + 0.5) / Math.pow(10,num);
}

/*imageAutoSize-------------*/
jQuery.fn.imageAutoSize = function(width,height){
	
	
    $(this).each(function(){
      try{
    	
    	/*image.css set  .img_100X65  $(this).css('width','auto'); 
      	$(this).css('height','auto'); 
    	$(this).css('max-width',width + 'px'); 
      	$(this).css('max-height',height + 'px'); 
    	*/
    	$(this).hide();//LEE 先藏起來 算完 再顯示 
    
        
        var image = $(this);
        
        var alumb='true';
        
        //imageAutoSize(width,height);
        //if($(this).attr("alumb")!=undefined && $(this).attr("alumb")=="true"){
        if(alumb=="true"){
        	//index_aboutus新式寫法<img alumb="true">
        	 //$(this).attr("sv", "v.0813a");
        	 var appname = navigator.appName.toLowerCase(); 
        	 
        	 if (this.complete){ //if already loaded  
        		//$(this).attr("hide1x", "on");
        		$(this).hide();//LEE 先藏起來 算完 再顯示
        	        
        		 //$(this).attr("imageStatus", "loaded");
        		 
        		//移除目前設定的影像長寬
         		$(this).removeAttr('width');
         		$(this).removeAttr('height');
         		
         		//取得影像實際的長寬
        		var imgW = $(this).width();
        		var imgH = $(this).height();

        		//計算縮放比例
        		var w=round(width/imgW,2);
        		var h=round(height/imgH,2);
        		
        		var pre=1;
        		if(w>h){
        			pre=h;
        		}else{
        			pre=w;
        		}
        		//有可能小圖 if(pre>1){pre=1;}	

        		//設定目前的縮放比例
        		$(this).width(round(imgW*pre,0));
        		$(this).height(round(imgH*pre,0));			
        		$(this).attr("width", round(imgW*pre,0));       $(this).attr("height", round(imgH*pre,0));
        		
        		// $(this).attr("newWidth", width);        		$(this).attr("newHeight", height);
        		// $(this).attr("oldWidth", imgW);        		    $(this).attr("oldHeight", imgH);
        		// $(this).attr("scale", pre);        		        $(this).attr("scaleW", w);
        		// $(this).attr("scaleH", h);
        		//$(this).attr("show1x", "on");
        		$(this).show();
        	    
             }else{     
            	 var xwidth=width;
            	 var xheight=height;
            	 $(this).aeImageResize({ height: xwidth, width: xheight }); 
            	 
            	 var imgW = $(this).width();
         		 var imgH = $(this).height();         		 
            	 // $(this).attr("imageStatus", "ImageResize");
            	 // $(this).attr("oldWidth", imgW);        		    $(this).attr("oldHeight", imgH);
              }

        	
		}else{
			//舊式寫法
			if(image.width()>width){
	            image.height(width/image.width()*image.height());
	            image.width(width);
	         }
	        if(image.height()>height){
	            image.width(height/image.height()*image.width());
	            image.height(height);
	        }
		}
      }catch(e){
		  //alert(e); //works  setGrid(); //doesn't get called 
	  } 
    });
}  

/*imageAutoSize  for IE6-------------*/

function imageAutoSize(width,height)
{
	
	MAX_WIDTH=width;
	MAX_HEIGHT=height;

	var tImg=new Image();
	tImg.onload=function(){
			if(obj.src.length<1) {obj.width=MAX_WIDTH; obj.height=MAX_HEIGHT; return;}
			var w=this.width;
			var h=this.height;
			if(wh) {
				obj.width=MAX_WIDTH;obj.height=MAX_WIDTH*h/w;
			}
			else{
				obj.height=MAX_HEIGHT;obj.width=MAX_HEIGHT*w/h;
			}
			if(obj.src) obj.style.display='';
	}
	tImg.src=obj.src;
}

/*please image.css set  .img_100X65{	width:auto;	    height:auto; 	max-width:100px;		max-height:65px; 		}*/
$(function(){ $('.img_100X65').imageAutoSize(100,65);});
$(function(){ $('.img_100X100').imageAutoSize(100,100);});
$(function(){ $('.img_150X100').imageAutoSize(150,100);});
$(function(){ $('.img_160X160').imageAutoSize(160,160);});
$(function(){ $('.img_210X110').imageAutoSize(210,110);});
$(function(){ $('.img_250X250').imageAutoSize(250,250);});
$(function(){ $('.img_50X50').imageAutoSize(50,50);});
$(function(){ $('.img_90X60').imageAutoSize(90,60);});
$(function(){ $('.img_120X90').imageAutoSize(120,90);});
$(function(){ $('.img_96X72').imageAutoSize(96,72);});
$(function(){ $('.img_140X140').imageAutoSize(140,140);});
$(function(){ $('.img_360X360').imageAutoSize(360,360);});
$(function(){ $('.img_950X60').imageAutoSize(950,60);});
$(function(){ $('.img_200X200').imageAutoSize(200,200);});
/*
$(function(){ $('.pda_img_260X175').imageAutoSize(260,175);});
$(function(){ $('.pda_img_60X60').imageAutoSize(60,60);});
$(function(){ $('.pda_img_110X82').imageAutoSize(110,82);});
$(function(){ $('.pda_img_157X95').imageAutoSize(157,95);});
$(function(){ $('.search_img_170X73').imageAutoSize(170,73);});
$(function(){ $('.search_img_90X90').imageAutoSize(90,90);});
$(function(){ $('.search_img_110X110').imageAutoSize(110,110);});
*/
