/* Author: 

*/

	
/******************toggle site index*****************/
	
$(function(){
		$("a#click_open").click(function(){
		$("nav#footer").slideDown("slow");
		$("#click_open").toggle("fade");
		$("a#click_close").toggle("fade");
		return false;
	});
	
		$("a#click_close").click(function(){
		$("nav#footer").slideUp("slow");
		$("a#click_open").toggle("fade");
		$("a#click_close").toggle("fade");
		return false;
	});
});

$(function(){
		$("a#click_open_login").click(function(){
		$("#account").slideDown("slow");
		return false;
	});
	
		$("a#click_close_login").click(function(){
		$("#account").slideUp("slow");
		return false;
	});
});


$(function(){
	// Set starting slide to 1
	var startSlide = 1;
	// Get slide number if it exists
	if (window.location.hash) {
		startSlide = window.location.hash.replace('#','');
	}
	// Initialize Slides
	$('#slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		generatePagination: true,
		play: false,
		pause: 2500,
		hoverPause: true,
		slideSpeed:800,
		// Get the starting slide
		start: startSlide,
		animationComplete: function(current){
			// Set the slide number as a hash
			window.location.hash = '#' + current;
		}
	});
});


// perform JavaScript after the document is scriptable.
$(function() {
	// setup ul.tabs to work as tabs for each div directly under div.panes
	$("ul.tabs").tabs("div.panes > div");
});

$(document).ready(function() {
	$('.top').addClass('hidden');
	$.waypoints.settings.scrollThrottle = 30;
	$('#wrapper').waypoint(function(event, direction) {
		$('.top').toggleClass('hidden', direction === "up");
	}, {
		offset: '-100%'
	}).find('#main-nav-holder').waypoint(function(event, direction) {
		$(this).parent().toggleClass('sticky', direction === "down");
		event.stopPropagation();
	});
});

jQuery(function($) {
	// Register each section as a waypoint.
	$('article > section').waypoint({ offset: '50%' });
	
	// The same for all waypoints
	$('body').delegate('article > section', 'waypoint.reached', function(event, direction) {
		var $active = $(this);
		
		if (direction === "up") {
			$active = $active.prev();
		}
		if (!$active.length) $active.end();
		
		$('.section-active').removeClass('section-active');
		$active.addClass('section-active');
		
		$('.link-active').removeClass('link-active');
		$('a[href=#'+$active.attr('id')+']').addClass('link-active');
	});
	
	// Negates the flash of non-active nav.
	$('body > header nav a').click(function() {
		$(this).addClass('link-active');
	}).eq(0).addClass('link-active');
	
	// Wicked credit to
	// http://www.zachstronaut.com/posts/2009/01/18/jquery-smooth-scroll-bugs.html
	var scrollElement = 'html, body';
	$('html, body').each(function () {
		var initScrollTop = $(this).attr('scrollTop');
		$(this).attr('scrollTop', initScrollTop + 1);
		if ($(this).attr('scrollTop') == initScrollTop + 1) {
			scrollElement = this.nodeName.toLowerCase();
			$(this).attr('scrollTop', initScrollTop);
			return false;
		}    
	});
	
	// Smooth scrolling for internal links
	$("a[href^='#']").click(function(event) {
		event.preventDefault();
		
		var $this = $(this),
		target = this.hash,
		$target = $(target);
		
		$(scrollElement).stop().animate({
			'scrollTop': $target.offset().top
		}, 500, 'swing', function() {
			window.location.hash = target;
		});
		
	});
});
