var back = "";

// 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);
	//alert("pageload back: " + back);
	// 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 едц.
			hash = encodeURIComponent(hash);
		}
		$("#main").toggle("blind", {}, 500);
		$("#"+hash).toggle("clip", {}, 500);
	} else {
		// start page
		$("#"+back).toggle("clip", {}, 500);
		$("#main").toggle("blind", {}, 500);
	}
}

$(document).ready(function(){
	$("#about").hide();
	$("#coding").hide();
	$("#contact").hide();
	
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$.historyInit(pageload, "index.html");
	
	// set onlick event for buttons
	$("#aboutlink").click(function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		back = hash;
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
		return false;
	});
	
	$("#codelink").click(function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		back = hash;
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
		return false;
	});
	
	$("#contactlink").click(function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		back = hash;
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
		return false;
	});
		
	return false;
});