$(function() {

	// validate contact form
	if ($("#contact").length > 0) {
		$("#contact-form").validate();
	}
	
	// initialize scrollable
//	if ($("#contact").length == 0) {
//	$(".scrollable").scrollable({ circular: true }).click(function() {
//		var numImages = $('.scrollable .items div:not(.cloned)').length;
//		if (numImages > 1) {
//			$(this).data("scrollable").next();
//		}
//	});
// }
	
	var numImages = $('.scrollable .items div:not(.cloned)').length;
	if (numImages > 1) {
		$('a.browse').css({'display':'block'});
	}
	
	var 
		speed = 1000,   // animation speed
		$wall = $('#masonary').find('.wrap')
	;


	// homepage masonry
	if ($("#services").length > 0) {
		$wall.masonry({
			columnWidth: 18,
			itemSelector: '.box:not(.invis)'
		});
	}

	// homepage masonry
	if ($("#home").length > 0) {
		$wall.masonry({
			columnWidth: 18,
			itemSelector: '.box:not(.invis)'
		});
	}
	
	// projects masonry
	if ($("#case_studies").length > 0) {
		$wall.masonry({
			columnWidth: 18,
			itemSelector: '.box:not(.invis)',
			animate: true,
			animationOptions: {
				duration: speed,
		    	queue: false
			}
		}, function() {
			$wall.children().not('.featured').not('.invis').toggleClass('invis').hide();
			$('.band_wrap h1').find('span').html('Featured');
			$('#filtering-nav .hidden').removeClass('hidden');
			$('.wrap').masonry({
				itemSelector: '.box:not(.invis)',
				columnWidth: 18
			});
		});
	}

	// masonry event handlers
	$('#filtering-nav a').click(function(){
		var colorClass = '.' + $(this).attr('class');
		if(colorClass=='.all') {
			// show all hidden boxes
		    $wall.children('.invis').toggleClass('invis').fadeIn(speed);
		} else {  
		    // hide visible boxes 
		    $wall.children().not(colorClass).not('.invis').toggleClass('invis').fadeOut(speed);
		    // show hidden boxes
		    $wall.children(colorClass+'.invis').toggleClass('invis').fadeIn(speed);
		}
		$wall.masonry();
		var filterName = $(this).attr('title');
		$('.band_wrap h1').find('span').html(filterName);
		return false;
	});
	
});



