{#
	Generate a list of linked tag.
#}
{% macro tags_list(tags, inline=False, add_hash=False, count=False) -%}

	{%- if inline -%}
		<span class="tags">
	{%- else -%}
		<div class="tags">
	{%- endif -%}

	{%- for tag in tags -%}
		<a href="{{ tag.url }}">{% if add_hash %}#{% endif %}{{ tag.name }}</a>
		{%- if count -%}
			<small class="text-muted">&nbsp;-&nbsp;{{ tag.count }}</small>
		{%- endif -%}
		{%- if not loop.last %}, {% endif %}
	{%- endfor -%}

	{% if inline -%}
		</span>
	{%- else -%}
		</div>
	{%- endif -%}

{%- endmacro -%}


{#
	Inserts Google Analytics code.
	This code is derived from the Octopress template, https://github.com/imathis/octopress
#}
{% macro google_analytics(id) -%}

	<script type="text/javascript">
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', '{{ id }}']);
		_gaq.push(['_trackPageview']);

		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
	</script>

{%- endmacro -%}


{#
	Inserts Disqus comments.
#}
{% macro disqus_comments(id) -%}

	<div id="disqus_thread"></div>
	<script type="text/javascript">
	    var disqus_shortname = '{{ id }}';

	    (function() {
	        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
	        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	    })();
	</script>
	<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

{%- endmacro -%}


{#
	Disqus comments counter to be included before "</body>".

	Quoting disqus.com: Append #disqus_thread to the href attribute
	in your links. This will tell Disqus which links to look up and return
	the comment count. For example:

		<a href="http://foo.com/bar.html#disqus_thread">Link</a>

#}
{% macro disqus_counter(id) -%}

	<script type="text/javascript">
		var disqus_shortname = '{{ id }}';

		(function () {
		    var s = document.createElement('script'); s.async = true;
		    s.type = 'text/javascript';
		    s.src = '//' + disqus_shortname + '.disqus.com/count.js';
		    (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
		}());
	</script>

{%- endmacro -%}


{#
	Inserts AddThis sharing buttons.
	This code is generated by https://addthis.com.
#}
{% macro addthis(id, url) -%}

	<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={{ id }}"></script>
	<script type="text/javascript">
		var addthis_share = {
		    url : '{{ url }}'
		};
	  addthis.layers({
	    'theme' : 'transparent',
	    'share' : {
	      'position' : 'left',
	      'services' : 'twitter,facebook,google_plusone_share',
	      'numPreferredServices' : 5
	    },
	    'whatsnext' : {},
			'recommended' : {},
			'thankyou' : false
	  });
	</script>

{%- endmacro -%}


{#
	Pluso.ru sharing buttons.
#}
{% macro pluso(url) -%}

	<script type="text/javascript">(function() {
	  if (window.pluso)if (typeof window.pluso.start == "function") return;
	  if (window.ifpluso==undefined) { window.ifpluso = 1;
	    var d = document, s = d.createElement('script'), g = 'getElementsByTagName';
	    s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true;
	    s.src = ('https:' == window.location.protocol ? 'https' : 'http')  + '://share.pluso.ru/pluso-like.js';
	    var h=d[g]('body')[0];
	    h.appendChild(s);
	  }})();</script>
	<div class="pluso" data-background="transparent" data-options="medium,round,line,horizontal,nocounter,theme=04" data-services="twitter,facebook,vkontakte,google" data-url="{{ url }}" data-user="211370802"></div>

{%- endmacro -%}


{#
	Insert image defined by id.
#}
{% macro img(id) %}
	{{ id|image() }}
{% endmacro %}
