function coreObject()
{
	/* данные */
	this.uid = '';
	this.tree = {};
	this.list = {};
	this.now = {};
	this.nowPage = {};
	//Если true - то будет отправлятся отчет по итоговому тестированию на почту
	this.sendTestReport = false;
	this.patterns =
	{
		defImages:'<div id="frameWrap"></div>',
		defTesting:
		'<div id="frameWrap" style="width:1024px; height:768px; background-color: transparent; background-image: url(img/start/bg.gif);" >'+
			'<div id="testingWrapOuter" class="testingWrapOuter" align="center">'+
				'<div id="testingWrap" class="testingWrap">'+
					'<div id="testingHead" class="testingHead">Вопрос №<span id="testing_number"></span> из <span id="testing_count"></span> <span id="multiple"></span></div>'+
					'<div id="testing_text" class="testing_text"></div>'+
					'<div id="testing_variants" class="testing_variants"></div>'+
					'<div id="testing_controls" class="testing_controls">'+
						'<div class="testing_control_left" id="testing_control_left"><img border="0px" src="img/buttons/back.gif" onmouseover="this.src=\'img/buttons/back_hover.gif\'" onmouseout="this.src=\'img/buttons/back.gif\'" onmousedown="this.src=\'img/buttons/back_press.gif\'" onclick="core.prev();" style="cursor: pointer;"></div>'+
						'<div class="testing_control_right" id="testing_control_right"><img border="0px" src="img/buttons/next.gif" onmouseover="this.src=\'img/buttons/next_hover.gif\'" onmouseout="this.src=\'img/buttons/next.gif\'" onmousedown="this.src=\'img/buttons/next_press.gif\'" onclick="core.next();" style="cursor: pointer;"></div>'+

						'<div id="soderjanie_btn"  class="testing_control_right" style="display:none;"><img border="0px" src="img/buttons/soderjanie.gif" onmouseover="this.src=\'img/buttons/soderjanie_hover.gif\'" onmouseout="this.src=\'img/buttons/soderjanie.gif\'" onmousedown="this.src=\'img/buttons/soderjanie_press.gif\'" onclick="core.view(\'toc\',0);" style="cursor: pointer;"></div>'+

						'<div id="testing_control_center" class="testing_control_center"><img id="testing_btn_check" border="0px" src="img/buttons/btn_testcheck.gif" onmouseover="this.src=\'img/buttons/btn_testcheck_hover.gif\'" onmouseout="this.src=\'img/buttons/btn_testcheck.gif\'" onmousedown="this.src=\'img/buttons/btn_testcheck_pressed.gif\'" onclick="core.testCheck();" style="cursor: pointer;"></div>'+
					'</div>'+
				'</div>'+
				'<div id="testingLine" class="testingLine"></div>'+
			'</div>'+
		'</div>',
		defTestingFull:
		'<div id="frameWrap" style="width:1024px; height:768px; background-color: transparent; background-image: url(img/start/bg.gif);">'+
			'<div id="result_block"></div>'+
			'<div id="testingWrapOuter" class="testingWrapOuter" align="center" >'+
				'<div id="report" style="display:none"></div>'+
				'<div id="testingWrap" class="testingWrap">'+
					'<div id="testingHead" class="testingHead">Вопрос №<span id="testing_number"></span> из <span id="testing_count"></span> <span id="multiple"></span></div>'+
					'<div id="testing_text" class="testing_text"></div>'+
					'<div id="testing_variants" class="testing_variants"></div>'+
					'<div id="testing_controls" class="testing_controls">'+
						'<div class="testing_control_left"><img id="testing_control_left" border="0px" src="img/buttons/back.gif" onmouseover="this.src=\'img/buttons/back_hover.gif\'" onmouseout="this.src=\'img/buttons/back.gif\'" onmousedown="this.src=\'img/buttons/back_press.gif\'" onclick="core.prev();" style="cursor: pointer;"></div>'+
						'<div class="testing_control_right"><img id="testing_control_right" border="0px" src="img/buttons/next.gif" onmouseover="this.src=\'img/buttons/next_hover.gif\'" onmouseout="this.src=\'img/buttons/next.gif\'" onmousedown="this.src=\'img/buttons/next_press.gif\'" onclick="core.next();" style="cursor: pointer;">  <img id="testing_btn_check" border="0px" src="img/buttons/btn_end.gif" onmouseover="this.src=\'img/buttons/btn_end_hover.gif\'" onmouseout="this.src=\'img/buttons/btn_end.gif\'" onmousedown="this.src=\'img/buttons/btn_end_pressed.gif\'" onclick="core.testCheckUnit();" style="display:none;cursor: pointer;"></div>'+
						'<div id="testing_control_center" class="testing_control_center"></div>'+
					'</div>'+
				'</div>'+
				'<div id="testingLine" class="testingLine"></div>'+
			'</div>'+
		'</div>',
		parts:
		{
			testing_radio: '<div class="testing_variant">'+
					'<input type="radio" onclick="core.testSet();" value="#NUM#" id="testing_variant_#NUM#" name="testing_variant" />'+
					'<label for="testing_variant_#NUM#"><div class="label">#TEXT#</div></label>'+
					'</div>',
			testing_check: '<div class="testing_variant">'+
					'<input type="checkbox" onclick="core.testSet();" value="#NUM#" id="testing_variant_#NUM#" />'+
					'<label for="testing_variant_#NUM#"><div class="label">#TEXT#</div></label>'+
					'</div>',
			testing_text: '<div class="testing_variant">'+
					'<input type="text" onchange="core.testSet();" onkeyup="core.testSet();" id="testing_variant_#NUM#" value="#TEXT#"/>'+
					'</div>'+
					'<div id="testing_text_answer"></div>',
			testing_text_right: '<div class="testing_text_right"></div>',
			testing_text_wrong: '<div class="testing_text_wrong">Правильный ответ: <span>#TEXT#</span></div>',
			testing_assoc_container: '<table class="testing_assoc_table"><tr><td><ol id="testing_assoc_table_left" class="testing_assoc_ol"></ol></td><td id="testing_assoc_table_right"></td></tr></table>',
			testing_assoc_ol_line: '<li id="testing_assoc_li_#NUM#">#TEXT#</li>',
			testing_assoc_div_line: '<div class="testing_variant">'+
					'<div class="testing_sort_answer" id="testing_answer_#NUM#"></div>'+
					'<button class="testing_sort_ord" id="testing_variant_#NUM#" onclick="core.testSet(this);"></button>'+
					'<div class="testing_sort_text">#TEXT#</div>'+
					'</div>',
			testing_sort: '<div class="testing_variant">'+
					'<div class="testing_sort_answer" id="testing_answer_#NUM#"></div>'+
					'<button class="testing_sort_ord" id="testing_variant_#NUM#" onclick="core.testSet(this);"></button>'+
					'<div class="testing_sort_text">#TEXT#</div>'+
					'</div>',
			testing_sort_btn: '<button id="testing_btn_sort" onclick="core.testFlush();">Сбросить</button>',
			testing_link: '|link|',
			testing_assoc: '<div class="testing_variant">'+
					'<div class="testing_sort_answer" id="testing_answer_#NUM#"></div>'+
					'<button class="testing_sort_ord" id="testing_variant_#NUM#" onclick="core.testSet(this);"></button>'+
					'<div class="testing_sort_text">#TEXT#</div>'+
					'</div>',
			areas_mark: '<div class="top"><div class="right"><div class="bottom"><div class="left"><div class="c1"><div class="c2"><div class="c3"><div class="c4"></div></div></div></div></div></div></div></div>',
			popups_right:'<table cellspacing="0" cellpadding="0" class="top"><tr><td class="left_top"></td><td class="center_top"></td><td class="right_top"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="center"><tr><td class="left"></td><td class="content">#TEXT#</td><td class="right"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="bottom_r"><tr><td class="left_bottom"></td><td class="center_bottom"></td><td class="right_bottom"></td></tr></table>',
			popups_right_top:	'<table cellspacing="0" cellpadding="0" class="top"><tr><td class="left_top_arrow"></td><td class="center_top_arrow"></td><td class="right_top_arrow"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="center"><tr><td class="left"></td><td class="content">#TEXT#</td><td class="right"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="bottom"><tr><td class="left"></td><td class="center"></td><td class="right"></td></tr></table>',
			popups_left: '<table cellspacing="0" cellpadding="0" class="top"><tr><td class="left_top"></td><td class="center_top"></td><td class="right_top"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="center"><tr><td class="left"></td><td class="content">#TEXT#</td><td class="right"></td></tr></table>'+
					'<table cellspacing="0" cellpadding="0" class="bottom_l"><tr><td class="left_bottom"></td><td class="center_bottom"></td><td class="right_bottom"></td></tr></table>',
			test_protocol: '<div class="testing_protokol_head">'+
					'<table><tr><th class="num">№</th><th class="text">Вопрос</th><th class="u_ans">Ваш ответ</th><th class="c_ans">Правильный ответ</th></tr></table></div>'+
					'<div class="testing_protokol_body"><table>#TEXT#</table>',
			test_protocol_send: '<div class="testing_protokol"><table><tr><th class="num">№</th><th class="text">Вопрос</th><th class="u_ans">Ваш ответ</th><th class="c_ans">Правильный ответ</th></tr>#TEXT#</table></div>'
		}
	};
	this.defaults = {page: {hideControls:false, locked:false, notCount:false, pattern:false, patternHTML:'', splash:false, viewed:false, images:[], areas:[], scripts:{initFrame:function(){}, startFrame:function(){}}, text:'', textStyle:'', textClass:'contentText'},
			pageTesting: {testing: {text:'', type:'none', answer:'', variants:[], userAnswers:'', done:false}},
			popup: {type:'right', text:'', count:'global', top:'0px', left:'0px', width:'100px', counter:0, disabled:false, el:false}/*,
			unitToc: {toc:{disableLink:false, hidden:false, name:false, opened:true, page:false, textTransform:'none'}}*/};
	this.blockload = {count:0, countReq:0, need:0, needReq:0, id:'', timeout:60000, done:false, splashTimeout: 1500, splashTimerIds:[]};
	this.divNum = 1;
	this.history = {data:[], pos:0};
	this.events = {};
	this.popups = {count:3, disabled:false, now:{}};
	this.bookmarks = [];
	this.previous = {id:'#', pos:'#'};
	this.restorePosition = false;

	this.restore = function restore()
	{
		if (this.restorePosition && this.uid == '')
		{
			var pos = cookies.get('prognoz_last_pos');
			if (!pos) return false;
			pos = decodeURIComponent(pos);
			pos = pos.split('|');
			if (typeof pos[0] != 'undefined' && typeof pos[1] != 'undefined')
			{
				this.uid = pos.join('|');
				this.view(pos[0], pos[1]);
				return true;
			};
		};
		return false;
	};
	this.save = function save()
	{
		if (this.restorePosition && this.uid != '')
		{
			cookies.set('prognoz_last_pos', encodeURIComponent(this.uid));
		};
	};
	/* переходы по разделу */
	this.current = function current(skipHistory)
	{
		/* пытаемся восстановить предыдущее положение в курсе */
		if (this.restore()) return true;

		/* загружает/перезагружает текущую страницу
		если в this.now.pos записана -1, то начинаем со стартовой страницы
		потом формируем контент текущей страницы */
		if (this.now.pos == -1)
			this.now.pos = this.now.start;
		if (!this.now.pages[this.now.pos]) return false;

		this.nowPage = this.now.pages[this.now.pos];
		this.now.posCountable = this.now.pages[this.now.pos].numCountable;
		this.uid = this.nowPage.id;

		/* Проверка на смену раздела */
		if (this.previous.id != this.now.id)
			this.handleEvent('onUnitChange');
		this.previous.id = this.now.id;
		this.previous.pos = this.now.pos;

		/* Шаг 1. Удяляем айдишки из переднего фрейма */
		this.contentDelIds();
		/* Шаг 2. Грузим шаблон */
		this.contentPattern();
		/* Шаг 3. Делаем попапы */
		this.contentPopups();
		/* Шаг 4. Делаем всякие области */
		this.contentAreas();
		/* Шаг 5. Показываем текст слайда */
		this.contentText();
		/* Шаг 6. Запускаем предпоказные дела */
		this.contentInit();
		this.handleEvent('oninit');
		/* Шаг 7. Грузим картинки */
		this.contentImages();
		/* Шаг 8. Стартуем фрейм */
		this.contentStart(skipHistory);
		/* Шаг 9. Настоящий старт происходит внутри верхней функции при выполнении условий */
		/* Шаг 10. Добавляем загрузившуюся страницу в историю, тамже где и предыдущий */
		return true;
	};
	this.contentFinish = function contentFinish(skipHistory)
	{
		this.blockload.done = true;
		this.splashHide();
		this.swapDiv();
		this.nowPage.viewed = true;
		this.contentPopupsFinish();
		if (!skipHistory)
			this.add();
		if (typeof infobox != 'undefined' && infobox.init && this.nowPage.infobox)
			infobox.init(this.nowPage.infobox);
		if (typeof sound != 'undefined' && sound.open && this.nowPage.sound)
			sound.open(this.nowPage.sound);
		this.nowPage.scripts.startFrame();
		this.save();
		this.handleEvent('onstart');
	};
	this.first = function first()
		{for (var i = 0; i < this.now.pages.length; i++) if (this.now.pages[i] && !this.now.pages[i].locked) {this.now.pos = i; this.current();break;}};
	this.last = function last()
		{for (var i = this.now.pages.length - 1; i >= 0; i--) if (this.now.pages[i] && !this.now.pages[i].locked) {this.now.pos = i; this.current(); break;}};
	this.next = function next()
	{
		for (var i = this.now.pos + 1; i < this.now.pages.length; i++)
			if (this.now.pages[i] && !this.now.pages[i].locked)
			{
				this.now.pos = i;
				this.current();
				return true;
			}
		return false;
	};
	this.prev = function prev()
	{
		for (var i = this.now.pos - 1; i >= 0; i--)
			if (this.now.pages[i] && !this.now.pages[i].locked)
			{
				this.now.pos = i;
				this.current();
				return true;
			}
		return false;
	};
	this.nextThru = function nextThru()
		{return this.thru(true);};
	this.prevThru = function prevThru()
		{return this.thru(false);};
	this.thru = function thru(forward)
	{
		if ((forward && !this.next()) || (!forward && !this.prev()))
		{
			var path = this.thruRecurent(this.tree, this.now.id, '', [], forward);
			if (path == false) return false;
			path = path.reverse();
			for (var i = 0; i < path.length; i++)
			{
				if (this.list[path[i]].toc.disableLink == true || this.list[path[i]].toc.hidden == true)
					continue;
				else
				{
					this.now = this.list[path[i]];
					if (forward)
						this.first();
					else
						this.last();
					return true;
				}
			}
			return false;
		}
		else
			return true;
	};
	this.thruRecurent = function thruRecurent(list, id, route, path, reverse)
	{
		var ids = [];
		for (var i in list)
			ids.push(i);
		if (reverse)
			ids = ids.reverse();
		for (var i = 0; i < ids.length; i++)
		{
			if (ids[i] == id)
			{
				return path;
			}
			else
			{
				path.push(ids[i]);
				route += ','+ids[i];
				var res = this.thruRecurent(list[ids[i]].sub, id, route, path, reverse);
				if (res !== false)
					return res;
			}
		}
		return false;
	};
	this.view = function view(id, pos, skipHistory)
	{
		/* просмотр любого слайда в дереве */
		if (id && this.list[id]) /* если существует такой раздел */
		{
			pos = parseInt(pos);
			this.now = this.list[id];
			this.now.pos = (!isNaN(pos))?pos:-1; /* передаем "-1" - значит начинаем со стартовой */
			this.current(skipHistory);
		}
	};
	/* история */
	this.add = function add()
	{
		if (this.history.data[this.history.pos-1] &&
		    this.history.data[this.history.pos-1].id == this.now.id &&
		    this.history.data[this.history.pos-1].pos == this.now.pos)
			return false;
		this.history.data[this.history.pos++] = {id: this.now.id, pos:this.now.pos};
		return true;
	};
	this.back = function back()
	{
		if (this.history.data[this.history.pos-2])
		{
			this.view(this.history.data[this.history.pos-2].id, this.history.data[this.history.pos-2].pos, true);
			this.history.pos--;
		}
	};
	this.forward = function forward()
	{
		if (this.history.data[this.history.pos])
		{
			this.view(this.history.data[this.history.pos].id, this.history.data[this.history.pos].pos, true);
			this.history.pos++;
		}
	};
	/* закладки */
	this.bookmark = function bookmark(name)
	{
		this.bookmarks.push({uid:this.uid, name:name});
		cookies.set('prognozLastBookmark', parseInt(cookies.get('prognozLastBookmark'))+1);
		this.bookmarkSet();
	};
	this.bookmarkToggle = function bookmarkToggle()
	{
		var el = $('bookmark_panel');
		if (el.style.display == 'none')
		{
			var last = cookies.get('prognozLastBookmark');
			if (typeof last == 'undefined')
			{
				cookies.set('prognozLastBookmark', 1);
				last = 1;
			}
			$('bm_input').value = 'Закладка '+last;
			el.style.display = 'block';
		}
		else
		{
			el.style.display = 'none';
		}
	};
	this.bookmarkCheck = function bookmarkCheck()
	{
		if ($('bm_input').value)
			$('bookmark_btn').disabled = false;
		else
			$('bookmark_btn').disabled = true;
	};
	this.bookmarkGo = function bookmarkGo(id)
	{
		if (this.bookmarks[id])
		{
			var bm = this.bookmarks[id].uid.split('|');
			if (typeof bm[0] != 'undefined' && typeof bm[1] != 'undefined')
				this.view(bm[0], bm[1]);
		}
	};
	this.bookmarkDel = function bookmarkDel(id)
	{
		delete this.bookmarks[id];
		this.bookmarkSet();

	};
	this.bookmarkGet = function bookmarkGet()
	{
		this.bookmarks = [];
		var in_ = cookies.get('prognozBookmarks');
		if (!in_) return;
		in_ = decodeURIComponent(in_);
		in_ = in_.split('|#|');
		for (var i = 0, len = in_.length; i < len; i++)
			if (in_[i] != '')
			{
				var bm = in_[i].split('|@|');
				if (bm[0] && bm[1])
					this.bookmarks.push({uid:bm[0],name:bm[1]});
			}
	};
	this.bookmarkSet = function bookmarkSet()
	{
		var out = [];
		for (var i = 0, len = this.bookmarks.length; i < len; i++)
		{
			if (this.bookmarks[i])
				out.push(this.bookmarks[i].uid+'|@|'+this.bookmarks[i].name);
		}
		out = out.join('|#|');
		cookies.set('prognozBookmarks', encodeURIComponent(out), 99);
	};

	/* тесты */
	this.testGet = function testGet()
	{
		var type = this.nowPage.testing.type;
		var userAnswers = this.nowPage.testing.userAnswers;
		var answer = this.nowPage.testing.answer;
		var variants = this.nowPage.testing.variants;
		var done = this.nowPage.testing.done;
		if (type == 'text')
			$('testing_variant_0').value = this.nowPage.testing.userAnswers;
		else if ((type == 'check' || type == 'radio') && userAnswers != '')
		{
			userAnswers = userAnswers.split(',');
			for (var i = 0; i < userAnswers.length; i++)
				$('testing_variant_'+userAnswers[i]).checked = true;
		}
		else if (type == 'sort')
		{
			userAnswers = userAnswers.split(',');
			/* Сбрасываем ответы */
			for (var i = 0; i < variants.length; i++)
			{
				var variant = $('testing_variant_'+i);
				if (variant)
				{
					variant.innerHTML = '...';
					variant._sortId = i;
					variant.disabled = false;
				}
			}
			/* устанавливаем ответы пользователя */
			for (var i = 0; i < userAnswers.length; i++)
			{
				var variant = $('testing_variant_'+userAnswers[i]);
				if (variant)
				{
					variant.innerHTML = (i+1);
					variant.disabled = true;
				}
			}
		}
		else if (type == 'assoc'){
			var varLen=variants.length - answer.split(',').length;
			userAnswers = userAnswers.split(',');
			for (var i = 0; i < varLen; i++)
			{
				var variant = $('testing_variant_'+i);
				if (variant)
				{
					variant.innerHTML = '...';
					variant._sortId = i;
					variant.disabled = false;
				}
			}
			/* устанавливаем ответы пользователя */
			for (var i = 0; i < varLen; i++)
			{
				var variant = $('testing_variant_'+userAnswers[i]);
				if (variant)
				{
					variant.innerHTML = (i+1);
					variant.disabled = true;
				}
			}
		}
		if (done)
			this.testCheck();
		//не лочим тесты
		if (this.now.testing.type == 'full' && this.now.testing.done == true)
			this.testDisable();


	};
	this.testSet = function testSet(element)
	{
		var type = this.nowPage.testing.type;
		var userAnswers = this.nowPage.testing.userAnswers;
		var answer = this.nowPage.testing.answer;
		var variants = this.nowPage.testing.variants;
		var done = this.nowPage.testing.done;
		if (type == 'text')
		{
			var el = $('testing_variant_0');
			if (el) this.nowPage.testing.userAnswers = el.value;
		}
		if (type == 'check' || type == 'radio')
		{
			var userAnswers = [];
			var pos = 0;
			while (el = $('testing_variant_'+pos))
			{
				if (el.checked)
					userAnswers.push(pos);
				pos++;
			}
			userAnswers = userAnswers.join(',');
			this.nowPage.testing.userAnswers = userAnswers;
		}
		if (type == 'sort')
		{
			var userAnswers = (userAnswers != '') ? userAnswers.split(','): [];
			if (typeof element._sortId == 'undefined') return;
			if (userAnswers.length >= variants.length) return;
			for (var i = 0; i < userAnswers.length; i++)
				if (userAnswers[i] == element._sortId) return;
			userAnswers.push(element._sortId);
			element.innerHTML = userAnswers.length;
			element.disabled = true;
			this.nowPage.testing.userAnswers = userAnswers.join(',');
		}
		if (type == "assoc"){
			var userAnswers = (userAnswers != '') ? userAnswers.split(','): [];
			var countUserAnswers = variants.length - answer.split(',').length;
			if (typeof element._sortId == 'undefined') return;
			userAnswers.push(element._sortId);
			element.innerHTML = userAnswers.length;
			element.disabled = true;
			this.nowPage.testing.userAnswers = userAnswers.join(',');
			if (userAnswers.length == answer.split(',').length) {
				for (var i=0; i<countUserAnswers; i++){

					$('testing_variant_'+i).disabled=true;
					$('testing_variant_'+i).innerHTML = ($('testing_variant_'+i).innerHTML == '...') ? '':$('testing_variant_'+i).innerHTML;
				};
			}

		}
		this.testInk(this.nowPage);
	};
	this.testCheck = function testCheck(page, silent)
	{
		if (typeof silent == 'undefined')
			silent = false;
		if (typeof page == 'undefined')
			page = this.nowPage;
		var type = page.testing.type;
		var userAnswers = page.testing.userAnswers;
		var answer = page.testing.answer;
		var variants = page.testing.variants;
		if (type == 'radio' && this.testAnswered(page) == 0) {if (!silent) alert('Вы должны выбрать ответ!'); return false;}
		if (type == 'check' && this.testAnswered(page) == 0) {if (!silent) alert('Вы должны выбрать ответы!'); return false;}
		if (type == 'text' && this.testAnswered(page) == 0) {if (!silent) alert('Вы должны ввести ответ!'); return false;}
		if (type == 'sort')
		{
			if (this.testAnswered(page) == 0) {if (!silent) alert('Вы должны выбрать последовательность!'); return false;}
			userAnswers = userAnswers.split(',');
			answer = answer.split(',');
			if (userAnswers.length < answer.length) {if (!silent) alert('Вы должны выбрать последовательность до конца!'); return false;}
			var ok = true;
			for (var i = 0; i < answer.length; i++)
				if (userAnswers[i] != answer[i]) ok = false;
			var css = (ok)?' testing_sort_right':' testing_sort_wrong';
			for (var i = 0; i < variants.length; i++)
			{
				var el = $('testing_answer_'+answer[i]);
				if (el)
				{
					el.className += css;
					el.innerHTML = i+1;
				}
			}

		}
		if (type == 'assoc'){
			if (userAnswers == '') {if (!silent) alert ('Вы должны указать соответствие'); return false;};
			userAnswers = userAnswers.split(',');
			answer = answer.split(',');
			if (userAnswers.length != answer.length) {if (!silent) alert('Вы должны выбрать последовательность до конца!'); return false;}
			var ok = true;
			for (var i = 0; i < answer.length; i++)
				if (userAnswers[i] != answer[i]) ok = false;
			var css = (ok)?' testing_sort_right':' testing_sort_wrong';
			for (var i = 0; i < answer.length; i++)
			{
				var el = $('testing_answer_'+answer[i]);
				if (el)
				{
					el.className += css;
					el.innerHTML = i+1;
				}
			}
		}
		page.testing.done = true;
		this.testDisable();
		this.testLight();
		return true;
	};
	this.testCheckUnit = function testCheckUnit(id)
	{
		var ok = true;
		if (typeof id == 'undefined') id = this.now.id;
		if (typeof this.list[id] == 'undefined') return false;
		var unit = this.list[id];
		unit.testing.correct = 0;
		unit.testing.total = 0;
		var showed = false;
		for (var i = 0; i < unit.pages.length; i++)
		{
			var page = unit.pages[i];
			if (typeof page.testing == 'undefined') continue;
			var ans = this.testAnswered(page);
			if (ans == 0)
			{
				if (!showed){
					this.view(page.id.split('|')[0], page.id.split('|')[1]);
					showed = true;
				};
				ok = false;
			}
			else if (ans == 2)
			{
				unit.testing.correct++;
			}
			unit.testing.total++;
		}
		if (ok == false && confirm('У вас имеются не отвеченные вопросы.\nВы действительно хотите закончить тестирование?'))
			ok = true;
		if (ok)
		{
			unit.testing.done = true;
			this.testDisable();
			this.handleEvent('onTestingUnitChecked', id);
		}
		return ok;
	};
	this.testFlush = function testFlush()
	{
		this.nowPage.testing.userAnswers = '';
		this.testGet();
		this.testInk(this.nowPage);
	};

	this.testDisable = function testDisable() //Лочим контролы
	{
		var el;
		var pos = 0;
		while (el = $('testing_variant_'+(pos++))) {el.disabled = true;};
		el = $('testing_btn_check');
		if (el) el.style.display = 'none';
		el = $('testing_btn_sort');
		if (el) el.disabled = true;
	};
	this.testLight = function testLight() // Выделение цветом ответов слушателя
	{
		var type = this.nowPage.testing.type;
		var userAnswers = this.nowPage.testing.userAnswers;
		var answer = this.nowPage.testing.answer;
		if (type == 'check' || type == 'radio')
		{
			answer = ','+answer+',';
			var pos = 0;
			while (el = $('testing_variant_'+pos))
			{
				if (answer.indexOf(','+pos+',') != -1)
					el.parentNode.className += ' testing_right';
				else
					el.parentNode.className += ' testing_wrong';
				pos++;
			}
		}
		else if (type == "text")
		{
			var el = $('testing_variant_0');
			if (el)
			{
				if (this.testAnswered(this.nowPage) == 2)
				{
					$('testing_text_answer').innerHTML = this.patterns.parts.testing_text_right;
					el.parentNode.className += ' testing_right';
				}
				else
				{
					$('testing_text_answer').innerHTML = this.patterns.parts.testing_text_wrong.split('#TEXT#').join(this.nowPage.testing.answer);
					el.parentNode.className += ' testing_wrong';
				}
			}
		}
	};

	this.testLine = function testLine() //Линия под тестами
	{
		$('testingLine').innerHTML = '';
		if (this.now.testing.type != 'full') return;
		var width = 100/this.now.pages.length;
		var out = '<table cellspacing="0" cellpadding="0" id="testingLineTable" class="testingLineTable"><tr>';
		for (var i = 0; i < this.now.pages.length; i++)
		{
			out += '<td id="line_cell_'+i+'" class="'+(this.testAnswered(this.now.pages[i])?' viewed ':'')+(this.now.pos == i?' now ':'')+'" style="width:'+width+'%;">'+
				'<a id="line_cell_a_0" href="javascript:core.view(\''+this.now.id+'\', '+i+');" />'+
				//'<a id="line_cell_a_0" href="javascript://" />'+
				'</td>';
		}
		out += '</tr></table>';
		$('testingLine').innerHTML = out;
	};

	this.testAnswered = function testAnswered(page)
	{
		var userAnswers = page.testing.userAnswers;
		var type = page.testing.type;
		var answer = page.testing.answer;
		if (userAnswers == '' && type == 'radio') {return 0;}
		if (userAnswers == '' && type == 'check') {return 0;}
		if (type == 'text')
		{
			if (userAnswers == '') {return 0;}
			var answer2 = '|'+answer.join('|')+'|';
			if (answer2.toLowerCase().indexOf('|'+userAnswers.toLowerCase()+'|') != -1)
				return 2;
			else
				return 1;
		}
		if (type == 'sort')
		{
			if (userAnswers == '') {return 0;}
			userAnswers = userAnswers.split(',');
			answer = answer.split(',');
			if (userAnswers.length < answer.length) {return 0;}
			userAnswers = userAnswers.join(',');
			answer = answer.join(',');
		}
		if (type == 'assoc')
		{
			if (userAnswers == '') {return 0;}
			if (userAnswers.split(',').length < answer.split(',').length) {return 0;}
		}
		if (userAnswers.toLowerCase() == answer.toLowerCase())
			return 2;
		return 1;
	};



	this.testInk = function testInk(page)
	{
		var el = $('line_cell_'+page.num);
		if (!el) return;
		if (this.testAnswered(page))
		{
			if (el.className.indexOf('viewed') == -1)
				el.className += ' viewed ';
		}
		else
			el.className = el.className.replace('viewed', '');
	};

	//Вывод результата тестирования
	this.testShowResult = function testShowResult(core, id)
	{
		var unit = core.list[id];
		if (!unit)
		{
			alert('Не верный раздел');
			return;
		}
		if (unit.testing.done != true)
		{
			alert('Вы не закончили тестирование в разделе');
			return;
		}
		var passMark = unit.testing.passMark;
		var percent = parseInt((unit.testing.total==0?0:unit.testing.correct/unit.testing.total)*100);
		var out = core.patterns.parts.test_protocol.split('#TEXT#').join(core.getTestProtocol());
        if(core.sendTestReport && location.href.split('//')[0] != 'file:')
        {
			var outToSend = core.patterns.parts.test_protocol_send.split('#TEXT#').join(core.getTestProtocol());
			var r={
				method:'post',
				url:((location.href.split('//')[0] != 'file:')? location.href.split('//')[0]+'//'+ location.href.split('//')[1].split('/')[0]: 'http://v-study-el.prognoz.ru')+'/interviewing_course/test.php',
				post:{'report': outToSend, 'percent': percent, 'passMark': passMark, 'userFIO': (typeof core.userFIO != 'undefined' && core.userFIO != '' && core.userFIO != ' ')? core.userFIO:'ФИО не было указано'}
			};
			request(r);
		};
		var html =
		'<div><br><h3 align="center">Результат</h3></div>'+
		'<div class="data_test">'+
			'<div class="result_label">Ваш результат:</div>'+
			'<div class="scale my">'+
				'<div id="percent_my" class="percent">'+percent+'%</div>'+
				'<div id="inner_my" class="inner" style="width: '+percent+'%;"/></div>'+
			'</div>'+
			'<div class="result_label">Проходной балл:</div>'+
			'<div class="scale system">'+
				'<div id="percent_system" class="percent">'+passMark+'%</div>'+
				'<div id="inner_system" class="inner" style="width: '+passMark+'%;"/></div>'+
			'</div>'+
			'<div class="result_text">'+(percent>=passMark?'<br>Тест сдан':'<br>Тест не сдан')+'</div>'+
			'</div>'+
			'<div class="testing_result">'+
				'<img style="float: left; padding-left:20px; cursor: pointer;" id="rep_btn" border="0px" src="img/buttons/rep.gif" onmouseover="this.src=\'img/buttons/rep_hover.gif\'" onmouseout="this.src=\'img/buttons/rep.gif\'" onmousedown="this.src=\'img/buttons/rep_press.gif\'" onclick="toggle(\'report\'); this.src=\'img/buttons/rep.gif\';">'+
				'<img style="float: right; padding-right:20px; cursor: pointer;" id="toc_btn" border="0px" src="img/buttons/soderjanie.gif" onmouseover="this.src=\'img/buttons/soderjanie_hover.gif\'" onmouseout="this.src=\'img/buttons/soderjanie.gif\'" onmousedown="this.src=\'img/buttons/soderjanie_press.gif\'" onclick="core.view(\'toc\',0);">'+
			'</div>';
		var frameWrap = $('frameWrap');

		frameWrap.innerHTML = '';
		var div = dom.create('div', {'innerHTML':html, 'id':'result_block', 'class':'result_block'});
		frameWrap.appendChild(div);
		var div = dom.create('div', {'innerHTML':out, 'align':'center', 'id':'report', 'class':'report'}, false, {display: 'none'});
		frameWrap.appendChild(div);
		step(['navfloat', 'head_pb'],[]);
//		core.swapDiv();
	};

	//Возвращает протокло итогового тестирования
	this.getTestProtocol = function getTestProtocol()
	{
		function getTestProtocolString(testing, result, answers)
		{
	    	var testing_ul = '<ul>#TEXT#</ul>'
	    	var testing_li = '<li>#TEXT#</li>'
	    	var type = 'u_answers';
	    	if(typeof answers == 'undefined')
	    	{
	    		result = 2;
	    		type = 'c_answers';
			};
	    	answers = (typeof answers == 'undefined')? testing.answer: answers;
            var ans = ((typeof answers == 'string')? answers.split(','): answers);
	    	var out = '';
	    	if(result != 0 )
	    	{
	    		if (testing.type == 'text')
	    			out =  testing_li.split('#TEXT#').join(ans.join(', '));
	    		else if(testing.type == 'training')
					(type == 'u_answers')? out = ((result == 2)? testing_li.split('#TEXT#').join('Были совершены верные действия'):testing_li.split('#TEXT#').join('Были совершены неверные действия')):'';
	    		else if (testing.type == 'assoc')
	    		{
	               	for(var i = 0; i < ans.length; i++)
	               	{
	               		var j = Number(i+testing.variants.length/2);
	               		out += testing_li.split('#TEXT#').join('<b>'+testing.variants[j]+'</b> - '+testing.variants[ans[i]]);
	               	};
	    		}
	    		else if(testing.type == 'sort')
	    		{
	               	for(var i = 0; i < ans.length; i++)
	               	{
	               		out += testing_li.split('#TEXT#').join((i+1)+'&nbsp;'+testing.variants[ans[i]]);
	               	};
	    		}
	    		else
	    		{
	               	for(var i = 0; i < ans.length; i++)
	               	{
	               		out += testing_li.split('#TEXT#').join(testing.variants[ans[i]]);
	               	};
	    		};
	    	}
	    	else out = testing_li.split('#TEXT#').join('Ответ&nbsp;не&nbsp;был&nbsp;дан');
      		return (out != '')? testing_ul.split('#TEXT#').join(out): '&nbsp;';
		};

    	var out = '';
    	for (var i = 0; i < core.now.pages.length; i++)
    	{
	    	var page = core.now.pages[i];
	    	var result = core.testAnswered(page);
	    	var userAnswers = page.testing.userAnswers;
	    	out += '<tr class="'+((result == 2)? 'green':'red')+'"><td class="num">'+(i+1)+'</td><td class="text">'+page.testing.text+'</td><td class="u_ans">'+getTestProtocolString(page.testing, result, userAnswers)+'</td><td class="c_ans">'+getTestProtocolString(page.testing)+'</td></tr>'
		};
		return out;
	}

	this.popupsWrong = function popupsWrong(id)
	{
		var now = false;

		if (typeof id == 'undefined')
			now = this.popups.now;
		else
			now = this.nowPage.popups[id];
		if (now && now.el && !this.popups.disabled)
		{
			var max = (now.count == 'global')?this.popups.count:now.count;
			now.counter++;
			if (now.counter >= max)
			{
				now.el.style.display = 'block';
				now.el.style.left = now.computedLeft+'px';
				now.el.style.top = now.computedTop+'px';
			}
		}
	};
	this.popupsSet = function popupsSet(id)
	{
		this.popupsReset();
		var now = this.nowPage.popups[id];
		if (now && now.el)
			this.popups.now = now;
	};

	this.popupsReset = function popupsReset()
	{
		this.popups.now = {};
		for (var i = 0; i < this.nowPage.popups.length; i++)
		{
			this.nowPage.popups[i].el.style.display = 'none';
			this.nowPage.popups[i].counter = 0;
		}
	};

	/* для внутреннего пользования */
	this.frontDiv = function frontDiv()
	{
		return $('frameWrapOuter'+this.divNum);
	};
	this.backDiv = function backDiv()
	{
		var num = (this.divNum == 1)?2:1;
		return $('frameWrapOuter'+num);
	};
	this.swapDiv = function frontDiv()
	{
		this.frontDiv().style.display = 'none';
		this.backDiv().style.display = 'block';
		this.divNum = (this.divNum == 1)?2:1;
	};

	this.parse = function parse(id)
	{
		/* штуковина, которая из плоского вида отстроит дерево в this.tree */
		this.parseRecurent(this.tree);
		if (this.uid == '')
			this.handleEvent('onfirststart');
		core.bookmarkGet();
		if (!this.parseLocation())
			this.view(id);
	};
	this.parseLocation = function parseLocation()
	{
		var loc = location.href;
		loc = loc.split('?');
		if (typeof loc[1] == 'undefined') return;
		loc = loc[1].split('&');
		var get = {};
		for (var i = 0; i < loc.length; i++)
		{
			var pair = loc[i].split('=');
			if (typeof pair[0] != 'undefined' && typeof pair[1] != 'undefined')
				get[pair[0]] = pair[1];
		};
		var locked = false;
		if (typeof get.locked != 'undefined' && get.locked == 'true')
			locked = true;
		if (typeof get.unit != 'undefined')
		{
			this.view(get.unit);
			return true;
		}
		return false;
	};
	this.parseRecurent = function parseRecurent(root)
	{
		var sub = false;
		for (var i in root)
		{
			if (!root[i].sub) root[i].sub = {};
			if (this.list[i])
			{
				sub = root[i].sub;
				root[i] = this.list[i];
				root[i].sub = sub;
				root[i].id = i;
				root[i].inTree = true;
				this.setDefaults(root[i]);
				this.parseRecurent(root[i].sub);
			}
			else
			{
				delete root[i];
			}
		}
	};
	this.setDefaults = function setDefaults(node)
	{
		/* Умолчания для раздела */
		node.name = node.name || 'Без названия';
		node.start = node.start || 0;
		node.pos = node.pos|| 0;
		node.notCount = node.notCount || false;
		node.pages = node.pages || [];
		node.length = node.pages.length || 0;
		node.testing = node.testing || {};
		node.testing.type = node.testing.type || 'mixed';
		node.testing.correct = node.testing.correct || 0;
		node.testing.total = node.testing.total || 0;
		node.testing.passMark = node.testing.passMark || 50;
		/*this.setDefaultsPage(node, this.defaults.unitToc);*/
		node.posCountable = 0;
		node.lengthCountable = 0;
		for (var i = 0; i < node.pages.length; i++)
		{
			/* умолчание по типу страницы: от него потом зависит парсинг */
			node.pages[i].type = node.pages[i].type || 'images';
			node.pages[i].type = node.pages[i].type.toLowerCase();

			if (node.pages[i].type == 'testing')
			{
				/* умолчания для тестов */
				this.setDefaultsPage(node.pages[i], this.defaults.pageTesting);
				node.pages[i].testing.type = node.pages[i].testing.type.toLowerCase();
				if (node.pages[i].testing.type == 'text' && node.pages[i].testing.variants.length != 1)
					node.pages[i].testing.variants = [''];
			}
			/* умолчания для всех разделов */
			this.setDefaultsPage(node.pages[i], this.defaults.page);
			/* поверх них то что указал пользователь */
			if (typeof node.pageDefault != 'undefined' && node.pageDefault)
				this.setDefaultsPage(node.pages[i], this.defaults[node.pageDefault]);

			/* умолчания для попапов */
			node.pages[i].popups = node.pages[i].popups || [];
			for (var j = 0; j < node.pages[i].popups.length; j++)
			{
				this.setDefaultsPage(node.pages[i].popups[j], this.defaults.popup);
				node.pages[i].popups[j].type = node.pages[i].popups[j].type.toLowerCase();
			}
			/* вычислимые показатели */
			node.pages[i].num = i;
			node.pages[i].id = node.id+'|'+i;
			node.pages[i].numCountable = node.lengthCountable;
			if (!node.pages[i].notCount)
				node.lengthCountable++;
		}
	};
	this.setDefaultsPage = function setDefaultsPage(page, def)
	{
		for (var i in def)
			if (typeof def[i] != 'object' || typeof def[i].length == 'number')
				page[i] = page[i] || def[i];
			else
			{
				page[i] = page[i] || {};
				this.setDefaultsPage(page[i], def[i]);
			}
	};

	this.contentDelIds = function contentDelIds()
	{
		for (var i = 0; i < this.frontDiv().childNodes.length; i++)
			this.contentDelIdsRecurent(this.frontDiv().childNodes[i]);
	};
	this.contentDelIdsRecurent = function contentDelIdsRecurent(node)
	{
		if (node.nodeType == 1) node.removeAttribute('id');
		for (var i = 0; i < node.childNodes.length; i++)
			this.contentDelIdsRecurent(node.childNodes[i]);
	};
	this.contentPattern = function contentPattern()
	{
		/*
		 В этой функции проявляется различие между разными типами слайдов
		 по умолчанию тип 'images' - самый просто и основной
		*/

		if (this.nowPage.splash)
			this.splashShow();
		else
			this.splashHide();

		var out = '';
		if 	(this.nowPage.patternHTML)
			out = this.nowPage.patternHTML;
		else if (this.nowPage.pattern && this.patterns[this.nowPage.pattern])
			out = this.patterns[this.nowPage.pattern];
		else
		{
			if (this.nowPage.type == 'images')
				out = this.patterns.defImages;
			else if (this.now.testing.type == 'mixed' && this.nowPage.type == 'testing')
				out = this.patterns.defTesting;
			else if (this.now.testing.type == 'full' && this.nowPage.type == 'testing')
				out = this.patterns.defTestingFull;
		}

		this.backDiv().innerHTML = out;

		/* если слайд - тестирования, запускаем пост-процессор */
		if (this.nowPage.type == 'testing')
			this.testingPattern();
	};

	this.testingPattern = function testingPattern()
	{
		var data = this.nowPage.testing;
		/* заголовок */
		var textEl = $('testing_text');
		if (textEl) textEl.innerHTML = data.text;
		var countEl = $('testing_count');
		var numberEl = $('testing_number');
		if (countEl) countEl.innerHTML = this.now.lengthCountable;
		if (numberEl) numberEl.innerHTML = this.now.posCountable+1;
		/* варианты ответов */
		var variantsEl = $('testing_variants');
		if (variantsEl && data.type == 'check'){
			$('multiple').innerHTML = '&nbsp;(может иметь несколько вариантов ответа)';

		}
		if (variantsEl && data.type != 'assoc')
		{
			if(data.variants.length > 5)
			{
				var testingContent = '';
				testingContent += '<table width="100%" border="0"><tr><td valign="top">';
				for (var i = 0; i < data.variants.length; i++)
				{
					var part = this.patterns.parts['testing_'+data.type];
					part = part.split('#NUM#').join(i);
					part = part.split('#TEXT#').join(data.variants[i]);
					testingContent += part;
					((i+1) == 5)? testingContent += '</td><td valign="top">': '';
				};
				testingContent += '</td></tr></table>';
				variantsEl.innerHTML += testingContent;
			}
			else
			{
				for (var i = 0; i < data.variants.length; i++)
				{
					var part = this.patterns.parts['testing_'+data.type];
					part = part.split('#NUM#').join(i);
					part = part.split('#TEXT#').join(data.variants[i]);
					variantsEl.innerHTML += part;
				};
			};
		} else if (variantsEl && data.type == 'assoc'){
			variantsEl.innerHTML=this.patterns.parts['testing_assoc_container'];
			var assoc_left=$('testing_assoc_table_left');
			var assoc_right=$('testing_assoc_table_right');
			var ansLen=data.answer.split(',').length;
			var varLen=(data.variants.length-data.answer.split(',').length);

			for (var i=0; i< ansLen; i++){
				var part = this.patterns.parts['testing_assoc_ol_line'];
				part = part.split('#NUM#').join(i);
				part = part.split('#TEXT#').join(data.variants[i+varLen]);
				assoc_left.innerHTML += part;
			};
			for (var i=0; i< varLen; i++){
				var part = this.patterns.parts['testing_assoc_div_line'];
				part = part.split('#NUM#').join(i);
				part = part.split('#TEXT#').join(data.variants[i]);
				assoc_right.innerHTML += part;
			}
		}
		/* контролы */
		var leftEl = $('testing_control_left');
		if (leftEl && this.now.posCountable == 0)
			leftEl.style.visibility = 'hidden';
		var rightEl = $('testing_control_right');
		var soderjanie_btn = $('soderjanie_btn');

		if (rightEl && (this.now.posCountable+1) == (this.now.lengthCountable) && this.now.testing.type == 'full')
		{
			rightEl.style.visibility = 'hidden';
		};

		if (rightEl && (this.now.posCountable+1) == (this.now.lengthCountable) && this.now.testing.type == 'mixed')
		{
			rightEl.style.display = 'none';
			soderjanie_btn.style.display = 'block';
		};



		var centerEl = $('testing_control_center');
		if (centerEl && data.type == 'sort')
			//Помещаем кнопку "сбросить" под варианты ответов
			$('testing_variants').innerHTML += '<div style="padding: 10px 0px 0px 39px;">'+this.patterns.parts.testing_sort_btn+'</div>';
		if (centerEl && data.type == 'assoc')
			$('testing_variants').innerHTML += '<div style="padding: 10px 0px 0px 191px;">'+this.patterns.parts.testing_sort_btn+'</div>';
		var checkEl = $('testing_btn_check');
		if (checkEl && this.now.testing.type == 'full' && (this.now.posCountable+1) == (this.now.lengthCountable))
			checkEl.style.display = '';
		/* рисуем линейку снизу */
		this.testLine();
		/* заполняем ответами пользователя */
		this.testGet();
	};

	this.contentPopups = function contentPopups()
	{
		if (!this.nowPage.popups)
		{
			this.popups.now = {};
			return;
		}
		if (this.nowPage.popups.length > 0)
			this.popups.now = this.nowPage.popups[0];
		for (var i = 0; i < this.nowPage.popups.length; i++)
		{
			var popup = this.nowPage.popups[i];
			popup.counter = 0;
			popup.id = 'popup_'+i;
			var left = popup.left;
			var top = popup.top;
			var inner = '';
			if (popup.type == 'right')
				inner = this.patterns.parts.popups_right.split('#TEXT#').join(popup.text);
			else if (popup.type == 'left')
				inner = this.patterns.parts.popups_left.split('#TEXT#').join(popup.text);
			else if (popup.type == 'right_top')
				inner = this.patterns.parts.popups_right_top.split('#TEXT#').join(popup.text);
			var el = dom.create('div', {id:popup.id, 'class':'popup', innerHTML: inner}, false, {width: popup.width, left: left, top:top, visibility:'hidden'});
			popup.el = el;
			this.backDiv().appendChild(el);
		}
	};

	this.contentPopupsFinish = function contentPopupsFinish()
	{
		for (var i = 0; i < this.nowPage.popups.length; i++)
		{
			var el = this.nowPage.popups[i].el;
			var popup = this.nowPage.popups[i];
			if (popup.type == 'right')
			{
				popup.computedLeft = el.offsetLeft - el.clientWidth + 33;
				popup.computedTop = el.offsetTop - el.clientHeight;
			}
			else if (popup.type == 'right_top')
			{
				popup.computedLeft = el.offsetLeft - el.clientWidth + 33;
				popup.computedTop = el.offsetTop;
			}
			else if (popup.type == 'left')
			{
				popup.computedLeft = el.offsetLeft - 32;
				popup.computedTop = el.offsetTop - el.clientHeight;
			}
			el.style.display = 'none';
			el.style.visibility = 'visible';
		}
	};

	this.contentAreas = function contentAreas()
	{
		for (var i = 0; i < this.nowPage.areas.length; i++)
		{
			var area = this.nowPage.areas[i];
			area.attrs = area.attrs || {};
			area.attrs.id = area.attrs.id || 'area_'/*+this.nowPage.id+'_'*/+i; // айдишник по-умолчанию
			area.style = area.style || {};
			area.attrs['class'] = ((area.attrs['class'])?area.attrs['class']:'');
			area.attrs['class'] += ' area ';
			var el = dom.create('div', area.attrs, false, area.style);

			if (area.type && area.type.toLowerCase() == 'mark')
				el.innerHTML = this.patterns.parts.areas_mark;

			this.backDiv().appendChild(el);
		}
	};

	this.contentText = function contentText()
	{
		if (this.nowPage.text != '')
		{
			var styleStr = '';
			var styleObj = {};
			if (typeof this.nowPage.textStyle == 'string')
				styleStr = this.nowPage.textStyle;
			else
				styleObj = this.nowPage.textStyle;
			var el = dom.create('div', {innerHTML: this.nowPage.text, 'class': this.nowPage.textClass, style: styleStr}, false, styleObj);
			$('frameWrap').appendChild(el);
		}
	};

	this.contentInit = function contentInit()
	{
		for (var i in this.nowPage.scripts)
			if (i != 'initFrame' && i != 'startFrame')
			{
				window.eval(i+' = '+this.nowPage.scripts[i]);
			}
		this.nowPage.scripts.initFrame();
	};
	this.contentImages = function contentImages()
	{
		this.blockload.id = this.nowPage.id;
		this.blockload.done = false;
		this.blockload.count = 0;
		this.blockload.countReq = 0;

		var countReq = 0;
		var count = 0;
		for (var i = 0; i < this.nowPage.images.length; i++)
		{
			if (this.nowPage.images[i].req) countReq++;
			count++;
		}
		this.blockload.need = count;
		this.blockload.needReq = countReq;

		for (var i = 0; i < this.nowPage.images.length; i++)
		{
			if (!this.nowPage.images[i].path) continue;
			this.nowPage.images[i].div = 		this.nowPage.images[i].div || 'frameWrap'; // див по-умолчанию
			this.nowPage.images[i].attrs = 		this.nowPage.images[i].attrs || {}; // чтобы были хотябы пустые атрибуты
			this.nowPage.images[i].attrs.id = 	this.nowPage.images[i].attrs.id || 'img_'+/*this.nowPage.id+'_'*/+i; // айдишник по-умолчанию
			this.nowPage.images[i].style = 		this.nowPage.images[i].style || {}; // чтобы был хотябы пустой стиль
			this.nowPage.images[i].req = 		this.nowPage.images[i].req || false; // обязательность картинки
			var el = dom.create('img', this.nowPage.images[i].attrs, false, this.nowPage.images[i].style);
			el.unit_id = this.nowPage.id;
			el.req = this.nowPage.images[i].req;
			el.core = this;
			el.onload = this.imageLoaded;
			//el.src = this.nowPage.images[i].path; // src
			setTimeout('core.imageLoad(\''+this.uid+'\', \''+this.nowPage.images[i].attrs.id+'\', \''+this.nowPage.images[i].path+'\');', 100);
			$(this.nowPage.images[i].div).appendChild(el);
		}
		setTimeout('core.splashTimeout(\''+this.nowPage.id+'\')', this.blockload.timeout);
	};

	this.imageLoad = function imageLoad(uid, id, url)
	{
		var ee = $(id);
		if (ee && uid == this.uid)
			ee.src = url;
	};

	this.imageLoaded = function imageLoaded()
	{
		if (this.unit_id == this.core.blockload.id)
		{
			this.core.blockload.count++;
			if (this.req)
			{
				this.core.blockload.countReq++;
			}
			this.core.contentStart();
		}
	};

	this.contentStart = function contentStart(skipHistory)
	{
		if (!this.blockload.done)
			if (this.blockload.countReq == this.blockload.needReq)
			{
				this.contentFinish(skipHistory);
			}
			else
				if (this.nowPage.splash)
					this.splashShow();
	};
	this.splashShow = function splashShow()
	{
		this.blockload.splashTimerIds.push(setTimeout('core.splashShow2()', this.blockload.splashTimeout));
	};
	this.splashShow2 = function splashShow2()
	{
		$('frameWrapSplash').style.display = 'block';
		//$('frameWrapSet').style.display = 'none';
		if (this.blockload.countReq > this.blockload.needReq) this.blockload.countReq = this.blockload.needReq;
		$('frameWrapSplash_x').innerHTML = this.blockload.countReq;
		$('frameWrapSplash_y').innerHTML = this.blockload.needReq;
		if (this.blockload.needReq)
			$('frameWrapSplash_pbIn').style.width = this.blockload.countReq/this.blockload.needReq*100+'%';
	};
	this.splashHide = function splashHide()
	{
		for (var i = 0; i < this.blockload.splashTimerIds.length; i++)
			clearTimeout(this.blockload.splashTimerIds[i]);
		this.blockload.splashTimerIds = [];
		$('frameWrapSplash').style.display = 'none';
		//$('frameWrapSet').style.display = '';
	};
	this.splashTimeout = function splashTimeout(id)
	{
		if (id == this.blockload.id && !this.blockload.done)
		{
			this.contentFinish();
			alert('by timeout');
		}
	};
	this.status = function status(id, this_core)
	{
		if (!this_core) this_core = this;
		if (!this_core.list[id]) return 0;

		var unit = this_core.list[id];
		var total = 0;
		var count = 0;

		for (var i in unit.sub)
		{
			total += 2;
			count += status(i, this_core);
		}

		if (!unit.notCount)
		{
			for (var i = 0; i < unit.pages.length; i++)
				if (!unit.pages[i].notCount )
				{
					total += 2;
					if (unit.pages[i].viewed)
						count +=2;
				}
		}
		if (count == 0 || total == 0) return 0;
		if (total == count) return 2;
		return 1;
	};
	this.addEventListener = function addEventListener(ev, func)
	{
		ev = ev.toLowerCase();
		if (!this.events[ev])
			this.events[ev] = [];
		this.events[ev].push(func);
	};
	this.handleEvent = function handleEvent(ev, params)
	{
		ev = ev.toLowerCase();
		if (!this.events[ev]) {this.events[ev] = {}; return;}
		for (var i = 0; i < this.events[ev].length; i++)
			this.events[ev][i](this, params);
	};

	//Поиск родительского элемента
	this.getParentUnitID = function getParentUnitID(root, idUnit)
    {
		var idParentUnit;
        for (var i in root)
        {
            for(var j in root[i].sub)
            {
				if(root[i].sub[j].id == idUnit)
				{
	        		idParentUnit = root[i].id;
	        		return idParentUnit;
				};
                idParentUnit = getParentUnitID(root[i].sub, idUnit);
                if(typeof idParentUnit != 'undefined') return idParentUnit;
            };
     	};
     	return idParentUnit;
    };
    //Возвращает полный заголовок раздела
	this.getFullTitle = function getFullTitle()
	{
		var idUnit = this.now.id;
		var fullTitle = "";
		fullTitle = this.list[idUnit].name;
		var idParentUnit = this.getParentUnitID(this.tree, idUnit);
		if(typeof idParentUnit == 'undefined')
			return fullTitle
		else
		{			while(typeof idParentUnit != 'undefined')
			{
				fullTitle = this.list[idParentUnit].name+' - '+fullTitle;
				idParentUnit = this.getParentUnitID(this.tree, idParentUnit);
			};
			return fullTitle;		};
	};
}
var core = false;
