
var _global_trans_speed = 600;

function pageload(hash) {
	loading();
	if(!hash) { hash = 'home'; }
	var cl = hash.replace('/', '');
	$('body').attr('class', cl);
	if (cl != 'intro') { 
		$('div#main').css('display', 'block');
	}
	if (hash != 'intro') {
		$('h1 a').html('<span>CEO</span>');
	}
    pageTracker._trackPageview('/' + hash);
	var url = www_path + hash + '?ajax=' + Math.floor(Math.random()*100000);
	$("#main").load(url, function() { setAjaxLinks(); });
}

function loading() {
	$('body').attr('class', 'loading');
	$("#main").html('&nbsp;');
}
	
$(document).ready(function(){
	// fade intro
	$('body.intro h1').css('opacity', 0);
	$('body.intro h1').animate({ opacity:1.0 }, _global_trans_speed);
	$.historyInit(pageload, "/");
	setAjaxLinks();
});

function setAjaxLinks() {
	
	ajax_load = true;
	
	$("a[rel='history']").click(function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		hash = hash.replace(www_path, '');
		if ($(this).attr('class') == 'intro') {
			
			if ($('body').attr('class') != 'intro') {
				ajax_load = false;
			}
			
			else {
				$('body.intro h1').animate(
					{ opacity:0 }, 
					_global_trans_speed,
					'easeOutExpo',
					function() {
						loading();
						$('h1').animate({ opacity:1.0 }, _global_trans_speed);
						$.historyLoad(hash);
					}
				);
			}
		}
		
		else {
			loading();
			$.historyLoad(hash);
		}
		
		if (!ajax_load) {
			location.href = www_path;
		}
		return false;
		
	});
	
}

