//Функции меню
var __ControlsForHide;
function ControlsForHide() {
	if (is_ie) {
		args = ControlsForHide.arguments;
		for (i = 0; i < (args.length); i += 1) {
			__ControlsForHide = new Array();
			__ControlsForHide[i] = args[i];
		}
	}
}
function HideControlOpenClose(isopen) {
	var obj, show;
	if (__ControlsForHide != null) {
		if (isopen == true) show = "visible"; else show = "hidden";
		for (i = 0; i < (__ControlsForHide.length); i += 1) {
			if ((obj = document.getElementById(args[i])) != null) {
				obj.style.visibility = show;
			}
		}
	}
}

function hMClose(index, select) {
	var td_hM = document.getElementById("td_hM_" + index);
	td_hM.setAttribute("expand", "close");
	HideControlOpenClose(true);
	window.setTimeout("__hMClose(" + index + ", " + select + ")", 100);
}
function __hMClose(index, select) {
	var td_hM = document.getElementById("td_hM_" + index);
	if (td_hM.getAttribute("expand") == "close") {
		td_hM.setAttribute("expand", null);
		var hM = document.getElementById("hM_" + index);
		if (select) hM.className = "hMCS"; else hM.className = "hMC";
		ExpandPanel("hME_" + index, false, true, 0);
	}
}
function hMExp(index, popup) {
	var td_hM = document.getElementById("td_hM_" + index);

	var expand = td_hM.getAttribute("expand");
	if (expand == null || expand == "" || expand == "null" || expand == "close") {
		var hM = document.getElementById("hM_" + index);

		HideControlOpenClose(false);
		hM.className = "hMO";
		td_hM.setAttribute("expand", "open");
		if (popup) ExpandPanel("hME_" + index, true, true, 0);
	}
}
function hMIO(index, popup) {
	var td_hM = document.getElementById("td1_hM_" + index);
	var expand = td_hM.getAttribute("expandItem");
	if (expand == null || expand == "" || expand == "null" || expand == "close") {
		td_hM.setAttribute("expandItem", "true");
		hMenuItemChangeClass(index, true, popup);
		if (popup) {
			var hME = document.getElementById("hME_" + index);
			if (hME.style.display != "") {
				hME.style.position = "absolute";
				hME.style.overflow = "visible";
				hME.style.display = "";
				hMenuItemMove(index);
			}
		}
		td_hM.setAttribute("expandItem", null);
	}
}
function hMenuItemMove(index) {
	var hME = document.getElementById("hME_" + index);
	var m = getElementPosition(hME.id);
	var clientWidth = 0;
	if (is_ie) clientWidth = window.Body.clientWidth; else clientWidth = self.innerWidth;
	if (clientWidth < (m.left + m.width)) {
		var l = parseInt(hME.style.left); if (isNaN(l)) l = 0;
		hME.style.left = l - m.width + 2;
	}
}
function hMIC(index, popup) {
	var td_hM = document.getElementById("td1_hM_" + index);
	var expand = td_hM.getAttribute("expandItem");
	if (expand != "closeStart") {
		td_hM.setAttribute("expandItem", "close");
		window.setTimeout("__hMenuItemOut('" + index + "'," + popup + ")", 0);
	}
}
function __hMenuItemOut(index, popup) {
	var td_hM = document.getElementById("td1_hM_" + index);
	var expand = td_hM.getAttribute("expandItem");
	if (expand == "close") {
		td_hM.setAttribute("expandItem", "closeStart");
		hMenuItemChangeClass(index, false, popup);
		if (popup) {
			var hME = document.getElementById("hME_" + index);
			hME.style.display = "none";
			hME.style.left = "";
		}
		td_hM.setAttribute("expandItem", null);
	}
}
function hMenuItemChangeClass(index, over, popup) {
	var className = "hMPO";	if (!over) className = "hMPC";
	var td1 = document.getElementById("td1_hM_" + index);
	var currentclass = td1.className;
	if (currentclass == className) return;
	td1.className = className;
	document.getElementById("td2_hM_" + index).className = className;
	document.getElementById("td3_hM_" + index).className = className;
	document.getElementById("td4_hM_" + index).className = className;
	document.getElementById("a_hM_" + index).className = className;
	if (popup) {
		var img = document.getElementById("hMenuAr" + index);
		if (over) img.className = "menu_arh2"; else img.className = "menu_arh1";
	}
}

