﻿	// PageLoad function
	// 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) {
		// alert("pageload: " + hash);
		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() function does't work when hash include special characters like aao.
				hash = encodeURIComponent(hash);
			}
			$("#content").load("data/" + hash + ".txt");
			
		} else {
			// start page
			$("#content").empty();
			//$("#content").load("data/home.txt");
			}
	}
	
	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload, "jquery_history.html");
		
		// set onlick event for buttons
		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"
			$.historyLoad(hash);
			return false;
		});
	});
