var sepHeight = "28";
var csepHeight = "30";
var m_index;
var ma_index;

function init(ma_id, m) {

	if (ma_id == "main") { ma_index = 1; }
	else if (ma_id == "community") { ma_index = 2; }
	else if (ma_id == "video") { ma_index = 3; }
    //else if (ma_id == "kcl") { ma_index = 4; }
	else if (ma_id == "matchesm") { ma_index = 4; }
	else if (ma_id == "bids") { ma_index = 5; }
	else if (ma_id == "ingame") { ma_index = 6; }
	else if (ma_id == "teams") { ma_index = 7; }
	else if (ma_id == "files") { ma_index = 8; }
	else if (ma_id == "forum") { ma_index = 9; }
    else if (ma_id == "about") { ma_index = 10; }
	else { ma_index = null; }

	var ma_index_next = ma_index- 0 + 1;
	var dt_L = document.getElementById(m + "sp_" + ma_index);
	var dt_R = document.getElementById(m + "sp_" + ma_index_next);

	position = "0 -" + (sepHeight*1) + "px";
	dt_L.style.backgroundPosition = position;
	position = "0 -" + (sepHeight*2) + "px";
	dt_R.style.backgroundPosition = position;

	if (ma_index == 10 ) {
		position = "0 -" + (sepHeight*3) + "px";
		dt_R.style.backgroundPosition = position;
	}
}

function change_sep_up(m_id, ma_id, m) {

	if (m == "mm") {
		if (m_id == "main") { m_index = 1; }
		else if (m_id == "community") { m_index = 2; }
		else if (m_id == "video") { m_index = 3; }
        //else if (m_id == "kcl") { m_index = 4; }
        else if (m_id == "matchesm") { m_index = 4 }
		else if (m_id == "bids") { m_index = 5; }
		else if (m_id == "ingame") { m_index = 6; }
		else if (m_id == "teams") { m_index = 7; }
		else if (m_id == "files") { m_index = 8; }
		else if (m_id == "forum") { m_index = 9; }
		else if (m_id == "about") { m_index = 10; }
		else { m_index = null; }
		if (ma_id == "main") { ma_index = 1; }
		else if (ma_id == "community") { ma_index = 2; }
        else if (ma_id == "video") { ma_index = 3; }
        //else if (ma_id == "kcl") { ma_index = 4; }
		else if (ma_id == "matchesm") { ma_index = 4; }
		else if (ma_id == "bids") { ma_index = 5; }
		else if (ma_id == "ingame") { ma_index = 6; }
		else if (ma_id == "teams") { ma_index = 7; }
		else if (ma_id == "files") { ma_index = 8; }
		else if (ma_id == "forum") { ma_index = 9; }
		else if (ma_id == "about") { ma_index = 10; }
		else { ma_index = null; }
	} else if (m == "sm"){
		if (m_id == "splayers") { m_index = 1; }
		else if (m_id == "steams") { m_index = 2; }
		else if (m_id == "sblogs") { m_index = 3; }
		else if (m_id == "sgallery") { m_index = 4; }
		else if (m_id == "sgroups") { m_index = 5; }
		else if (m_id == "smusic") { m_index = 6; }
		else if (m_id == "sclassified") { m_index = 7; }
		else if (m_id == "spolls") { m_index = 8; }
		else if (m_id == "sumanager") { m_index = 9; }
		else { m_index = null; }
		if (ma_id == "splayers") { ma_index = 1; }
		else if (ma_id == "steams") { ma_index = 2; }
		else if (ma_id == "sblogs") { ma_index = 3; }
		else if (ma_id == "sgallery") { ma_index = 4; }
		else if (ma_id == "sgroups") { ma_index = 5; }
		else if (ma_id == "smusic") { ma_index = 6; }
		else if (ma_id == "sclassified") { ma_index = 7; }
		else if (ma_id == "spolls") { ma_index = 8; }
		else if (ma_id == "sumanager") { ma_index = 9; }
		else { ma_index = null; }
	}

	var m_index_next = m_index- 0 + 1;
	var dt_L = document.getElementById(m + "sp_" + m_index);
	var dt_R = document.getElementById(m + "sp_" + m_index_next);
	var dt_Last = document.getElementById(m + "sp_11");

	if (ma_index == m_index - 1) {
		position = "0 -" + (sepHeight*3) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*2) + "px";
		dt_R.style.backgroundPosition = position;
	} else if (ma_index == m_index + 1) {
		position = "0 -" + (sepHeight*1) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*3) + "px";
		dt_R.style.backgroundPosition = position;
	} else {
		position = "0 -" + (sepHeight*1) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*2) + "px";
		dt_R.style.backgroundPosition = position;
	}
	if (m == "mm" && m_index == "10") {
		position = "0 -" + (sepHeight*3) + "px";
		dt_R.style.backgroundPosition = position;
	}
	if (m == "sm" && m_index == "9") {
		position = "0 -" + (sepHeight*2) + "px";
		dt_R.style.backgroundPosition = position;
	}
	if (m == "mm" && ma_index == "10") {
		position = "0 -" + (sepHeight*3) + "px";
		dt_Last.style.backgroundPosition = position;
	}
}

