$(document).ready(function() {

	// Bind an event to window.onhashchange that, when the history state changes,
	// gets the url from the hash and displays either our cached content or fetches
	// new content to be displayed.
	$(window).bind( 'hashchange', function(e) {
		

	// Get the hash (fragment) as a string, with any leading # removed. Note that
	// in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
	var url = e.fragment;
	
	
	// If no hash exists in the url, just start the slideshow up
	
	if (url == "") {
		
		// Start the slideshow when the page loads
		startSlideshow();
		
	} //if
	
	else {
		
		// Kill any Current Slideshows
		$('.slideshow').find('ul').cycle('destory');
		
		// Remove .current-thumb class from any previously "current" link(s).
		$( 'a.current' ).removeClass( 'current' );
		
		// Add .current class to "current" nav link(s), only if url isn't empty.
		url && $( 'a[href="#' + url + '"]' ).addClass( 'current' );
		
		// Show "loading" content while AJAX content loads.
		$( '#content' ).addClass('loading');

		// Load external content via AJAX. Note that in order to keep this
		// example streamlined, only the content in .infobox is shown. You'll
		// want to change this based on your needs.
		$('#content').hide().load( url, function(){

			// Show new content
			$(this).fadeIn();
			
			// Remove loading class
			$('#content').removeClass('loading');
			
			// Restart the Slideshow with the new content
			startSlideshow();
			
		}); //load
		
	} //else

	}); //hashchange event

	// Since the event is only triggered when the hash changes, we need to trigger
	// the event now, to handle the hash the page may have loaded with.
	$(window).trigger( 'hashchange' );

}); //end document.ready

function startSlideshow() {
	
	// Add the placeholder for the number nav
	    $('.title h1').after(
		    	//'<div class="project-information">'
		    	'<ol class="numbers"></ol>'
				//+ '<ul class="read-more"><li><a class="toggle">Read More +</a></li></ul>'
				//+		'<ol class="numbers"></ol>'
				//+ '</div>'
	  );

	// Start Jquery cycle a.k.a. the slider
	// Looking for cycle options -- http://jquery.malsup.com/cycle/options.html
	$('.slideshow').find('ul').cycle({
			fx: 'scrollHorz',
			easing: 'swing',
			speed: 400,
			pager: '.numbers',
			activePagerClass: 'active',
			pagerAnchorBuilder: function(idx, slide) {
				return '<li><a href="#">' + (idx + 1) + '</a></li>';
			 }
		});
		
} //startSlideshow
