// JavaScript Document
function _id(id){return (typeof(id)=='object'?id:document.getElementById(id))}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {  
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function doImgSize(img,m){
	var iw=img.width;
	var ih=img.height;
	var cup=m.parentNode.parentNode;
	var ttw = window.getComputedStyle?window.getComputedStyle(cup,null).width:cup.currentStyle["width"];
	var tth = window.getComputedStyle?window.getComputedStyle(cup,null).height:cup.currentStyle["height"];
	var tw=parseInt(ttw)-5;
	var th=parseInt(tth)-5;
	var mw,mh;
	if(ih<th&&iw<tw){
		m.width=mw=iw;
		m.height=mh=ih;
		m.style.marginTop=((th-mh)/2)+"px"; 
	}else if(iw>tw&&ih>th){ 
			if(ih>=iw){
				var nh=th-2; 
				m.height=mh=nh; 
				m.width=mw=(nh*iw)/ih; 
			}else if(ih<=iw){
				var nw=tw-2;
				m.width=mw=nw;
				m.height=mh=Math.floor((nw*ih)/iw);
			}
	}else if(ih>th){
		var nh=th-2; 
		m.height=mh=nh; 
		m.width=mh=(nh*iw)/ih; 
	}else if(iw>tw){ 
		var nw=tw-2; 
		m.width=mw=nw; 
		m.height=mh=(nw*ih)/iw;
	}
	if(true){m.style.marginTop=((th-m.height)/2)+"px";}
}
