$(document).ready(function() {
	var cm_t_href = [];
	var cm_c_count = [];
	var cm_ch_count = [];

	$(".MainLinksGroupTitle").each(function() {
		var comps = this.id.split("_");
		var gid = comps[comps.length-1];

		if ($("#cm_sl_"+gid)[0]) {
			cm_t_href[gid] = $(this).attr("href");
			$(this).attr("href", "javascript: void(0);");

			$(this).click(function() {
				menuLinks(gid);
			});
		}
	});
});

function menuLinks(gid) {
	$(".MainLinksGroupSublinksContainer").each(function() {
		var scomps = this.id.split("_");
		var sgid = scomps[scomps.length-1];
		if (sgid != gid)
			$(this).animate({height: "0px"});
	});

	var p_rows = 2;
	var p_c = $("#cm_sl_"+gid+" > DIV.MainLinksGroupSublinksPrimary");
	var p_h = 0;
	if (p_c[0])
		p_h = parseInt(p_c[0].style.height.replace("px", ""));
	var h = p_h+24;

	if ($("#cm_sl_"+gid).css("height") == "0px") {
		s_count = $("#cm_sl_"+gid+"_sl").children("DIV:visible").children("A").length;
		h += (s_count*15)+4;

		$("#cm_sl_"+gid).css("display", "").animate({height: h+"px"});
	} else {
		$("#cm_sl_"+gid).animate({height: "0px"}).css("display", "none");
	}
}

function menuHideSublinks(gid) {
	s_menu = $("#cm_sl_"+gid+"_sl");

	s_menu.css({display: "none"});
	s_menu.children("DIV").css({display: "none"});
}
function menuSublinks(gid, sgid) {
	$("[id^='cm_sl_"+gid+"_sla_']").attr("className", "");

	t_menu = $("#cm_sl_"+gid);

	s_menu = $("#cm_sl_"+gid+"_sl");
	s_links = $("#cm_sl_"+gid+"_sl_"+sgid);
	s_count = s_links.children("A").length;

	s_links_a = $("#cm_sl_"+gid+"_sla_"+sgid);
	s_links_a.attr("className", "MainLinksGroupSublinksSecondaryOActive");

	s_menu.css({display: "none"});
	s_menu.children("DIV").css({display: "none"});
	s_links.fadeOut(1);

	var h_s = (s_count*15)+4;

	var p_c = $("#cm_sl_"+gid+" > DIV.MainLinksGroupSublinksPrimary");
	var p_h = 0;
	if (p_c[0])
		p_h = parseInt(p_c[0].style.height.replace("px", ""));
	var h_t = p_h+24+h_s;

	t_menu.animate({height: h_t+"px"});
	s_menu.css({display: ""});
	s_links.fadeIn(500);
}

$(document).ready(function() {
	$("DIV.HeadLink").each(function() {
		if ($(this).children().length > 1) {
			$(this).hover(function() {
				$(this).children().filter(".HeadLinksSublinksContainer").show();
			}, function() {
				$(this).children().filter(".HeadLinksSublinksContainer").hide();
			});
		}
	});
});
