var g_oDrzewo;
var x;
var y;
var w=20;
var h=20;
var g_bZnaleziony=0;
var GRAFIKA="GRAFIKA"; //Element jest wtłączne grafiką , a nie linkiem

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

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

		this.URL = sURL;
		this.URLNapis = sURLNapis; 
 		this.Ojciec = oOjciec;
 		this.Klucz = sKlucz;
 		this.Styl = sStyl; 		this.ImgId = pImgId;

		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("");
		NarysujElement( g_oDrzewo );
	document.write("");
	}

	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 )
	{

		if ( oElem.URLGraphic == GRAFIKA )
		{
			document.write(oElem.URLGraphicSpec +"<br>");
		}
		else
		{
			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 =""
			if ( oElem.Ojciec.Klucz != "root" ) sTylkoWGlownym="";

			document.write(sTylkoWGlownym + "" );

			document.write( Grafika );

			if( ! bLink ) document.write( "<a href=" + oElem.URL + oElem.Styl );

			document.write( "<img name=mimg" + oElem.ImgId + " width=118 height=24 border=0 src="+ oElem.URLNapis +">" );
			if( ! bLink ) document.write( "</A>" );


			document.write("<br>");
		}
	}

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