var myGetComputedStyle = function(element)
{
	return element.currentStyle || document.defaultView.getComputedStyle(element, '');
}

var adjustImageSize = function(image)
{
	var diff, block, blockStyle, imageStyle;
	var blockWidth, blockHeight, imageWidth, imageHeight;
	var photoFrame, eventDate, i, l;

	try {
		block = image.parentNode;
		if (block.className != 'photo-image') {
			block = block.parentNode;
			if (block.className != 'photo-image') {
				return;
			}
		}

		photoFrame = block.parentNode;
		if (photoFrame.className == 'photo') {
			eventDate = null;
			i = 0;
			l = photoFrame.childNodes.length;
			while (i < l) {
				if (photoFrame.childNodes[i].nodeType == 1) {
					eventDate = photoFrame.childNodes[i];
					break;
				}
				i++;
			}
			if (eventDate && eventDate.className == 'photo-event-date') {
				photoFrame.className += ' photo-event';
			}
		}

		blockStyle = myGetComputedStyle(block);
		blockWidth = parseInt(blockStyle.width);
		blockHeight = parseInt(blockStyle.height);

		imageStyle = myGetComputedStyle(image);
		imageWidth = parseInt(imageStyle.width);
		imageHeight = parseInt(imageStyle.height);

		if (imageWidth / imageHeight > blockWidth / blockHeight) {
			image.style.width = 'auto';
			image.style.height = blockStyle.height;
			diff = blockWidth - blockHeight * imageWidth / imageHeight
			image.style.marginLeft = Math.floor(diff / 2).toString() + 'px';
		} else {
			image.style.width = blockStyle.width;
			image.style.height = 'auto';
			diff = blockHeight - blockWidth * imageHeight / imageWidth
			image.style.marginTop = Math.floor(diff / 2).toString() + 'px';
		}
	} catch (e) {}
}
