/*
	-- -- -- -- -- -- --
	css sprites 2
	cross-browser fancy nav behaviour
	
	http://www.alistapart.com/articles/sprites2
	-- -- -- -- -- -- --	
*/
function generateSprites(parent, selectedPrefix, setActive, hoverSpeed, style) {
	// throw the parent object's class into a variable
	var parentClass = $(parent).attr("class");

	// start a loop that cycles through each of the li elements inside the parent element
	$(parent).children("li").each(function() {
		// create a few variables that we'll need during this function:
		// myClass = the class of the object we're currently inspecting
		// current = what the selected class should look like for the parent of the object we're currently inspecting
		var myClass = ($(this).attr("class"))
		var current = parent.substring(1) + " current-" + ($(this).attr("class"));

		// turn on nav events for element this loop identifies
		attachNavEvents(parent, myClass, setActive, hoverSpeed, style);
	
		// let's hide the CSS-defined background image, but only if this isn't the currently-selected item
		if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}

	});
}






/*
	-- -- -- -- -- -- --
	jquery masonry
	arranges elements horizontally and vertically according to a grid

	http://desandro.com/demo/masonry/
	-- -- -- -- -- -- --
*/			
$(function(){
	$('.note-listing').masonry({
		//columnWidth: 260, 
		columnWidth: 300, 
		itemSelector: 'div'
	});
	
 	$('.related-note-listing').masonry({
		columnWidth: 225, 
		itemSelector: 'div'
	});
	
	 $('.mixtape-thumbnails').masonry({
		columnWidth: 320, 
		itemSelector: 'div'
	});
	
	// animation speed
	var speed = 750;
	
	$('.thumbnails').masonry({
	    columnWidth: 240,
	    // only apply masonry layout to visible elements
	    itemSelector: '.thumb:not(.invis)',
	    animate: true,
	    animationOptions: {
	        duration: speed,
	        queue: false
	    }
	});
	
	$('.work-type-nav a').click(function(){
	    var colorClass = '.' + $(this).attr('class');
	    //$("a.selected").removeClass("selected");
        //$(this).addClass('selected'); 
	    
	    if(colorClass=='.all') {
	        // show all hidden boxes
	        $('.thumbnails').children('.invis')
	            .toggleClass('invis').animate({opacity: 1},{ duration: speed });   
	    } else {    
	        // hide visible boxes 
	        $('.thumbnails').children().not(colorClass).not('.invis')
	            .toggleClass('invis').animate({opacity: 0},{ duration: speed });
	        // show hidden boxes
	        $('.thumbnails').children(colorClass+'.invis')
	            .toggleClass('invis').animate({opacity: 1},{ duration: speed });  
	    }
	    
	    $('.thumbnails').masonry();	
	    return false;
	});
  
/* Resolve any incoming anchor links */
	$(window).load(function(){
		if ( window.location.hash ) {
		    var destination = $( window.location.hash ).offset().top;
		    $("html:not(:animated),body:not(:animated)").scrollTop( destination );
		}
	});
});











		
$(document).ready(function(){
	/*
	-- -- -- -- -- -- --
	css sprites 2
	cross-browser fancy nav behaviour
	
	http://www.alistapart.com/articles/sprites2
	-- -- -- -- -- -- --	
	*/
	//generateSprites(".nav", "current-", true, 300, "fade");
	
	
	
	
	/*
	-- -- -- -- -- -- --
	add div to images
	insert a div around images so that we don't have to add extra mark-up in the backend
	-- -- -- -- -- -- --
	*/	
	$('.project .post p img').parent().addClass('diagonal-background');
	
	
	
	
	/*
	-- -- -- -- -- -- --
	project nav
	adds/removes highlight ids, not classes!! :(
	-- -- -- -- -- -- --
	*/	
	$("p.work-type-nav a").click(function(){
        $("a#selected").removeAttr('id', 'selected');
        $(this).attr('id', 'selected');                                               
	});
	
	

	
	/*
	-- -- -- -- -- -- --
	project hovers
	adds hover to project images
	-- -- -- -- -- -- --
	*/
	$('.thumbnails .thumb img').hover(
		function(){$(this).fadeTo('fast', 0.7);},
		function(){$(this).fadeTo('fast', 1);}
	);

});   
