function dynamic_comments_show()
{
		$(".article").hide();
		$(".comments").show();
}

function dynamic_comments_hide()
{
	$(".comments").hide();
	$(".article").show();
	size_pictures();
}


$(document).ready(function() {
	
	var str = document.location.toString();
	if(str.indexOf("#comments") != -1)
	{
		dynamic_comments_show();
	}
	else if(str.indexOf("#respond") != -1)
	{
		dynamic_comments_show();
	}
	else
	{
		dynamic_comments_hide();
	}
		

	setTimeout("size_pictures()",500);
});

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function size_pictures() {
	$('.text img').each(function(index) {
	  if ($(this).width() > 490) {
			var width = $(this).width();
			var height = $(this).height();
			var ratio = roundNumber(width/height,2);
			width = 490;
			height = roundNumber(width/ratio,0)
			$(this).css('width', width+'px');
			$(this).css('height', height+'px');
	  }
	});
	$('.text .wp-caption').each(function(index) {
		if ($(this).width() > 510) {
			$(this).css('width', '510px');
		}
	});
	$('.text embed').each(function(index) {
		var url = $(this).attr("src");
		var is_youtube = url.search("youtube.com");
		if ($(this).width() > 524 && is_youtube != -1 ) {
			var width = $(this).width();
			var height = $(this).height();
			var ratio = roundNumber(width/height,2);
			width = 524;
			height = roundNumber(width/ratio,0)
			$(this).css('width', width+'px');
			$(this).css('height', height+'px');
		}
	});
		$('.text object').each(function(index) {
		var url = $(this).attr("src");
		if ($(this).width() > 524 ) {
			var width = $(this).width();
			var height = $(this).height();
			var ratio = roundNumber(width/height,2);
			width = 524;
			height = roundNumber(width/ratio,0)
			$(this).css('width', width+'px');
			$(this).css('height', height+'px');
		}
	});
}
