function tryFade(element, mode) {
	var result = $try(function(){
		element.set('tween', {duration: 100});
		element.fade(mode);
	}, function(){
	    if (mode == 'in') {
	    	element.style.visibility = "visible";
	    } else {
	    	element.style.visibility = "hidden";
	    }
	}, function(){
	    return false;
	});
}


function viewGnbsub(layerId, actId)
{
	var sublayer_length = getCountElementsByIdName();
	var divId = "menubox_";

	for(var i=0;i<=sublayer_length + 2;i++)
	{
		if(layerId == divId+i)
		{
			if( document.getElementById(divId+i) ) {
				tryFade(document.getElementById(divId+i),'in');
			}
		}
		else
		{
			if( document.getElementById(divId+i) ) {
				tryFade(document.getElementById(divId+i),'out');
			}
		}
	}

	//activate link
	if( document.getElementById('menuentry_' + actId ).className != 'ison' ) {
		var div = document.getElementById('menuentry_' + actId);
		// get reference of this element
		myElement = $(div);
		property = myElement.getProperty('class');
	}
}

function hideGnbsub( actId )
{
	var sublayer_length = getCountElementsByIdName();
	var divId = "menubox_";
	for(var i=0;i<=sublayer_length+1;i++)
	{
		if( document.getElementById(divId+i) ){
			tryFade(document.getElementById(divId+i),'out');
		}
	}
}


function getCountElementsByIdName(){
	var arrReturn = new Array();
	arrAll = document.getElementsByTagName("div");

	for(var i=0; i<arrAll.length; i++){
		if(arrAll[i].id.search(/^menubox_.+/) != -1){
			arrReturn[arrReturn.length] = arrAll[i];
		}
	}
	return arrReturn.length;
}

/* first hide all */
window.addEvent('domready', function() {
	var sublayer_length = getCountElementsByIdName();
	var divId = "menubox_";

	for(var i=0;i<=sublayer_length + 2;i++)
	{
			if( document.getElementById(divId+i) ){
				tryFade(document.getElementById(divId+i), 'hide');
			}
	}
});