function vMExp(index, popup) {
	vMenuItemChangeClass(index, true, popup);
	
	if (popup) {
		var td_vM = document.getElementById("td_vM_" + index);
		var expand = td_vM.getAttribute("expand");
		if (expand == null || expand == "" || expand == "null" || expand == "close") {
			td_vM.setAttribute("expand", "open");
			ExpandPanel("hME_" + index, true, true, 2);
			HideControlOpenClose(false);
		}
	}
}
function vMClose(index, popup) {
	vMenuItemChangeClass(index, false, popup);
	if (popup) {
		var td_vM = document.getElementById("td_vM_" + index);
		td_vM.setAttribute("expand", "close");
	}
	window.setTimeout("__vMClose('" + index + "', " + popup + ")", 100);
}
function __vMClose(index, popup) {
	if (popup) {
		var td_vM = document.getElementById("td_vM_" + index);
		if (td_vM.getAttribute("expand") == "close") {
		td_vM.setAttribute("expand", null);
			ExpandPanel("hME_" + index, false, true, 2);
			HideControlOpenClose(true);
		}
	}
}
function vMenuItemChangeClass(index, over, popup) {
	var className = "vMO";	if (!over) className = "vMC";
	var td = document.getElementById("td_vM_" + index);
	var currentclass = td.className;
	if (currentclass == className) return;
	td.className = className;
	document.getElementById("a_vM_" + index).className = className;
	if (popup) {
		var img = document.getElementById("vMenuAr" + index);
		if (over) img.className = "menu_arv2"; else img.className = "menu_arv1";
	}
}



function ExpandPanel(id, show, display, mode) {
	var element = document.getElementById(id);
	if (element == null) return;
	
	var width = parseInt(element.style.width); if (isNaN(width)) width = parseInt(element.clientWidth);
	var height = parseInt(element.style.height); if (isNaN(height)) height = parseInt(element.clientHeight);
	var hide = (display && element.style.display == "none") || (!display && element.style.visibility == "hidden");
	var expand = element.getAttribute("expand"); if (expand == "null" || expand == "") expand = null;
	if (show) {
		if (hide) {
			if (expand == null) {
				if (display) element.style.display = ""; else element.style.visibility = "visible";
				width = parseInt(element.style.width); if (isNaN(width)) width = parseInt(element.clientWidth);
				height = parseInt(element.style.height); if (isNaN(height)) height = parseInt(element.clientHeight);
				if ("12".indexOf(mode) != -1) element.style.width = 1;
				if ("01".indexOf(mode) != -1) element.style.height = 1;
				element.setAttribute("expand", "open");
				__ExpandPanel(id, width, height, display, mode);
			}
		} else {
			if (expand != null) element.setAttribute("expand", "open");
		}
	} else {
		if (expand == null) {
			element.setAttribute("expand", "close");
			__ExpandPanel(id, width, height, display, mode);
		} else {
			if (!hide && expand != null) element.setAttribute("expand", "close");
		}
	}
}
function __ExpandPanel(id, width, height, display, mode) {
	var dOpen = 10;
	var dClose = 3;
	var timerOpen = 15;
	var timerClose = 15;
	
	var element = document.getElementById(id);
	var expand = element.getAttribute("expand");
	var d = dOpen;
	var timer = timerOpen; 
	if (expand == "close") {
		d = dClose;
		timer = timerClose;
	}
	
	element.style.overflow = "hidden";
	element.style.position = "absolute";

	var w = parseInt(element.style.width);
	var h = parseInt(element.style.height);
	var wd = parseInt(width / d); if (wd == 0) wd = 1;
	var hd = parseInt(height / d); if (hd == 0) hd = 1;
	
	if (expand == "open") {
		var flg = false;
		if ("12".indexOf(mode) != -1) {
			if (w + wd < width) {
				element.style.width = w + wd;
				flg = true;
			} else {
				flg = false;
			}
		}
		if ("01".indexOf(mode) != -1) {
			if (h + hd < height) {
				element.style.height = h + hd;
				flg = true;
			} else {
				flg = false;
			}
		}
		if (flg) {
			window.setTimeout("__ExpandPanel('" + id + "', " + width + ", " + height + ", " + display + ", " + mode + ")", timer);
		} else {
			element.style.overflow = "visible";
			element.style.width = width;
			element.style.height = height;
			element.setAttribute("expand", null);
			element.style.zIndex = "";
			return;
		}
		element.style.zIndex = 0;
	} else if (expand == "close") {
		var flg = false;
		if ("12".indexOf(mode) != -1) {
			if (w - wd > 0) {
				element.style.width = w - wd;
				flg = true;
			} else {
				flg = false;
			}
		}
		if ("01".indexOf(mode) != -1) {
			if (h - hd > 0) {
				element.style.height = h - hd;
				flg = true;
			} else {
				flg = false;
			}
		}
		if (flg) {
			window.setTimeout("__ExpandPanel('" + id + "', " + width + ", " + height + ", " + display + ", " + mode + ")", timer);
		} else {
			element.setAttribute("expand", null);
			if (display) element.style.display = "none"; else element.style.visibility = "hidden";
			element.style.width = width;
			element.style.height = height;
			element.style.zIndex = "";
			return;
		}
		element.style.zIndex = 1000;
    }
}