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

function init(ma_id, m) {
	
	var menus = document.getElementsByTagName('dt');
	if (m == 'mm') 
	{
		var identifier = new RegExp('(^| )'+'main_menu_sep'+'( |$)');
		var counter = 1;
	}
	else
	{
		var identifier = new RegExp('(^| )'+'smenu_sep'+'( |$)');
		var counter = 0;
	}
	
	for(var q = 1; q < menus.length; q++) 
	{
		if(identifier.test(menus[q].className))
		{
			counter = counter - 0 + 1;
		}
		
		if (menus[q].id == ma_id)
		{
			var a_index = counter - 0;
			var a_index_next = a_index - 0 + 1;
			var dt_L = document.getElementById(m + "sp_" + a_index);
			var dt_R = document.getElementById(m + "sp_" + a_index_next);
	
			position = "0 -" + (sepHeight*1) + "px";
			dt_L.style.backgroundPosition = position;
			position = "0 -" + (sepHeight*2) + "px";
			dt_R.style.backgroundPosition = position;
		}
	}
	
	if (m == 'mm' && a_index == counter) {
		var index_last = counter - 0 + 1;
		var dt_Last = document.getElementById(m + "sp_" + index_last);
		position = "0 -" + (sepHeight*3) + "px";
		dt_Last.style.backgroundPosition = position;
	}
}

function change_sep_up(m_id, ma_id, m, index) {

	var index_next = index - 0 + 1;
	var dt_L = document.getElementById(m + "sp_" + index);
	var dt_R = document.getElementById(m + "sp_" + index_next);
	
	var menus = document.getElementsByTagName('dt');
	if (m == 'mm') 
	{
		var identifier = new RegExp('(^| )'+'main_menu_sep'+'( |$)');
		var counter = 1;
	}
	else
	{
		var identifier = new RegExp('(^| )'+'smenu_sep'+'( |$)');
		var counter = 0;
	}
	
	for(var q = 1; q < menus.length; q++) 
	{
		if(identifier.test(menus[q].className))
		{
			counter = counter - 0 + 1;
		}
		
		if (ma_id != '' && menus[q].id == ma_id)
		{
			var a_index_next = counter - 0 + 1;
		}
	}
	
	a_index = a_index_next - 1;
	var index_last = counter - 0 + 1;
	var dt_Last = document.getElementById(m + "sp_" + index_last);

	if (a_index == index - 1) {
		position = "0 -" + (sepHeight*3) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*2) + "px";
		dt_R.style.backgroundPosition = position;
	} else if (a_index == index - 0 + 1) {
		position = "0 -" + (sepHeight*1) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*3) + "px";
		dt_R.style.backgroundPosition = position;
	} else if (m == 'mm' && counter == index) {
		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' && counter == a_index) {
		position = "0 -" + (sepHeight*3) + "px";
		dt_Last.style.backgroundPosition = position;
	}
}

function change_sep_norm(m_id, ma_id, m, index) {
	
	var menus = document.getElementsByTagName('dt');
	if (m == 'mm') 
	{
		var identifier = new RegExp('(^| )'+'main_menu_sep'+'( |$)');
		var counter = 1;
	}
	else
	{
		var identifier = new RegExp('(^| )'+'smenu_sep'+'( |$)');
		var counter = 0;
	}
	
	for(var q = 1; q < menus.length; q++) 
	{
		if(identifier.test(menus[q].className))
		{
			counter = counter - 0 + 1;
		}
		
		if (menus[q].id == ma_id)
		{
			var a_index_next = counter - 0 + 1;
		}
	}
	
	a_index = a_index_next - 1;
	
	var index_next = index - 0 + 1;
	var dt_L = document.getElementById(m + "sp_" + index);
	var dt_R = document.getElementById(m + "sp_" + index_next);
	var dt_aL = document.getElementById(m + "sp_" + a_index);
	var dt_aR = document.getElementById(m + "sp_" + a_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' && counter == index) {
		position = "0 -" + (sepHeight*0) + "px";
		dt_L.style.backgroundPosition = position;
		position = "0 -" + (sepHeight*1) + "px";
		dt_R.style.backgroundPosition = position;
	}
	if (m == 'mm' && counter == a_index) {
		position = "0 -" + (sepHeight*1) + "px";
		dt_aL.style.backgroundPosition = position;
		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) {
	
	var menus = document.getElementsByTagName('dt');
	var identifier = new RegExp('(^| )'+'smenu_sep'+'( |$)');
	var sma_index = 0;
	
	for(var q = 0; q < menus.length; q++) 
	{
		if(identifier.test(menus[q].className))
		{
			sma_index = sma_index - 0 + 1;
		}
		
		if (sma_id != '' && menus[q].id == sma_id)
		{
			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);
	
	var separators = document.getElementsByTagName('dt');
	var indeter = new RegExp('(^| )'+'cmenu_sep'+'( |$)');
	var SP_count = 0;
	
	for(var q = 0; q < separators.length; q++) { 
		if(indeter.test(separators[q].className)) {
			SP_count = SP_count + 1;
		}
	}

	for(i=1;i<=SP_count-3;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";
	}
}


/*///////////////////////// TOOLTIP /////////////////////////*/

var d = document;
var offsetfromcursorY=15 // y offset of tooltip
var ie=d.all && !window.opera;
var ns6=d.getElementById && !d.all;
var tipobj,op;
         
function tooltip(el,txt) {
    tipobj=d.getElementById('mess');
    tipobj.innerHTML = txt;
    op = 0.1;  
    tipobj.style.opacity = op;
    tipobj.style.visibility="visible";
    el.onmousemove=positiontip;
    appear();
}
 
function hide_info(el) {
    d.getElementById('mess').style.visibility='hidden';
    el.onmousemove='';
}
 
function ietruebody(){
return (d.compatMode && d.compatMode!="BackCompat")? d.documentElement : d.body
}
 
function positiontip(e) {
    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    var winwidth=ie? ietruebody().clientWidth : window.innerWidth-20
    var winheight=ie? ietruebody().clientHeight : window.innerHeight-20
     
    var rightedge=ie? winwidth-event.clientX : winwidth-e.clientX;
    var bottomedge=ie? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
 
    if (rightedge < tipobj.offsetWidth)  tipobj.style.left=curX-tipobj.offsetWidth+"px";
    else tipobj.style.left=curX+"px";
 
    if (bottomedge < tipobj.offsetHeight) tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
    else tipobj.style.top=curY+offsetfromcursorY+"px";
}
 
function appear() {
    if(op < 1) {
        op += 0.1;
        tipobj.style.opacity = op;
        tipobj.style.filter = 'alpha(opacity='+op*100+')';
        t = setTimeout('appear()', 30);
    }
}