function change_sep_norm(m_id, ma_id, m) {

	if (m == "mm") {
		if (m_id == "main") { m_index = 1; }
		else if (m_id == "community") { m_index = 2; }
		else if (m_id == "video") { m_index = 3; }
        //else if (m_id == "kcl") { m_index = 4; }
		else if (m_id == "matchesm") { m_index = 4; }
		else if (m_id == "bids") { m_index = 5; }
		else if (m_id == "ingame") { m_index = 6; }
		else if (m_id == "teams") { m_index = 7; }
		else if (m_id == "files") { m_index = 8; }
		else if (m_id == "forum") { m_index = 9; }
		else if (m_id == "about") { m_index = 10; }
		else { m_index = null; }
		if (ma_id == "main") { ma_index = 1; }
		else if (ma_id == "community") { ma_index = 2; }
		else if (ma_id == "video") { ma_index = 3; }
        //else if (ma_id == "kcl") { ma_index = 4; }
		else if (ma_id == "matchesm") { ma_index = 4; }
		else if (ma_id == "bids") { ma_index = 5 }
		else if (ma_id == "ingame") { ma_index = 6; }
		else if (ma_id == "teams") { ma_index = 7; }
		else if (ma_id == "files") { ma_index = 8; }
		else if (ma_id == "forum") { ma_index = 9; }
		else if (ma_id == "about") { ma_index = 10; }
		else { ma_index = null; }
	} else if (m == "sm"){
		if (m_id == "splayers") { m_index = 1; }
		else if (m_id == "steams") { m_index = 2; }
		else if (m_id == "sblogs") { m_index = 3; }
		else if (m_id == "sgallery") { m_index = 4; }
		else if (m_id == "sgroups") { m_index = 5; }
		else if (m_id == "smusic") { m_index = 6; }
		else if (m_id == "sclassified") { m_index = 7; }
		else if (m_id == "spolls") { m_index = 8; }
		else if (m_id == "sumanager") { m_index = 9; }
		else { m_index = null; }
		if (ma_id == "splayers") { ma_index = 1; }
		else if (ma_id == "steams") { ma_index = 2; }
		else if (ma_id == "sblogs") { ma_index = 3; }
		else if (ma_id == "sgallery") { ma_index = 4; }
		else if (ma_id == "sgroups") { ma_index = 5; }
		else if (ma_id == "smusic") { ma_index = 6; }
		else if (ma_id == "sclassified") { ma_index = 7; }
		else if (ma_id == "spolls") { ma_index = 8; }
		else if (ma_id == "sumanager") { ma_index = 9; }
		else { ma_index = null; }
	}

	var m_index_next = m_index- 0 + 1;
	var ma_index_next = ma_index- 0 + 1;
	var dt_L = document.getElementById(m + "sp_" + m_index);
	var dt_R = document.getElementById(m + "sp_" + m_index_next);
	var dt_aL = document.getElementById(m + "sp_" + ma_index);
	var dt_aR = document.getElementById(m + "sp_" + ma_index_next);

	position = "0 -" + (sepHeight*0) + "px";
	dt_L.style.backgroundPosition = position;
	position = "0 -" + (sepHeight*0) + "px";
	dt_R.style.backgroundPosition = position;

	if(ma_id!="")
	{
		position = "0 -" + (sepHeight*1) + "px";
		dt_aL.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*2) + "px";
		dt_aR.style.backgroundPosition = position;
	}
	if (m == "mm" && m_index == "10") {
		position = "0 -" + (sepHeight*1) + "px";
		dt_R.style.backgroundPosition = position;
	}
	if (m == "mm" && ma_index == "10") {
		position = "0 -" + (sepHeight*3) + "px";
		dt_aR.style.backgroundPosition = position;
	}
}

