var expand, collapse, distance, status, linkClicked;
status = "collapse";
function $$(id) {
	return document.getElementById(id);
}

window.onload = bodyLoaded;
window.onresize = bodyLoaded;

function bodyLoaded() {
	$$("sitemap").style.height = document.body.offsetHeight + "px";
	$$("wrapper").onmouseover = wrapperOver;
	$$("wrapper").onmouseout = wrapperOut;
	$$("sitemap").onclick = sitemapClick;
	if ($$("sitemap").getElementsByTagName("a")) {
		links = $$("sitemap").getElementsByTagName("a");
		for (i = 0; i < links.length; i++) {
			links[i].onclick = linksClick;
		}
	}
	if ($$("search").getElementsByTagName("input")) {
		input = $$("sitemap").getElementsByTagName("input");
		for (i = 0; i < input.length; i++) {
			input[i].onclick = linksClick;
			input[i].onfocus = linksClick;
			input[i].onblur = inputBlur;
		}
	}
}
function linksClick() {
	linkClicked = true;
}
function inputBlur() {
	linkClicked = false;
}
function wrapperOver() {
	$$("shadow").style.display = "block";
}
function wrapperOut() {
	if (status == "collapse") {
		if ($$("sitemap").style.left == "-277px" || $$("sitemap").style.left == "") {
			$$("shadow").style.display = "none";
		}
	}
}
function sitemapClick() {
	if (linkClicked != true) {
		if (status == "collapse") {
			status = "expand";
			if ($$("sitemap").style.left == "") $$("sitemap").style.left = "-277px";
			$$("shadow").style.display = "block";
			clearTimeout(collapse);
			showSitemap();
		} else {
			status = "collapse";
			clearTimeout(expand);
			hideSitemap();
		}
	}
}
function showSitemap() {
	distance = Math.round(parseInt($$("sitemap").style.left) / 12);
	if (distance >= -1) distance = -1;
	if (parseInt($$("sitemap").style.left) <= -8) {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) - distance) + "px";
		expand = setTimeout(showSitemap,1);
	} else if (parseInt($$("sitemap").style.left) <= -2) {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) + 1) + "px";
		expand = setTimeout(showSitemap,1);
	} else {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) + 1) + "px";
		clearTimeout(expand);
	}
}
function hideSitemap() {
	distance = Math.round((-277 - parseInt($$("sitemap").style.left)) / 12);
	if (distance >= -1) distance = -1;
	if (parseInt($$("sitemap").style.left) >= -269) {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) + distance) + "px";
		collapse = setTimeout(hideSitemap,1);
	} else if (parseInt($$("sitemap").style.left) >= -275) {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) - 1) + "px";
		collapse = setTimeout(hideSitemap,1);
	} else {
		$$("sitemap").style.left = (parseInt($$("sitemap").style.left) - 1) + "px";
		$$("shadow").style.display = "none";
		status = "collapse";
		clearTimeout(collapse);
	}
}function EmailCheck(value) {	var regexpMail =  /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;	if(regexpMail.test(value) == false) {      return false;   }}function FormCheckSendNews(form){ ErrorFlag=0;  if (form.Mail.value=='' || EmailCheck(form.Mail.value)==false) {  alert('Укажите правильный почтовый адрес для обратной связи!');  ErrorFlag=1; } if (form.Name.value=='') {  alert('Укажите название отправителя!');  ErrorFlag=1; } if (form.Subject.value=='') {  alert('Укажите тему письма!');  ErrorFlag=1; } if (form.SendText.value=='') {  alert('Выберите форму рассылки (новости или текст)!');  ErrorFlag=1; } if (form.SendToGroup.value=='') {  alert('Выберите адресатов рассылки (группу или отдельных подписчиков)!');  ErrorFlag=1; } if (ErrorFlag==1)  return false; confirm('Сейчас письмо будет разослано подписчикам. Вы уверены, что введенная информация корректна?'); return true;}


function init()  {
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);
}
function onFontResize(e,args) {
	$$("sitemap").style.height = document.body.offsetHeight + "px";
	$$("sitemap").style.height = document.body.scrollHeight + "px";
}
//id of element to check for and insert control
TextResizeDetector.TARGET_ELEMENT_ID = 'body';
//function to call once TextResizeDetector has init'd
TextResizeDetector.USER_INIT_FUNC = init;