
/***************************************************************
****************************************************************
**
** /htdocs/froomity/resources/pub/../development/js/own/Function.js
**
****************************************************************
****************************************************************/

/**
 * Function extension.
 */

Function._callQueue = [];
Function._loaded = false; 

Function.callQueue = function()
{
	Function._loaded = true;
	
	var queue = Function._callQueue;
	for (var i = 0, l = queue.length; i + 3 <= l; i += 3)
	{
		// instead of queueing an object we insert three elements (lower memory consumption)
		queue[i + 0].apply(queue[i + 1], queue[i + 2]);
	}
	
	Function._callQueue = [];
};

Function.prototype.queue = Function.prototype.queueFunction = function()
{
	if (Function._loaded)
	{
		this.apply(window, arguments);
	}
	else
	{
		Function._callQueue.push(this);
		Function._callQueue.push(window);
		Function._callQueue.push(arguments);
	}
	return false; // cancel event
};

Function.prototype.queueMethod = function()
{
	var args = [];
	for (var i = 1, l = arguments.length; i < l; ++i)
	{
		args.push(arguments[1]);
	}

	if (Function._loaded)
	{
		this.apply(arguments[0], args);
	}
	else
	{
		Function._callQueue.push(this);
		Function._callQueue.push(arguments[0]);
		Function._callQueue.push(args);
	}
	return false; // cancel event
};

/***************************************************************
****************************************************************
**
** /htdocs/froomity/resources/pub/../development/js/own/Page.js
**
****************************************************************
****************************************************************/

/**
 * Page class.
 */

function Page()
{
}

Page._domLoaded = false;
Page._jsLoaded = false;

Page.loaded = function(obj, func)
{
	if (Page._domLoaded && Page._jsLoaded)
	{
		return true;
	}

	if (obj == null)
	{
		obj = window;
	}
	if (typeof func == 'string')
	{
		func = obj[func];
	}

	func.queueMethod(obj);
	return false;
};

Page.checkLoaded = function()
{
	return Page._domLoaded && Page._jsLoaded;
};

Page._setDOMLoaded = function()
{
	Page._domLoaded = true;
	if (Page.checkLoaded())
	{
		Function.callQueue();
	}
};

Page._setJSLoaded = function()
{
	Page._jsLoaded = true;
	if (Page.checkLoaded())
	{
		Function.callQueue();
	}
};
