$(document).ready(function () {
	// if the window is taller than the entire contents, tack the bg image to the bottom of the window.
	//alert( $(document).height() +" : " + $(window).height() );
	if ( !$('body').hasClass('home') && $(window).height() > $(document).height() ){
		$('body').css('background-attachment',"fixed");
	}
	
	// *** hover-fade effects ***
	
	// duplicate the image
	$('.hover-fade a img').each( function(){
		var dup = $(this).clone().addClass("hover-image").insertAfter(this);
		$(this).css('left',"0");
		dup.css('opacity','0' );
	});
	// add events
	$('.hover-fade a').each( function(){
		$(this).mouseover(function() {
			$(".hover-image", this).stop().fadeTo(500,1);
		});
		$(this).mouseout(function() {
			$(".hover-image", this).stop().fadeTo(500,0);
		});

	});
	
	// *** multi-column ***
	var target = ".archives .posts";
	$( target ).append("<div class='multicolumn'>&nbsp;</div>");
	var numColumns = 3;
	var multiColumn = $(".multicolumn");
	var posts = $( target + ' .post' );
	var columnLength = Math.ceil(posts.length/numColumns);
	for ( var i=0; i < numColumns; i++ ){
		multiColumn.append("<div class='column' id='column-"+(i+1)+"'></div>");
	}
	for (var i=0; i<posts.length; i++ ){
		var current = Math.floor(i/columnLength)+1;
		$('#column-'+current).append(posts[i]);
		//console.log("Current: "+current);
		//console.log(posts[i]);
	}
	$('#column-'+Math.min(i,numColumns) ).append( $('.navigation') );

	
	// *** Shadowbox on image blocks *** 
	$('.image-block a:has(img)').map( function(){
		//console.log( $(this).attr('href') );
		if ( $(this).attr('href').indexOf('.jpg') > 0 || $(this).attr('src').indexOf('.png') > 0  ){
			$(this).attr('rel','shadowbox[post];player=img;');		
		}
	});
});

