//An alternative function. Note: for dynamic resizing, attach to the window resize event 
function setMaxWidth(elementId, width){ 
  var container = document.getElementById(elementId); 
  container.style.width = (container.clientWidth > (width - 1)) ? width + "px" : "auto"; 
} 
//Example usage 
setMaxWidth('li.active img', 50); 
