/* Author: Barandi Solutions
 * www.barandisolutions.com
 */ 

(function() {
	
	var $items = $('header li a.scroll-nav');	
	var position = [0, 350, 1200];
	
	var scrollPage = function() {
		var y = (window.scrollY || window.scrollY === 0) ? window.scrollY : document.documentElement.scrollTop,
			$current;		
		
		if(y < position[1]) {
			$current = $items.eq(0);			
		} else if(y < position[2]) {
			$current = $items.eq(1);
		} else {
			$current = $items.eq(2);
		};
		
		if($current.hasClass('active-item')) return false;
			
		$items.removeClass('active-item');
		$current.addClass('active-item');
		
	};
	
	var scrollToPosition = function() {
		var $this = $(this);
		var index = $items.index($this);
		
		$('html, body').animate({
			scrollTop: parseInt(position[index])
		}, 500);
		return false;
	};
	 
	$(document).ready(function() {
		$items.click(scrollToPosition);
		
		$('#contact-button').click(function() {
			$('html, body').animate({
				scrollTop: parseInt(position[3])
			}, 500);
		});
		
		scrollPage();
		$(window).bind('scroll', scrollPage);
	});

}());
