// JavaScript Document

/**
 * Load components
 *
 * @uses jQuery
 * @version 1.0
 * @author Martin Walper
 * @link klickhere.com
 *
 */

;(function($)
{
	var TIMER;
	var COUNT = 0;
	var LOAD = [
		"resource/js/jquery/ui/jquery.ui.js",
		"resource/js/menu.js",
//		"resource/js/json.js",
		"resource/js/jquery/jquery.autocomplete.js",
//		"resource/js/jquery/jquery.history.js",
//		"resource/js/jquery/jquery.flydom.js",
//		"resource/js/jquery/jquery.sessionchk.js",
//		"resource/js/jquery/jquery.infotab.js",
		"resource/js/jquery/jquery.metadata.js",
		"resource/js/jquery/jquery.validate.js",
		"resource/js/jquery/jquery.validate.additional.js",
//		"resource/js/jquery/jquery.ifixpng.js",
		"resource/js/jquery/jquery.gatracker.js",

// add new plugins here


// have to stay at last
		"resource/js/layout.js"

	];
	var MAX = LOAD.length;


	$.loader = function()
	{
		$.each(LOAD, function (i,n)
		{
			$.ajax(
			{
				url:n,
				type: "GET",
				dataType:"script",
				global:false,
				success:onSuccess,
				error:onError
			});
		});

		TIMER = window.setTimeout("$.loader.timeout()", 5000);
	};

	$.loader.timeout = function()
	{
		onTimeout();
	}

	function onSuccess(msg)
	{
		COUNT++;
		if (COUNT == MAX)
		{
			onFinish();
		}
	}

	function onFinish()
	{
		window.clearTimeout(TIMER);
		loadAllways();
		loadByAction();
	}

	function onError(o,t,e)
	{
		$.log('Error loading file ! Script paused.');
		$.log(o);
	}

	function onTimeout()
	{
		$.log('Script timed out while loading critical files! Script aborted.');
		alert("A JavaScript timed out while loading dependent files!\nPlease refresh this page.");
	}

})(jQuery);

