Type.registerNamespace('MySpace.ProfileDisplay');

MySpace.ProfileDisplay.resizeObjects = function(rootNode) {
	var objects =  _proxy_jslib_handle(rootNode, 'getElementsByTagName', '', 1, 0)("OBJECT");

	if (objects.length > 0){
		for (var i=0; i<objects.length; i++){
		
			var elem =  _proxy_jslib_handle(objects, (i), 0, 0).parentNode;
			if (elem.clientWidth < 1) continue;
			var newWidth = elem.clientWidth;	
			var k = 1;		
									
			while ((elem && elem.className && elem.className.indexOf('autoResize') === -1) && (k < 10)){				
				elem = elem.parentNode;
				newWidth = elem.clientWidth;	
				k++;
			}

			if (oldHeight === 0) continue;
			
			var oldHeight =  _proxy_jslib_handle(objects, (i), 0, 0).height;
			var oldWidth =  _proxy_jslib_handle(objects, (i), 0, 0).width;
		
			// set original height/width ratio once
			if ((! _proxy_jslib_handle(objects, (i), 0, 0)._ratio)&&(! _proxy_jslib_handle(objects, (i), 0, 0)._origWidth)){	
				if ((oldHeight !== 0) && (oldWidth !== 0)){
						 _proxy_jslib_handle(objects, (i), 0, 0)._ratio = (MySpace.ProfileDisplay.validPercent(oldWidth)) ? ((newWidth * (parseInt(oldWidth) / 100)) / oldHeight) : (oldWidth / oldHeight);
						 _proxy_jslib_handle(objects, (i), 0, 0)._origWidth = oldWidth;
				}
			}
			
			if ( _proxy_jslib_handle(objects, (i), 0, 0)._ratio === 0) continue;

			// resize to original dimensions if object fit
			if (MySpace.ProfileDisplay.validPercent( _proxy_jslib_handle(objects, (i), 0, 0)._origWidth)) {
				 _proxy_jslib_handle(objects, (i), 0, 0).height = (newWidth * (parseInt(oldWidth) / 100)) /  _proxy_jslib_handle(objects, (i), 0, 0)._ratio;
			}
			else if (!isNaN( _proxy_jslib_handle(objects, (i), 0, 0)._origWidth)){
				if ( _proxy_jslib_handle(objects, (i), 0, 0)._origWidth >= newWidth){
					 _proxy_jslib_handle(objects, (i), 0, 0).height = newWidth /  _proxy_jslib_handle(objects, (i), 0, 0)._ratio;
					 _proxy_jslib_handle(objects, (i), 0, 0).width = newWidth;
				}
				else if ( _proxy_jslib_handle(objects, (i), 0, 0)._origWidth !==  _proxy_jslib_handle(objects, (i), 0, 0).width) {
					 _proxy_jslib_handle(objects, (i), 0, 0).height =  _proxy_jslib_handle(objects, (i), 0, 0)._origWidth /  _proxy_jslib_handle(objects, (i), 0, 0)._ratio;
					 _proxy_jslib_handle(objects, (i), 0, 0).width =  _proxy_jslib_handle(objects, (i), 0, 0)._origWidth;
				}
			}
		}
	}
};

MySpace.ProfileDisplay.validPercent = function(val) {
	var theNum = parseInt(val);
	return ((val.lastIndexOf('%') === (val.length - 1)) && (!isNaN(theNum)) && (theNum > 0 && theNum <= 100));
}; ;
_proxy_jslib_flush_write_buffers() ;