var G = {
	data: null
};
function loadPage(pageName) {
	$("#contentWrapper").animate({opacity: 0}, 200,
		function() {
			$.post("index.php",{p: pageName},
				function(data) {
					$("#contentWrapper").html(data);
					if ($.browser.mozilla)
						document.title = "On-Track Cleaners :: "+pageName[0].toUpperCase()+pageName.substr(1);
					$("#contentWrapper").animate({opacity: 100}, 200,
						function() {
							$(window).focus();
							window.focus();
							$.cookie('lastPage', pageName);
						});
				});
		});
}

function showLogin() {
	$.getScript("js/otcmodal.js", function() {
		$.getScript("js/otcmodal.class.login.js", function() {
			$.get("data/otcmodal.php?action=login", function(data){
				if (data == 'true')
					loadPage('account');
				else
					$(data).modal({
						close: false,
						overlayId: 'otcmodal-overlay',
						containerId: 'otcmodal-container',
						onOpen: otcmodal_login.open,
						onShow: otcmodal_login.show,
						onClose: otcmodal_login.close,
						persist: true
					});
			});
		});
	});
}

$(document).ready(function() {
	var lastPage = $.cookie('lastPage');
	var direct = $.cookie('direct');
	if (lastPage != null && direct == null) {
		loadPage(lastPage);
	}
	$.cookie('direct',null);
});
