function showMenu(obj) {
	obj.parentNode.getElementsByTagName("a")[0].className = "hover";
	var divs = obj.parentNode.getElementsByTagName("div");
	if (divs.length > 0)
		divs[0].style.display = "block";
}

function hideMenu(obj) {
	//return;
	obj.parentNode.getElementsByTagName("a")[0].className = "";
	var divs = obj.parentNode.getElementsByTagName("div");
	if (divs.length > 0)
		divs[0].style.display = "none";
}

function adjustLines() {
	arrHr = document.getElementsByTagName("hr");
	
	for (var i = 0; i < arrHr.length ; i++) {
		if ((arrHr[i].parentNode.className != "line-gray") && (arrHr[i].parentNode.className != "line-blue"))
			$(arrHr[i]).wrap('<div class="line-gray"></div>');
	}
}

function adjustMenuRight() {
	var submenu = document.getElementById("submenu");
	if (submenu != null) {
		height = getPageSize()["sizeContent"];
		elements = submenu.getElementsByTagName("ul")
		if (elements.length >= 1) {
		    submenu.getElementsByTagName("ul")[0].style.height = (height-300)+"px";
		}
	}
}

function adjustMenuWidth() {
	var nLis = $('#menu > li').length;
	var totalWidth = $('#menu').width(); 
	totalWidth = 1000;
	var newWidth = parseInt(totalWidth / nLis) - 1;
	var dif = totalWidth % nLis;
	
	$('#menu > li:not(:last)').width(newWidth);
	$('#menu > li:not(:last)').each(function () {
		$(this).find('div.submenu').each(function (i) {
			$(this).width(newWidth - 1);
			
			$(this).find('ul > li').width(newWidth - 1);
			$(this).find('ul > li > a').width(newWidth - 8);
			if (i > 0) {
				$(this).css('left', newWidth - 8);
			}
		});
	});
	
	$('#menu > li:last').width(newWidth + dif);
	$('#menu > li:last').each(function () {
		$(this).find('div.submenu').each(function (i) {
			
			$(this).width(newWidth - 1 + dif);
			$(this).find('ul > li').width(newWidth - 1 + dif);
			$(this).find('ul > li > a').width(newWidth - 8 + dif);
			
			if (i > 0) {
				$(this).css('left', newWidth - 8 + dif);
			}
		});
	});
	
	$('#menu > li:last').css('border', 'none');
}

$(document).ready(function(){
	adjustLines();
	adjustMenuRight();
	adjustMenuWidth();
});
