
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		$(".splash").fadeOut('slow', function() {
	       	 	
			// 	Send an AJAX request to get all the states.
			    $.get( hash + '?tp=1', function(response) {
			    
			        // 	Append the response to the div.
			       	 	$(".splash").html( '' );
			       	 	$(".splash").html( response );	
			       	 	$(".splash").fadeIn('slow', function() {
			       	 		getApple();	
			       	 	});
			       	 	
			    }); 
		});	

	} else {
		// start page
			$(".splash").fadeOut('slow', function() {
	       	 	
			// 	Send an AJAX request to get all the states.
			    $.get( 'home' + '?tp=1', function(response) {
			    
			        // 	Append the response to the div.
			       	 	$(".splash").html( '' );
			       	 	$(".splash").html( response );	
			       	 	$(".splash").fadeIn('slow', function() {
			       	 	});
			       	 	
			    }); 
		});	
	}
}

$(document).ready(function(){
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$.history.init(pageload);
	
	// set onlick event for buttons
	$("a[rel=history]").click(function(){
		cancelClass(); 
		$(this).parent().addClass('active');
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		$.history.load(hash);
		return false;
	});
	
});
