jQuery(document).ready(function() {
	
	//Add JS control class
	jQuery('body').addClass('js-enabled').prepend('<span id="scroll-control"></span>');
		
	//Move images into column
	jQuery('ul#posts > li > div.body').find('img').each(
		function(i)
		{
			jQuery(this).removeAttr('title');
			jQuery(this).closest('li').find('div.images').append(jQuery(this));
		}
	);
	
	//Clean up empty paragraphs and links
	jQuery('ul#posts a:empty').remove();
	jQuery('ul#posts p:empty').remove();
	
	//Make web icon sticky
	jQuery('p#web-icon').sticky();
	
	//Position header dots
	jQuery('ul#posts li h2').addClass('follow').each(
		function(i)
		{
			//Get offset position of headers
			var offset = jQuery(this).offset();
			
			//Position dots
			jQuery('<span class="dot" id="dot-'+i+'"></span>').appendTo('body').css({
				'top' : (offset.top),
				'left' : (offset.left)
			});
		}
	);
	
	jQuery(window)
		.bind('scrollstop', function(e){
			
			//Move dots
	    	jQuery('ul#posts li h2').each(
				function(i)
				{
					var offset = jQuery(this).offset();
					var dot_id = "#dot-" + i;
					var scroll_control = (jQuery('span#scroll-control').offset().top);
					jQuery(dot_id).animate({'top' : (offset.top - scroll_control)}, 1000);
				}
			);
			
			//Move web icon
			jQuery('p#web-icon').sticky(1000);
			
		})
		.resize(function(){
			jQuery('ul#posts li h2').each(
				function(i)
				{
					var offset = jQuery(this).offset();
					var dot_id = "#dot-" + i;
					jQuery(dot_id).css({'left' : offset.left});
				}
			);
			
			//Make web icon sticky
			jQuery('p#web-icon').sticky();
		})
	;
	
	//Show subscribe form
	jQuery('a#subscribe-toggle').toggle(
		function() { jQuery('div#subscribe').fadeIn(); return false; },
		function() { jQuery('div#subscribe').hide(); return false; }
	);
	
});