jQuery(function( $ ){
/**
* Demo binding and preparation, no need to read this part
*/
//borrowed from jQuery easing plugin
//http://gsgd.co.uk/sandbox/jquery.easing.php
$.easing.easeInOutSine= function (x, t, b, c, d) {
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};


	//by default, the scroll is only done vertically ('y'), change it to both.
	$.scrollTo.defaults.axis = 'y'; 			
	//this one is important, many browsers don't reset scroll on refreshes
	$('div.pages').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$.scrollTo( 0 );//reset the screen to (0,0)

	//TOC, shows how to scroll the whole window
	$('.pageNavi a').click(function(){//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
		$.scrollTo( this.hash, 800, { easing:'easeOutSine' });
		$(this.hash).find('.section part').text( this.title );
		return false;
	});
	
	// handle nav selection
	$('#masthead #navigation').find('a').click(selectNav);

	function selectNav() {
	  $(this)
	    .parents('ul:first')
	      .find('a')
	        .removeClass('selected')
	      .end()
	    .end()
	    .addClass('selected');
	}

	// go find the navigation link that has this target and select the nav
	function trigger(data) {
	  var el = $('#masthead #navigation').find('a[href$="' + data.id + '"]').get(0);
	  selectNav.call(el);
	}

	if (window.location.hash) {
	  trigger({ id : window.location.hash.substr(1) });
	} else {
	  $('ul#navigation li a:first').click();
	}

});
