/* Do we need this for ie? */
document.createElement('header');
document.createElement('footer');
document.createElement('section');
document.createElement('aside');
document.createElement('nav');
document.createElement('article');

/* Google analytics */
var _gaq = [['_setAccount', 'UA-11067983-1'], ['_trackPageview']];
(function (d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
})(document, 'script');


var nameSpace = {};
/*global Hyphenator, prettyPrint */
function keepItNice()
{
	/* Move those labels inside */
	$('label').css('position', 'absolute').css('top', '4px').css('right', '15px');

	/* Make the text nice */
	Hyphenator.config({
		minwordlength : 4
	});
	Hyphenator.run();

	/* Highligh that code! */
	prettyPrint();
}

$(window).bind("load", function() {

	//$("h1").scaletext();

});


$(document).ready(function () {

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

	$('.open-disqus').click(function () {
    	var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
    	dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
    	(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
		$('.open-disqus').remove();
	});

	keepItNice();

	var hover = false;
	var fadeOutTimer;

	function fadeOut () {
		if (! hover && $(window).width() > 960) {
			$('header li:not(:first-child)').fadeOut(400);
			$('#logo').fadeTo('fast', .1)
		}
	}

	$(window).scroll(function () {
		if ($('header li:not(:first-child):visible').length > 0 && $(window).scrollTop() > 50) {
			fadeOut(400);
		} else if ($('header li:not(:first-child):visible').length === 0 && $(window).scrollTop() < 50) {
			$('header li:not(:first-child)').fadeIn('fast');
			$('#logo').fadeTo('fast', 1)
		}
	});

	$('header ul').hover(function () {
			hover = true;
			$('header li:not(:first-child)').fadeIn('fast');
			$('aside').fadeOut(400);
			$('#logo').fadeTo('fast', 1)
			clearTimeout(fadeOutTimer);
		}, function() {
			hover = false;
			if ($(window).scrollTop() > 50) {
				fadeOutTimer = setTimeout(fadeOut, 4000);
			}
		}
	);

});
