var nn4 = (document.layers)?true:false;
var ie4 = (document.all)?true:false;
var menudelaytime = 500;	// milisekundy
var refX = 0;
var refY = 0;
var initialized = 0;
var timID = 0;
var whatNow = 0;		// ktore menu jest teraz aktywne (0 - zadne)

var who_is_open = new Array(0,0,0,0,0,0,0,0);

function init()
{
	initialized = 1;
}

// --------------------------------------- DIV'y ----------------------
function shadeOn( id )
{

        document.all["cell"+id].style.color="white";
		document.all["cell"+id].style.cursor="hand";

}

function shadeOff( id, depth )
{
	if( who_is_open[depth] != id )
	{
		shadeOfff( id );
	}
}
function shadeOfff( id )
{
	document.all["cell"+id].style.color="#151A80";
}


function showLayer( divId, showhide )
{
	if(nn4)
	{
		(showhide)?document.layers[divId].visibility = "show":document.layers[divId].visibility = "hide"; 
	}
	else
	{
		(showhide)?document.all[divId].style.visibility = "visible":document.all[divId].style.visibility = "hidden"; 
	}
}

function openPage( id )
{
	window.location="index.php?strona=pagebuilder&id_strony=" + id;
}

function expandMenu( id, depth )
{
	wio = who_is_open[depth];
	if( who_is_open[depth] != 0 )
	{
		// zamykamy otwarte menu (wszystkie do tej glebokosci)
		for( i = depth; i < who_is_open.length; i++ )
		{
			if( who_is_open[i] > 0 )
			{
				if( id != who_is_open[i] )
				{
					shadeOfff( who_is_open[i] );
				}
				showLayer( "submenu" + who_is_open[i], 0 );
				who_is_open[i] = 0;
			}
		}
	}
	if( wio == id )
	{
		// kliknieto na to samo podmenu wiec je tylko zamykamy (powyzej)
		who_is_open[depth] = 0;
	}
	else
	{
		who_is_open[depth] = id;
		showLayer( "submenu" + who_is_open[depth], 1 );
	}
}

function showSel()
{
	stopTimeing();
	if( whatNow != -1 )
	{
		offf();
		whatNow = -1;

		showLayer( 'prodselect', 1 );
	}
	else
	{
		offf();
		showLayer( 'prodselect', 0 );
	}
}
function delTimer()
{
	//showSel();
}
function closeProd()
{
	//timID = setTimeout( "offf()", menudelaytime );
}


function on( id )
{
	stopTimeing();
	if( whatNow != id )
	{
		offf();
		whatNow = id;

		showLayer( 'submenu' + id, 1 );
	}
}

function off( id )
{
	timID = setTimeout( "offf()", menudelaytime );
}

function offf()
{
	if( whatNow )
	{
		stopTimeing();
		if( whatNow == -1 )	showLayer( 'prodselect', 0 );
		else	showLayer( 'submenu' + whatNow, 0 );
	}
	whatNow = 0;
}

function stopTimeing()
{
	if( timID )
	{
		clearTimeout( timID );
		timID = 0;
	}
}


