$(document).ready(function() {
	// add captions to all article images
	
	$('div.entry-asset img').each(function() {
		var imgWidth = $(this).width();
		if (imgWidth > 200) {
			var imgSrc = $(this).attr('alt');
			var imgDesc = $('p.lightbox-desc:contains('+imgSrc+')').attr('title');
			var imgWidth = $(this).width();
			imgWidth = imgWidth + 8;
			if (imgDesc && imgDesc.length > 0) {
				var toAppend = '<p class="imgDesc" style="width: ' +imgWidth+ 'px;">'+imgDesc+'</p>';
				var thisFloat = $(this).css('float');
				if($(this).parent().parent('.mt-enclosure-image').length > 0) {
					$(this).css({'margin-bottom': '0', 'float': 'none'}).parent().parent('.mt-enclosure-image').append(toAppend).css({'display': 'block', 'float': 'right', 'margin-right': '20px', 'width': imgWidth});
				} else {
					$(this).css({'margin-bottom': '0', 'float': 'none'}).parent().append(toAppend).css({'display': 'block', 'float': 'right', 'margin-left': '20px', 'width': imgWidth});
				}
			}
		}
		
	});
	
	//add some margin to all object tags in the blogs
	$('object').each(function(){
		var el = $(this);
		var side = el.attr('align');
		if (side == 'left')
			el.attr('style', 'margin: 10px 20px 10px 0; display: block; float: left;');
		else
			el.attr('style', 'margin: 10px 0px 10px 20px; display: block; float: right;');
		el.removeAttr('align');
	});
	
	//if it's floated, make it actually float correctly
	$('img.mt-image-right').each(function() {
		$(this).attr('style', 'float: right; margin-left: 20px; display: inline;');
	});
	$('img.mt-image-left').each(function() {
		$(this).attr('style', 'float: left; margin-right: 20px; display: inline;');
	});

});
