$.fn.nextUntil = function(expr, include) {
var match = [];
include = include ? true : false

// We need to figure out which elements to push onto the array
this.each(function(){
// Traverse through the sibling nodes
for( var i = this.nextSibling; i; i = i.nextSibling ) {
// Make sure that we're only dealing with elements
if ( i.nodeType != 1 ) continue;

// Add it on to the stack if include is set
if ( include ) {
match.push( i );
}
// If we find a match then we need to stop
if ( jQuery.filter( expr, [i] ).length ) break;

// Add it on to the stack if include is not set
if (! include ) {
match.push( i );
}
}
});
return this.pushStack( match, arguments );
}


$(document).ready(function() {



	/*	EXTERNAL LINKS
	-------------------------------------------------------------*/

	$('a.external').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
 
 
 
 
	/*	CUFON TYPOGRAPHY
	-------------------------------------------------------------*/
	 
	Cufon.replace('h1', { fontFamily: 'BlairMdITC TT' });
	Cufon.replace('form#newsletter p', { fontFamily: 'HelveticaNeue57' });
	Cufon.replace('#navigation li a', { fontFamily: 'HelveticaNeue57' });




	/*	ACCORDION
	----------------------------------------------------------*/
	
	$("#sidebar").accordion({ header: 'dt' });
	$("#sidebar dt").click(function(){
		$(this).addClass("test").siblings("#sidebar dt").removeClass("test");
	});
	$("#sidebar dd").height(352);



	/*	TEAM SHOW/HIDE 
		Hide (Collapse) the toggle containers on load
	----------------------------------------------------------*/

		$(".reveal dd").hide();
		$("dl.reveal ul").hide();
		
		$(".reveal dt").toggle(function(){$(this).addClass("selected").nextUntil("dt").slideToggle("200");}, function (){$(this).removeClass("selected").nextUntil("dt").slideToggle("200");});
		

	
		$(".reveal dd h6").click(function() {
	    	 $(this).next("dl.reveal ul").slideToggle("200");
	  		});	

		
		
	/*	TEAM SHOW/HIDE 
		Hide (Collapse) the toggle containers on load
	----------------------------------------------------------*/

		$(".team_content").hide();
		
		$("h5.team a").toggle(function(){$(this).addClass("selected");}, function (){$(this).removeClass("selected");});
		
		$("h5.team a").click(function(){$(this).next(".team_content").slideToggle("200");});
		


		
	/*	TABS: IMAGE EFFECTS
	-------------------------------------------------------------*/

		$('#photos').galleryView({
			panel_width: 430,
			panel_height: 183,
			frame_width: 30,
			frame_height: 30,
		    overlay_opacity: 0.25,
		    background_color: '#4d3011',
		    border: '1px solid #4d3011',
		    pointer_color: '#4d3011',
		    pause_on_hover: true
	    });


	/*	PRINT
	-------------------------------------------------------------*/

		$("a.print").click(function () {
			$('[rel="hidden"]').show();
			javascript:window.print();
			return false;
		});


	/*	CYCLE: IMAGE EFFECT
	-------------------------------------------------------------*/
	$('#cycle_effect').cycle({ 
  		delay:  500, 
    	speed:  1000, 
    	cleartype:  true,
    	cleartypeNoBg:  true,
    	before: onBefore 
	}); 
 
 
	function onBefore() { 
	    $('#title') 
	        .html(this.alt); 
	}; 


	/*	COLORBOX: Launch Lightbox
	-------------------------------------------------------------*/
	
	$('a.gallery').colorbox({transition:'fade', speed:500});


});

