if(window.addEventListener) window.addEventListener("load", startResize, false);
else if(window.attachEvent) window.attachEvent("onload", startResize);

function startResize()
{
	var mainBlock=document.getElementById('main_block');
	
	resizeElements(mainBlock);
}

function resizeElements(startId)
{
	if(startId.nodeType==1)
	{
		// resize
		if((startId.tagName=="IMG")||
		   (startId.tagName=="IFRAME")||
		   (startId.tagName=="OBJECT")||
		   (startId.tagName=="EMBED")
		   )
		{
			if(startId.offsetWidth)
			{
				var width=startId.offsetWidth;
				var height=startId.offsetHeight;
				
				var i_w = width/400;
				var i_h = height/500;
				
				if(i_w > i_h)
				{
					index = i_w;
				}
				else if(i_w < i_h)
				{
					index = i_h;
				}
				else
				{
					index = i_w;
				}

				w_f = Math.floor(width/index);
				h_f = Math.floor(height/index);
				
				if((width>400)||(height>500))
				{
					startId.style.width=w_f+'px';
					startId.style.height=h_f+'px';
				}
			}
		}
		
		var children=startId.childNodes;
		for(var i=0; i<children.length; i++)
		{
			resizeElements(children[i]);
		}
	}
	
}
