function setImgMaxWidth(){
	if($("postsList")){
        var w=$("postsList").parentNode.style.width;
        w=w.substring(0,2);
		window.i_w=parseInt(906*w/100)-20;
    }    
	else{
		window.i_w=$("article_main").offsetWidth-20;
        window.i_w=650; 
    }     
}

window.changeW=function(e){
if(!e)
	e=window.event;
	e=e.srcElement||e.target;

	var iw=e.width||e.offsetWidth;
	var ih=e.height||e.offsetHeight;
		
	if(!iw||!ih)
		return;		
	if(iw>i_w){
		var p=e.parentNode;

		if(p.href==undefined){
			var a=document.createElement("a");
			a.href=e.src;
					
			a.target="_blank";
			e.width=i_w-20;

			e.height=parseInt((i_w-20)*ih/iw);
			p.replaceChild(a,e);
			a.appendChild(e);

		}
	}	
}
window.changeIW=function(e){
	var iw=e.width||e.offsetWidth;
	var ih=e.height||e.offsetHeight;
		
	if(!iw||!ih)
		return;		
	if(iw>i_w){
		var p=e.parentNode;
		if(p.href==undefined){
			var a=document.createElement("a");
			a.href=e.src;
					
			a.target="_blank";
			e.width=i_w-20;

			e.height=parseInt((i_w-20)*ih/iw);
			p.replaceChild(a,e);
			a.appendChild(e);

		}
	}	
}
/*修复图片宽度*/
function fixImgs(node){
	if(!window.i_w){
		//window.currentWidthConfig=widthconfig[currentLayoutId];
		setImgMaxWidth();
	}

		var imgs=node.getElementsByTagName("img");
		if(!imgs)
			return;
		
		for(var j=0;j<imgs.length;j++){
            if(imgs[j].width){
               if(parseInt(imgs[j].width)>window.i_w){
                   var m=parseInt(imgs[j].width);
                   
                   imgs[j].width=window.i_w;
                   if(imgs[j].height){
                       var n=parseInt(imgs[j].height);
                       imgs[j].height=parseInt(window.i_w*n/m);
                   }
               }    
            }
            else if(imgs[j].complete){
					changeIW(imgs[j]);
					
			}
			else{

					imgs[j].onload=changeW;
					
			}
		}

}
