$(document).ready(function() {

	// Filter the service and project listing templates
	$('#filters select').change(function() {
		$(this).siblings('input[type=submit]').trigger('click');
	});


	// Swap form field values when focused
	$('input[type=text], input[type=search]').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {this.value = '';}
	    });
	    $(this).blur(function() {
	        if(this.value == '') {this.value = default_value;}
	    });
	});


	// Animate the business divisions tabs when hovered
	$('#division-list li h3').hover(function() {
		$(this).siblings('p').css('z-index','10').slideDown();
	}, function() {
		$(this).siblings('p').css('z-index','0').slideUp();
	});
	
	
	// Hide gallery link if there are no items
	if ( $('#content #photo-gallery li').length == 0 ) {
		$('a.gallery-link').hide();
	}
	

	// Configuration for the slideshow on homepage
	$('#feature').append('<div id="slideshow-nav"></div>');
	
	$('#slideshow').cycle({
		fx: 'fade',
		timeout: 10000,
		activePagerClass: 'active',
		prev: '#slideshow-controls a.prev',
		next: '#slideshow-controls a.next',
		pager: '#slideshow-nav'
	});


	// Configuration for the photo gallery
	$('#main a.fancybox').attr('rel','gallery').fancybox({
		'type': 'image',
		'speedIn': 500,
		'speedOut':	200,
		'titlePosition': 'over',
		'overlayColor': '#000'
	});
	
	
	// Launch the photo gallery on click
	$('a.gallery-link, body.single a.photo').click(function() {
		$('#photo-gallery a.fancybox:first').trigger('click');
		
		return false;
	});


});
