var g_oDrzewo;
var x;
var y;
var w=20;
var h=20;
var g_bZnaleziony=0;

bSzkapa = (document.layers)? true:false;
bIE = (document.all)? true:false;

	function ElementMenu( sURLGraphic, sURLGraphicSpec, sURLClass, sURL, sURLNapis, oOjciec, sKlucz, sStyl )
	{
		this.URLGraphic = sURLGraphic;
		this.URLGraphicSpec = sURLGraphicSpec;

		this.URLClass = sURLClass;
		this.URL = sURL;
		this.URLNapis = sURLNapis; 
 		this.Ojciec = oOjciec;
 		this.Klucz = sKlucz;
		this.Styl= sStyl;

		this.Dzieci = new Array();
		this.DodajDziecko = DodajDziecko;

		if ( sKlucz != "root" )
		{
			oOjciec.DodajDziecko( this );
			this.Otwarte = 0;
		}
		else
		{
			this.Otwarte = 1;
		}

	}

	function DodajDziecko( oDziecko )
	{
		this.Dzieci[this.Dzieci.length]=oDziecko;
	}

	//koniec klasy ---------------------------------------------------------------------
	
	function WyrysujMenu()
	{
		ZaznaczOtwarte();
		Narysuj( g_oDrzewo );	
	}


	function ZaznaczOtwarte()
	{
		g_bZnaleziony = 0;
		ZanaczOtwarteOdNoda( g_oDrzewo );

	}

	function ZanaczOtwarteOdNoda( oElem )
	{

		var i;

		if ( g_bZnaleziony ) return;

		if ( oElem.Klucz == g_sKluczStrony )
		{
			ZaznaczOtwarteDrzewkoWGore( oElem );
			g_bZnaleziony = 1;
			return;
		}

		for( i = 0 ; i < oElem.Dzieci.length; i ++ )
		{
			ZanaczOtwarteOdNoda( oElem.Dzieci[i] );
		}

	}

	function ZaznaczOtwarteDrzewkoWGore( oElem )
	{
		var oOjciec = oElem;
		while ( oOjciec.Klucz != "root" )
		{
			oOjciec.Otwarte = 1;
			oOjciec = oOjciec.Ojciec;
		};

	}

	
	function Narysuj()
	{
		y=0;
		x=0;
		document.write("<table border=0 cellpadding=0 cellspacing=0 width=90%>");
		NarysujElement( g_oDrzewo );
	document.write("</table>");
	}

	function NarysujElement( oElem )
	{

		if ( oElem.Klucz != "root" )
		{
			RysujElement( oElem, x, y );
			y++;	
		}


		if ( oElem.Otwarte )
		{
			x++;
			var i;
			for( i = 0 ; i < oElem.Dzieci.length; i ++ )
			{
				NarysujElement( oElem.Dzieci[i] );
			}
			x--;
		}
	}

	function 	RysujElement( oElem, x, y )
	{
		var i;
		var sStyl, Grafika;
		var bLink;
		
		sStyl = new String(oElem.Styl);

		if ( oElem.Klucz == g_sKluczStrony )
		{
			Grafika = oElem.URLGraphicSpec;
			bLink = true;
		}
		else
		{
			Grafika = oElem.URLGraphic;
			bLink = false;
		}

		var sTylkoWGlownym ="<tr><TD width=100% bgColor=#FFFFFF height=0></TD></tr>"
		if ( oElem.Ojciec.Klucz != "root" ) sTylkoWGlownym="";

		document.write(sTylkoWGlownym + "<tr><td " + sStyl  + " height=16>" );
		
		if( ! bLink ) document.write("<A class=" + oElem.URLClass +  " href=/_pl/" + oElem.URL + ">" );

		document.write( Grafika );

		for( i=0 ; i<x ; i ++) document.write("&nbsp;");

		document.write( oElem.URLNapis );
		if( ! bLink ) document.write( "</A>" );

		document.write("</td></tr><tr><TD width=100% bgColor=#FFFFFF height=0></TD></tr>");
	}

	function DajDiva(sID)
	{
		if (bSzkapa)
		{
			return document.layers[sID];
		}
		else if (bIE)
		{
			return  document.all[sID].style;
		}
	}
