var mmTargets="#contentBlock-1 img";

function mmAdaptMasthead () {
	var w = jQuery(window).width();

	var path = jQuery('#masthead').attr('src');
	path = path.replace(/\w*\.\w*$/,'');

	var img = 
		(w > 1024) ? 'mm_masthead_1024x77.png'
		: (w > 960) ? 'mm_masthead_960x73.png'
		: (w > 768)	? 'mm_masthead_768x58.png'
		: (w > 640)	? 'mm_masthead_640x48.png'
		: (w > 480)	? 'mm_masthead_480x36.png'
		: 'mm_masthead_320x24.png';


	jQuery('#masthead').attr('src', path+img);
}

jQuery(document).ready(function() {
	// Remove HTML attributes from ALL images
	jQuery('img').each(function() {
			jQuery(this).removeAttr('width').removeAttr('height');	// Remove HTML Attributes
	});
	
	mmAdaptMasthead();

	jQuery(mmTargets).each(function () {
		jQuery(this).load(function () {
			var el = jQuery(this);
			el.css('width','auto').css('height','auto').css('max-width','100%');	// Remove existing CSS
			el.removeAttr('width').removeAttr('height');	// Remove HTML Attributes
			el.data('ratio', el.width()/el.height());
			mmAdaptImages();
		});
	});

	jQuery(window).resize(function () {
		mmAdaptImages();
		mmAdaptMasthead();
	});
});

jQuery(window).load(function () {
	mmAdaptImages();
});

function mmAdaptImages() {
	jQuery(mmTargets).each(function () {
		var el = jQuery(this);
		el.css('width','auto').css('height','auto');
		var thisLh = 18;
		var thisFs = parseInt(el.css('font-size'));
		var width = el.width();
		var ratio = el.data().ratio;
		var blHeight =	(Math.round((width / ratio)/thisLh))*thisLh/thisFs + "em";
		el.css('height',blHeight);
	});
}


