function imgFix() { 
var widthRestriction = 122; 
var heightRestriction = 84; 
var imgbox = document.getElementById('img');
var allElements = imgbox.getElementsByTagName('*') ;
for (var i = 0; i < allElements.length; i++){ 
if (allElements[i].className.indexOf('img') >= 0) 
{ 
var imgElements = allElements[i].getElementsByTagName('img'); 
for (var j=0; j < imgElements.length; j++) 
{ 
if ( imgElements[j].width > widthRestriction || imgElements[j].height > heightRestriction ) 
{ 
if ( imgElements[j].width > imgElements[j].height) 
{ 
imgElements[j].height = imgElements[j].height*(widthRestriction/imgElements[j].width); 
imgElements[j].width = widthRestriction; 
} else 
{ 
imgElements[j].width = imgElements[j].width*(heightRestriction/imgElements[j].height); 
imgElements[j].height = heightRestriction; 
} 
} 
if ( imgElements[j].height < heightRestriction ) 
{ 
imgElements[j].style.paddingTop = ( heightRestriction -imgElements[j].height ) /2 + "px"; 
} 
}
} 
}
} 
window.onload = imgFix; 