function initc(cma_id, m) {

	if (cma_id == "cnews") { cma_index = 1; }
	else if (cma_id == "carticl") { cma_index = 2; }
	else { cma_index = 3; }

	var cma_index_next = cma_index+1;
	var dt_cL = document.getElementById(m + "sp_" + cma_index);
	var dt_cR = document.getElementById(m + "sp_" + cma_index_next);

	for(i=1;i<=4;i++)
	{
		document.getElementById(m + "sp_"+i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_cL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_cR.style.backgroundPosition = position;
}

function initp(pma_id, m) {

	if (pma_id == "peven") { pma_index = 1; }
	else { pma_index = 2; }


	var pma_index_next = pma_index- 0 + 1;
	var dt_pL = document.getElementById(m + "sp_" + pma_index);
	var dt_pR = document.getElementById(m + "sp_" + pma_index_next);

	for(i=1;i<=3;i++)
	{
		document.getElementById(m + "sp_"+i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_pL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_pR.style.backgroundPosition = position;
}

function init_s(sma_id, m) {
	if (sma_id == "splayers") { sma_index = 1; }
	else if (sma_id == "steams") { sma_index = 2; }
	else if (sma_id == "sblogs") { sma_index = 3; }
	else if (sma_id == "sgallery") { sma_index = 4; }
	else if (sma_id == "sgroups") { sma_index = 5; }
	else if (sma_id == "smusic"){ sma_index = 6; }
	else if (sma_id == "sclassified") { sma_index = 7; }
	else if (sma_id == "spolls"){ sma_index = 8; }
	else if (sma_id == "sumanager") { sma_index = 9; }
	else { sma_index = null; }


	if(sma_index)
	{
		var sma_index_next = sma_index- 0 + 1;
		var dt_sL = document.getElementById(m + "sp_" + sma_index);
		var dt_sR = document.getElementById(m + "sp_" + sma_index_next);

		position = "0 -" + (sepHeight*1) + "px";
		dt_sL.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*2) + "px";
		dt_sR.style.backgroundPosition = position;
	}
}

function initcat(catma_index, m) {
	
	var catma_index_next = catma_index - 0 + 1;
	var dt_catL = document.getElementById(m + "sp_" + catma_index);
	var dt_catR = document.getElementById(m + "sp_" + catma_index_next);

	for(i = 1; i <= 10; i++)
	{
		document.getElementById(m + "sp_"+i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}
	
	if (catma_index == "8") {
		var dt_catL = document.getElementById(m + "sp_" + "3");
		var dt_catR = document.getElementById(m + "sp_" + "4");
	}
	else if (catma_index >= "3" && catma_index != "9") {
		var catma_index = catma_index - 0 + 1;
		var catma_index_next = catma_index - 0 + 1;
		var dt_catL = document.getElementById(m + "sp_" + catma_index);
		var dt_catR = document.getElementById(m + "sp_" + catma_index_next);
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_catL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_catR.style.backgroundPosition = position;
}

function initwm(wma_index, m) {

	var wma_index_next = wma_index - 0 + 1;
	var dt_wL = document.getElementById(m + "sp_" + wma_index);
	var dt_wR = document.getElementById(m + "sp_" + wma_index_next);

	for(i=1;i<=5;i++)
	{
		document.getElementById(m + "sp_" + i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_wL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_wR.style.backgroundPosition = position;
}

function inittu(tuma_index, m) {

	var tuma_index_next = tuma_index - 0 + 1;
	var dt_tuL = document.getElementById(m + "sp_" + tuma_index);
	var dt_tuR = document.getElementById(m + "sp_" + tuma_index_next);

	for(i=1;i<=3;i++)
	{
		document.getElementById(m + "sp_" + i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_tuL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_tuR.style.backgroundPosition = position;
}

function inittm(tma_index, m) {

	var tma_index_next = tma_index - 0 + 1;
	var dt_tL = document.getElementById(m + "sp_" + tma_index);
	var dt_tR = document.getElementById(m + "sp_" + tma_index_next);

	for(i=1;i<=4;i++)
	{
		document.getElementById(m + "sp_" + i).style.backgroundPosition = "0 -" + (csepHeight*0) + "px";
	}

	position = "0 -" + (csepHeight*1) + "px";
	dt_tL.style.backgroundPosition = position;
	position = "0 -" + (csepHeight*2) + "px";
	dt_tR.style.backgroundPosition = position;
}

function addHandler(node, evt, func) {
    if (node.addEventListener) {
        node.addEventListener(evt, func, false);
    } else {
        node.attachEvent('on' + evt, func);
    }
};

function isParent(child, parent) {
    if (!child || !parent) {
        return false;
    }
    while (true) {
        if (child == parent) {
            return true;
        }
        if (child.parentElement) {
            child = child.parentElement;
        } else if (child.parentNode) {
            child = child.parentNode;
        } else {
            return false;
        }
    }
}

function showprofMenu (wich) {
	hideprofMenu ();
	window.onclick = function(){}
	menuItem = document.getElementById(wich);
	menuHeadLeft = document.getElementById(wich + "_left");
	menuHeadRight = document.getElementById(wich + "_right");
	menuHeadCenter = document.getElementById(wich + "_center");

	menuItem.style.display = "block";
	menuHeadLeft.style.background = "url('images/profm_l_open.png') no-repeat 0 0";
	menuHeadRight.style.background = "url('images/profm_r_open.png') no-repeat 100% 0";
	menuHeadCenter.style.background = "#d9d9d9";

	document.getElementById(wich + "Link").onclick = function() {
		hideMenu(wich);
	}

    var node = document.getElementById(wich + "_parent");

    addHandler(node, 'mouseout', function(e) {
        var target = e.relatedTarget || e.toElement;
        if(!isParent(target, node)) {
			document.onclick = function(){
					hideprofMenu ();
					document.onclick = function(){}
				}
		}
    });

}

function hideprofMenu () {
	if(document.getElementById('profileMenu').style.display=='block') {
        hideMenu ("profileMenu");
    }
	if(document.getElementById('contentMenu').style.display=='block') {
        hideMenu ("contentMenu");
    }
	if(document.getElementById('messageMenu').style.display=='block') {
        hideMenu ("messageMenu");
    }
	if(document.getElementById('gamesMenu')) {
		if(document.getElementById('gamesMenu').style.display=='block') {
            hideMenu ("gamesMenu");
        }
	}
}

function hideMenu (wich) {
    document.onclick ='';
	menuItem = document.getElementById(wich);
	menuHeadLeft = document.getElementById(wich + "_left");
	menuHeadRight = document.getElementById(wich + "_right");
	menuHeadCenter = document.getElementById(wich + "_center");

	menuItem.style.display = "none";
	menuHeadLeft.style.background = "url('images/profm_l.png') no-repeat 0 0";
	menuHeadRight.style.background = "url('images/profm_r.png') no-repeat 100% 0";
	menuHeadCenter.style.background = "#ffffff";
	document.getElementById(wich + "Link").onclick = function() {
		showprofMenu(wich);
	}

}

function IC_toggle (id, tab, status, r) {
	i = document.getElementById(id);
	but = document.getElementById(tab + '_upshrink_ic');
	if (!r) {
		r = "";
	}

	if (status == 'opened') {
		i.style.display = "block";
		but.src = "images/collapse" + r +".png";
	} else {
		i.style.display = "none";
		but.src = "images/expand" + r + ".png";
	}
}