// JQUERY DOM READY
$(document).ready(function() {
	// ToggleVal entry from input labels
	$(".toggleval").toggleVal({ populateFrom: "label", removeLabels: true });
	
	// Homepage Slider Gallery
	$('#slider').nivoSlider({
		controlNav: false,
		effect: 'fold',
		animSpeed: 1000,
		pauseTime: 5000,
		directionNav: false
	});
	
	// About Us collapse
	if($('#resources').length == 0){
		$('#content dl dt').toggle(
			function(){
				$(this).next('dd').slideUp();
				$(this).addClass('collapse');
				return false;
			}, function(){
				$(this).next('dd').slideDown();
				$(this).removeClass('collapse');
				return false;
			}
		);
		$('#content dl dt').click();
	}
	
	// Team Photo Fading
	$('#about ul li div').hide();
	$('#about ul li').hoverIntent(
		function(){
			$(this).find('div').fadeIn();
		}, function(){
			$(this).find('div').fadeOut();
	});
	
	// Gallery Logic
	$('#gallery .arrow.right').bind('click', function(){
		if ($('#gallery #image .on').next().length > 0){
			thisClass = $('#gallery #image .on').next();
			$('#gallery #image li').removeClass('on');
			thisClass.addClass('on');
			$('#gallery #image').stop(true, true).animate({left:	'-=449' }, 1000);
		}
		return false;
	});
	$('#gallery .arrow.left').bind('click', function(){
		if ($('#gallery #image .on').prev().length > 0){
			thisClass = $('#gallery #image .on').prev();
			$('#gallery #image li').removeClass('on');
			thisClass.addClass('on');
			$('#gallery #image').stop(true, true).animate({left:	'+=449' }, 1000);
		}
		return false;
	});
	$('#gallery area').bind('click', function(){
		substringed = $(this).attr('href').substr(1);
		leftScroll = (substringed * -449)+449;
		$('#gallery #image').fadeOut();
		$('#gallery #image').animate({left: leftScroll}, 1000, function(){ $('#gallery #image').fadeIn('slow') });
		$('#gallery #image li').removeClass('on');
		$('#gallery #image .' + substringed).addClass('on');
	});

});
