/*----------------------------------------------------------
	Name:		Chris Isaak
	Code:		Matt Goucher : ground(ctrl)
----------------------------------------------------------*/
$(document).ready(function(){

	$('.home.featured.news .listing')
		.slider({
			transition	: 'slide',
			auto		: false,
			interval	: 7000,
			navigation: false,
			loop		: true,
			seemlessLoop : true 
		});

	var ctrlrElement = $('#ctrlr'),
		ctrlr = $('#ctrlr a'),
		home = 0,
		events = 1140,
		slideshow = 2040,
		featured = 3140,
		recent = 4240;
	
	ctrlr.bind('click',function(){
		var length = $(this).attr('class');

		$('html, body')
			.stop()
			.animate({ 
				scrollTop: $('.parallax-section.' + length).offset().top
			}, 1000);
	});
	
	$(window).bind('scroll',function(){
		var scrollPos = window.scrollY;
		if( scrollPos < events ) {
			var current = 'home';
		}else if ( scrollPos >= events && scrollPos < slideshow ){
			current = 'events';
		}else if ( scrollPos >= slideshow && scrollPos < featured ){
			current = 'slideshow';
		}else if ( scrollPos >= featured && scrollPos < recent ){
			current = 'featured';
		}else if ( scrollPos >= recent ){
			current = 'recent';
		}			
		
		if ( current != ''){
			ctrlrElement.children('.' + current)
				.addClass('selected')
				.siblings().removeClass('selected');
		}
		
	});
	
});
