function dynamic_comments_show()
{
		jQuery(".article").hide();
		jQuery(".comments").show();
		if(jQuery(".comments").html() == "")
		{
			jQuery(".comments").append("<p style=\"text-align:center;\"><img src=\"http://www.boot.lv/wp-content/themes/boot/img/ajax-loader.gif\" alt=\"loading\" style=\"text-align:center;\"/></p>");
			jQuery.ajax({ url: "http://www.boot.lv/wp-content/themes/boot/ajax_comments.php", data: "id="+comment_id, dataType: "html", success: function(d) {
				jQuery(".comments").html(d);

				}
			});
		}
		reload_ads();
		document.location.hash = "#comments";
		window.scrollTo(0, elmYPosition("comments"));
		//else
		//{
		//	$(".comments").show();
		//}
}

function elmYPosition(eID) {
	var elm  = document.getElementById(eID);
	if(elm != null){
		var y    = elm.offsetTop;
		var node = elm;
		while (node.offsetParent && node.offsetParent != document.body) {
			node = node.offsetParent;
			y   += node.offsetTop;
		} return y;
	} else {
		return 0;
	}
}

function dynamic_comments_hide()
{
	document.location.hash = "";
	jQuery(".comments").hide();
	jQuery(".article").show();
	size_pictures();
	reload_ads();
}

function reload_ads()
{
		var boot_ts = Math.round((new Date()).getTime() / 1000);
		if(jQuery("#ad_250x200_1")[0]){
			jQuery("#ad_250x200_1").html("<iframe id='a6bb35b7' name='a6bb35b7' src='http://ads.boot.lv/www/delivery/afr.php?zoneid=13&amp;cb="+boot_ts+"' frameborder='0' scrolling='no' width='250' height='200'><a href='http://ads.boot.lv/www/delivery/ck.php?n=a9f1f0c5&amp;cb="+boot_ts+"' target='_blank'><img src='http://ads.boot.lv/www/delivery/avw.php?zoneid=13&amp;cb="+boot_ts+"&amp;n=a9f1f0c5' border='0' alt='' /></a></iframe>");
		}
		if(jQuery("#ad_250x200_2")[0]){
			jQuery("#ad_250x200_2").html("<iframe id='a2204664' name='a2204664' src='http://ads.boot.lv/www/delivery/afr.php?zoneid=14&amp;cb="+boot_ts+"' frameborder='0' scrolling='no' width='250' height='200'><a href='http://ads.boot.lv/www/delivery/ck.php?n=a85c4a2e&amp;cb="+boot_ts+"' target='_blank'><img src='http://ads.boot.lv/www/delivery/avw.php?zoneid=14&amp;cb="+boot_ts+"&amp;n=a85c4a2e' border='0' alt='' /></a></iframe>");
		}
		if(jQuery("#ad_250x200_3")[0]){
			jQuery("#ad_250x200_3").html("<iframe id='aea8972a' name='aea8972a' src='http://ads.boot.lv/www/delivery/afr.php?zoneid=15&amp;cb="+boot_ts+"' frameborder='0' scrolling='no' width='250' height='200'><a href='http://ads.boot.lv/www/delivery/ck.php?n=a0702d64&amp;cb="+boot_ts+"' target='_blank'><img src='http://ads.boot.lv/www/delivery/avw.php?zoneid=15&amp;cb="+boot_ts+"&amp;n=a0702d64' border='0' alt='' /></a></iframe>");
		}
		if(jQuery("#ad_250x200_4")[0]){
			jQuery("#ad_250x200_4").html("<iframe id='ae32218f' name='ae32218f' src='http://ads.boot.lv/www/delivery/afr.php?zoneid=16&amp;cb="+boot_ts+"' frameborder='0' scrolling='no' width='250' height='200'><a href='http://ads.boot.lv/www/delivery/ck.php?n=a753404b&amp;cb="+boot_ts+"' target='_blank'><img src='http://ads.boot.lv/www/delivery/avw.php?zoneid=16&amp;cb="+boot_ts+"&amp;n=a753404b' border='0' alt='' /></a></iframe>");
		}
}


jQuery(document).ready(function() {

	if(document.location.hash.search("comment") != -1)
	{
		dynamic_comments_show();
	}
	else if(document.location.hash.search("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() {
	jQuery('.text img').each(function(index) {
	  if (jQuery(this).width() > 490) {
			var width = jQuery(this).width();
			var height = jQuery(this).height();
			var ratio = roundNumber(width/height,2);
			width = 490;
			height = roundNumber(width/ratio,0)
			jQuery(this).css('width', width+'px');
			jQuery(this).css('height', height+'px');
	  }
	});
	jQuery('.text .wp-caption').each(function(index) {
		if (jQuery(this).width() > 510) {
			jQuery(this).css('width', '510px');
		}
	});
	jQuery('.text embed').each(function(index) {
		var url = jQuery(this).attr("src");
		var is_youtube = url.search("youtube.com");
		if (jQuery(this).width() > 524 && is_youtube != -1 ) {
			var width = jQuery(this).width();
			var height = jQuery(this).height();
			var ratio = roundNumber(width/height,2);
			width = 524;
			height = roundNumber(width/ratio,0)
			jQuery(this).css('width', width+'px');
			jQuery(this).css('height', height+'px');
		}
	});
}
