/*	Inland Calendar Project - main.js
	External JS file for the main template.
	
	Creator: Nik Molnar ©2007	*/

var overlayVisible = false;
var showAnimation = false;
var animationFrame = 0;

function showOverlay() {
	if (!overlayVisible) {
		document.getElementById("p_overlay").style.display = "block";
		document.getElementById("p_overlay_bottom").style.overflow = "auto";
		Spry.Effect.Blind("p_overlay", {duration: 1000, from: '0px', to: '440px'});
		setTimeout('overlayVisible = true', 1000);
	}
}

function hideOverlay() {
	if (overlayVisible) {
		Spry.Effect.Blind("p_overlay", {duration: 500, from: '390px', to: '0px'});
		setTimeout('document.getElementById("p_overlay").style.display = "none"', 500);
		document.getElementById("p_overlay_bottom").style.overflow = "visible";
		setTimeout('overlayVisible = false', 500);
	}
}

function viewCalendar(calendarPage) {
	if (overlayVisible) {
		hideOverlay();
	}
	else {
		window.location = calendarPage;
	}
}

function loadingAnimation() {
	var text;
	
	if (showAnimation) {
		switch (animationFrame) {
			case 0:
				text = "L";
				animationFrame = 1;
				break;
			
			case 1:
				text = "Lo";
				animationFrame = 2;
				break;
			
			case 2:
				text = "Loa";
				animationFrame = 3;
				break;
			
			case 3:
				text = "Load";
				animationFrame = 4;
				break;
			
			case 4:
				text = "Loadi";
				animationFrame = 5;
				break;
			
			case 5:
				text = "Loadin";
				animationFrame = 6;
				break;
				
			case 6:
				text = "Loading";
				animationFrame = 7;
				break;
				
			case 7:
				text = "Loading.";
				animationFrame = 8;
				break;
				
			case 8:
				text = "Loading..";
				animationFrame = 9;
				break;
				
			case 9:
				text = "Loading...";
				animationFrame = 0;
				break;
		}
		
		document.getElementById("page_content").innerHTML = "Loading. Please wait.\n<h1>" + text + "</h1>";
		
		setTimeout('loadingAnimation()',200);
	}
}

function loadPage(pageURL) {
	document.getElementById("page_content").innerHTML = "Loading. Please wait.";
	showOverlay();
	
	showAnimation = true;
	loadingAnimation();
	
	//Send request
	var page = new Spry.Data.XMLDataSet(pageURL, "/page", {useCache: false});
	page.addObserver(pageLoaded);
	page.loadData();
}

function pageLoaded(notification, dataSet, data) {
	if(notification == "onPostLoad") {
		document.getElementById("page_title").innerHTML = dataSet.getData()[0]['title'];
		document.getElementById("page_content").innerHTML = dataSet.getData()[0]['body'];
		
		showAnimation = false;
	}
}
