/*
systym: the NIH-syndrome javascript library
copyright (c) 2009 Chris Rose-Mathew
*/

/*==============================================================
This file is where the active part of your website gets started.
A startup function is assigned to run upon the windows.onload event.
In your case, the "window.onload" event might already have other
event handling functions attached. These will be overwritten.
The current version of systym does not support multiple
onload event handlers.
================================================================*/

//================================================================
// This is the main log object.
// It is placed here as a global to allow other files to
// reference it in IE.
//================================================================
log = null;

//================================================================
// This is the system scene object.
// It is placed here as a global to allow other files to
// reference it in IE.
//================================================================
scene = null;

//================================================================
// coreStart()
//================================================================
// This function is the bootstrap function assigned to window.onload
//================================================================
function coreStart()
{
	//================================================================
	// Boot up utility helper module
	//================================================================
	utils = new Utils()
	
	//================================================================
	// Boot up the system log.
	// "loggingElementId" is the id of an element in the HTML document. 
	//================================================================
	var loggingElementId = "mainContent";
	log = new Log(loggingElementId);
	log.addItem("systym front-end framework - version 0.1");
	log.addItem("developed by Chris Rose-Mathew");
	log.addItem("starting up...");
	log.addItem("current time is :");
	log.addItem(new Date());

	//================================================================
	// Create and setup the scene.
	// "theStage" is the id of an element in the HTML document.
	//================================================================
	scene = new Scene("theStage");

	// Setup scene update tick
	window.setInterval("scene.tick()", scene.frameMilliseconds);

	// Trigger the main presentation after some time has been left for
	// the loading of resources such as images and other page content
	window.setTimeout("startPresentation()", scene.loadingTimeSeconds * 1000);
}

//================================================================
// startPresentation()
//================================================================
// This function triggers the main interactive features of your web applicaion
// This function is designed to be called after a timeout has elapsed, giving
// page resources time to load.
// Currently simply calls into the scene object to being it's work.
//================================================================
function startPresentation()
{
	scene.startPresentation();
}

//================================================================
// coreBrowserViewportResize()
//================================================================
// This function is assigned to the browser's window.onresize event handler
// It triggers a resize of the scene.
//================================================================
function coreBrowserViewportResize()
{
	if (scene)
		scene.resize();
}

//================================================================
// getElement(idText)
//================================================================
// Retrieve a document node with a given ID, which must be
// a text string.
//================================================================
function getElement(idText)
{
	return document.getElementById(idText);
}

//================================================================
// getBodyElement()
//================================================================
// Retrieve a the document's body element in a cross-browser
// manner, or a "surrounds" element which can help IE correctly
// crop scene items to the browser viewport when it is
// specified with overflow: hidden.
//================================================================
function getBodyElement()
{
	var surroundsElement = document.getElementById("surrounds");
	if (surroundsElement)
		return surroundsElement;
	
	// If no surrounds, return the actual body
	if (document.body)
		return document.body;
	return document.getElementsByTagName("body")[0];
}

/*============================================================
This is the kickoff point for all javascript code.
Once the page HTML is fully downloaded and the above
functions and variables defined - set up the primary event handlers.
==============================================================*/
window.onload = coreStart;
window.onresize = coreBrowserViewportResize;

