<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">
	<xsl:variable name="eAuScripts">
		<script type="text/javascript" defer="true">
			// Порядок выполнения скриптов меняется, если используются алерты
			// ПОЭТОМУ В ЭТОМ БОЛОКЕ КОДА НИ В КОЕМ СЛУЧАЕ НЕЛЬЗЯ ИСПОЛЬЗОВАТЬ
			// АЛЕРТ, только если точно знаешь что делаешь и используюешь
			// дебажную версию eAuthor
			if (window.eAu_Course) {
				if (typeof window.eAu_Course.onloadTimeOut != 'undefined') {
					clearTimeout(window.eAu_Course.onloadTimeOut);
				}
			}

			window.eAu_Course = {};
			window.eAu_Course.projectFolderURL = '<xsl:value-of select="$project-url"/>';
			window.eAu_Course.loadedScripts = {};
			window.eAu_Course.onloadHandlers = [];
			window.eAu_Course.onloadHappened = false;

			window.eAu_Course.preloadScript = function (strFileName) {
				var documentBodyPath = window.eAu_Course.projectFolderURL
					 , currentScriptIndex = strFileName.replace(/(\/|-|\.)/g, '_')
					 , axObject;

				if (typeof window.eAu_Course.loadedScripts[currentScriptIndex] != 'undefined')
					return false;

				window.eAu_Course.loadedScripts[currentScriptIndex] = 'loading';
				axObject = new ActiveXObject("MSXML2.XMLHTTP.4.0");
				axObject.open("GET", documentBodyPath + strFileName, false);
				axObject.onreadystatechange = function () {
					if (axObject.readyState == 4) {
						if (axObject.responseText) {
							window.eAu_Course.loadedScripts[currentScriptIndex] = 'loaded';
							
							try {
								eval(axObject.responseText);
							} catch (error) {}
						} else {
							window.eAu_Course.loadedScripts[currentScriptIndex] = window.undefined;
						}
					}
				};
				try {
					axObject.send(null);
				} catch (error) {
					axObject.onreadystatechange = null;
					window.eAu_Course.loadedScripts[currentScriptIndex] = window.undefined;
					return false;
				}
				return true;
			}

			window.eAu_Course.preloadScript('template-files/json2.js');
			window.eAu_Course.preloadScript('template-files/underscore.js');
			window.eAu_Course.preloadScript('template-files/eau.js');
			window.eAu_Course.preloadScript('template-files/jquery.js');
			if (window.jQuery) { jQuery.noConflict(); }
			window.eAu_Course.preloadScript('template-files/script.js');

			window.eAu_Course.onload = function (f) {
				if (typeof f != 'function')
					return;
				if (_.indexOf(window.eAu_Course.onloadHandlers, f) != -1)
					return;

				window.eAu_Course.onloadHandlers.push(f);
				if (window.eAu_Course.onloadHappened) {
					f();
				}
			}

			window.eAu_Course.onloadTimeOut = _.delay(function () {
				_.invoke(window.eAu_Course.onloadHandlers, 'call');
				window.eAu_Course.onloadHappened = true;
			});

			var body = document.getElementsByTagName("body");
			if (body) {
				if (body[0]) {
					body[0].onselectstart = function(e) {
						return _.indexOf(['input', 'button', 'textarea', 'select', 'option'], window.event.srcElement.tagName.toLowerCase()) != -1;
					}
				}
			}
		</script>
	</xsl:variable>
</xsl:stylesheet>

