function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
function colorbox(){
	$(".colorbox-image").colorbox({
		rel: 'colorbox-image'
	});
	$(".colorbox-iframe").colorbox({
		iframe: true,
		width: "80%",
		height: "80%"
	});
	$(".colorbox-inline").colorbox({
		inline: true
	});
}

jQuery(document).ready(function(){
	
	$('#page').hide().fadeIn(1000);
	
	colorbox();
	
	// DigitalMill
	function resetStage() {
		var r = setTimeout(function() {
			digitalmillHeader();
		}, 10000);
	}
	function digitalmillHeaderInit() {
		function bokeh() {
			$(".bokeh").animate({
				opacity: 1
			}, 7000);				
		}
		function slideText() {
			$(".where").animate({
				opacity: 1,
				left: 320
			}, 1000);
			$(".where").animate({
				left: 370
			}, 4000);
			$(".where").animate({
				left: 970,
				opacity: 0
			}, 500);
			$(".meets").delay(500).animate({
				opacity: 1,
				left: 350
			}, 1000);
			$(".meets").animate({
				left: 220
			}, 3500);
			$(".meets").animate({
				left: -300,
				opacity: 0
			}, 500, function() {
				showLogo();
			});
		}
		function showLogo() {
			$(".digitalmill-logo").animate({
				opacity: 1	
			}, 1000);
			$(".digitalmill").delay(200).animate({
				opacity: 1	
			}, 1000, function() {
				resetStage();
			});
		}
		bokeh();	
		slideText();	
	}
	function digitalmillHeader() {
		$(".digitalmill-logo, .digitalmill").animate({
			opacity: 0
		}, 500);
		$(".where").css({ left: -259 });
		$(".meets").css({ left: 961 });
		digitalmillHeaderInit();
	}
	digitalmillHeader();
	
	// quicksand
	$filterHolder = $('ul.filter-items'); // get original list
	$filterClone = $filterHolder.clone(); // clone it so it can be reverted back to
	
	$('ul.filter-menu a').click(function(e) {
		e.preventDefault(); // stop anchor tags from doing anything
		
		$filterClass = $(this).attr('class'); // gets class from clicked anchor
		
		$('ul.filter-menu li').removeClass('active'); // remove active class from all filter links
		$(this).parent().addClass('active'); // add active class to clicked link
		
		if($filterClass == 'all'){
			$filters = $filterClone.find('li'); // get all li's from original cloned list and assign them to variable
		} else {
			$filters = $filterClone.find('li[data-type~='+ $filterClass +']'); // get li's from ul.source with data-type containing $filterclass
		}
		
		$filterHolder.quicksand($filters, {
			duration: 1000,
			adjustHeight: 'dynamic'
		}, function() {
			// callback code
			colorbox();
		}); // initiate quicksand fn
	});
	
	// sitemap
	$('#menu-sitemap li:has(ul)').not('li ul li').append('<span class="toggle"></span>');
	$("#menu-sitemap li span.toggle").click(function(){
		$(this).toggleClass("active").prev().slideToggle("fast");
		$(this).parent().toggleClass("active");
	});
	
	// equalHeight
	//equalHeight($("#id"));
	
});
