var curPage = null;

$(function()
{
	var random = Math.floor(Math.random() * 8);
	$('body').css('background', '#fff url(/images/bg' + (random + 1) + '.jpg) top left no-repeat');

	$.ajaxSetup(
	{
		cache: false
	});

	$("#loading").ajaxSend(function()
	{
		$(this).show();
	})
	.ajaxStop(function()
	{
		$(this).slideUp();
	});

	/*$('a.amenu').click(function()
	{
		var anchor = this.href.substr(this.href.indexOf('#') + 1);
		loadPage(anchor + '.' + getExt(anchor));
	});*/

	$('#theme-icons > img').click(function()
	{
		var id = this.src.split('-')[2].replace(/\.(gif|jpg|png)/, '');
		$('body').css('background', '#fff url(/images/bg' + id + '.jpg) top left no-repeat');
	});

	/*var anchor = document.location.hash.substring(1);

	if(anchor.length > 0)
	{
		var callback = null;
		try
		{
			callback = eval('list' + anchor.substring(0, 1).toUpperCase() + anchor.substring(1));
		}
		catch(e) {}

		if($.isFunction(callback))
			loadPage(anchor + '.' + getExt(anchor), callback);
		else
			loadPage(anchor + '.' + getExt(anchor))
	}*/
});

function getExt(anchor)
{
	return (anchor == 'projects' || anchor == 'links' || anchor == 'sharings' || anchor == 'awards') ? 'php' : 'shtml';
}

function loadPage(url, callback)
{
	if(curPage == url)
		return;

	$.get(url, function(data)
	{
		curPage = url;

		$('#main').html(data);

		if($.isFunction(callback))
			callback(url);
	});
}