            var newsPackSize = 8;

            var menuStructure = new Array();
            menuStructure["events"] = new Array();
            menuStructure["events"] = ["actual","archive"];
            menuStructure["events"] = ["actual"];
            menuStructure["aboutme"] = new Array();
            menuStructure["aboutme"] = ["whoami","achievements","contact"];
            menuStructure["writings"] = new Array();
            menuStructure["writings"] = ["novels","poems","fairytales","dramas","edu"];

            var frames = new Array();
            frames["news"] = "news.html";   
            frames["whoami"] = "whoami.html";
            frames["achievements"] = "achievements.html";
            frames["contact"] = "contact.html";
            frames["novels"] = "novels.html";
            frames["poems"] = "poems.html";
            frames["fairytales"] = "fairytales.html";
            frames["dramas"] = "dramas.html";
            frames["edu"] = "edu.html";
            
            function upperMenuClicked(which) {

                var buf = "";
                var space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                if (menuStructure[which].length>3) {
                    space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }
                
                for (i = 0; i < menuStructure[which].length; i++) {
                    if (i>0) {
                        buf+=space;
                    }
                    buf+=getMenu(menuStructure[which][i]);
                }
                document.getElementById("lowermenu").innerHTML = buf;

								chooseMenu(menuStructure[which][0]);
            }
            
            function getMenu(menu) {
                return  "<a class=\"zs_lowermenulink\" href=\"javascript:chooseMenu('"+menu+"');\">"+menus[menu]+"</a>";
            }
            
            function chooseMenu(menu) {
                if (menu=="poems") {
                    loadPoems();
                }
                else if (menu=="actual") {
                    loadActualNews();
                }
                else if (menu=="contact") {
                    loadContact();
                }
                else {
                    loadFrame(menu);
                }
            }

            function loadContact() {
                advAJAX.get({
                     url:frames["contact"], 
                     onSuccess: function(obj){ setContent("fr", obj.responseText); document.getElementById("ckt").innerHTML = getCkt(); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }
            
            function getCkt()
            {
                var arr = new Array();
                arr[0] = 'm';
                arr[1] = 'o';
                arr[2] = 'c';
                arr[3] = '.';
                arr[4] = 'l';
                arr[5] = 'i';
                arr[6] = 'a';
                arr[7] = 'm';
                arr[8] = 'g';
                arr[9] = '&#64';
                arr[10] = 'staniszewska';
                arr[11] = '.';
                arr[12] = 'zofia';

                var str = '';
                for (i = arr.length-1; i >= 0; i--) {
                    str += arr[i];
                }
                return str;
            }

            function getFr()
            {
              return document.getElementById("fr");
            }
            function loadFrame(fr)
            {
              doGet(frames[fr],"fr");
            }
            
            function setContent(id, content)
            {
                document.getElementById(id).innerHTML = content;
            }
            function setCursor(cursorType)
            {
                if (cursorType != null) document.body.style.cursor = cursorType;
            }

            function doGet(url, id)
            {
                setCursor('wait');
                advAJAX.get({url: url,
                  onSuccess : function(obj) { setContent(id, obj.responseText);
																							Shadowbox.clearCache();
																							Shadowbox.setup();
																							},
                  onError : function(obj) { actionError(obj.status); }
                });
                setCursor('auto');
            }
            
            function loadNews(nid) {
                advAJAX.get({
                     url:"news/"+nid+".txt", 
                     onSuccess: function(obj){ printSingleNews(nid, obj); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }
            
            function printSingleNews(nid, obj)
            {
                var newsBody = new NewsBody(nid, obj);
                
                clearTable("newslist");
                var row = addRow("newslist");
                var cell = row.insertCell(0);
                cell.innerHTML = 
                    "<div class='zs_return'><a class='url' href='javascript:loadActualNews()'>Powr&#243t</a></div>"+
                    "<div class='newstitle'>"+newsBody.title+"</div>"+
                    "<div class='newsdate'>"+newsBody.date+"</div>"+
                    "<div class='newstext'>"+newsBody.body+"</div>";
                
                document.getElementById("newsNav").innerHTML = '';
                
            }
            
            function printNews(newsBody)
            {
                var row = addRow("newslist");
                var cell = row.insertCell(0);
                cell.innerHTML = "<div class='newstitle'><a class='url' href='javascript:loadNews("+newsBody.id+")'>"+newsBody.title+"</a></div>"+
                                 "<div class='newsdate'>"+newsBody.date+"</div>"+
                                 "<div class='newstext'>"+newsBody.shortBody+"</div>";
            }
            
            function clearTable(tableId)
            {
                var table = document.getElementById(tableId);
                while (table.rows.length>0)
                    table.deleteRow(0);
            }
    
    
            function loadActualNews() {
                advAJAX.get({
                     url:frames["news"], 
                     onSuccess: function(obj){ setContent("fr", obj.responseText); loadNewsCounter(); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }
    
            function loadNewsCounter() {
                advAJAX.get({
                     url:"news/count", 
                     onSuccess: loadLastNews, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }

            function loadLastNews(obj)
            {
                var counter = obj.responseText;

                if (firstDisplayedNews == -1) {
                    firstDisplayedNews = maxNews = counter;
                }

                advAJAX.get({
                     url:"news/"+counter+".txt", 
                     onSuccess: function(obj) { loadPrevNews(obj, counter); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }
    
            function loadPrevNews(obj, counter)
            {
                var newsBody = new NewsBody(counter, obj);

                printNews(newsBody);

                counter--;

                if (counter > 0 && newsPackSize > firstDisplayedNews - counter) {
                    advAJAX.get({
                         url:"news/"+counter+".txt", 
                         onSuccess: function(obj1) { loadPrevNews(obj1, counter); }, 
                         onError: function(obj1) {alert(obj1.status);} 
                     });
                }
                else
                {
                    printNewsNav();
                }
            }
    
            function loadArchiveNews(firstNews)
            {
                var counter = firstNews;

                firstDisplayedNews = firstNews;

                clearTable("newslist");

                advAJAX.get({
                     url:"news/"+counter+".txt", 
                     onSuccess: function(obj) { loadPrevNews(obj, counter); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }
    
            var firstDisplayedNews = -1, maxNews = -1;
    
            function NewsBody(id, obj)
            {
                this.id = id;
                
                var arr = getBodyArray(obj);

                this.title = arr[0];

                this.date = arr[1];

                this.shortBody = "";
                this.body = "";
                
                
                for (i = 2; i < arr.length; i++) 
                {
                    this.body += arr[i];
                    
                    this.shortBody += arr[i];
                    
                    if (i < arr.length - 1) {
                        this.body += "<br>";
                    }
                }
                
                var shortBodyLength = 50;
                this.shortBody = this.shortBody.substring(0,shortBodyLength);
                if ( this.body.length > shortBodyLength ) {
                    var c = '';
                    var i = shortBodyLength;
                    while (true)
                    {
                        c = this.body.charAt(i);
                        
                        if ( c == ' ' || c == '\n' || c == '<' || i == this.body.length ) break;
                        
                        this.shortBody += c;
                        
                        i++;
                    }
                }
                if ( this.shortBody.length < this.body.length ) {
                    this.shortBody += "<a class='url' href='javascript:loadNews("+this.id+")'>...</a>";
                }
                
            }
            function printNewsNav() {
                var navs = "";
                var idx = 0;

                for (i = maxNews; i > 0; i=i-newsPackSize) {

                    if (navs.length > 0) {
                        navs += "   ";
                    }

                    var ii = i-newsPackSize+1;
                    if (ii<=0) {
                        ii = 1;
                    }

                    if (firstDisplayedNews == i) {
                        navs += "["+i+"-"+ii+"]";
                    }
                    else
                        navs += "<a href=\"javascript:loadArchiveNews("+i+")\" >["+i+"-"+ii+"]</a>";
                }
                document.getElementById("newsNav").innerHTML = navs;
            }
    
            
    
            function loadPoems()
            {
                advAJAX.get({
                     url:frames["poems"], 
                     onSuccess: function(obj){ setContent("fr", obj.responseText); loadPoemsList(); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }

            function loadPoemsList()
            {
                advAJAX.get({
                     url:"poems/list.txt", 
                     onSuccess: function(obj){ printPoemsList(obj); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }

            function printPoemsList(obj)
            {
                var arr = getBodyArray(obj);
                var poemList = new Array();
                for (i = 0; i < arr.length; i++) {
                    poemList[i] = new PoemListEntry(arr[i]);
                }

                for (i = 0; i < poemList.length; i++) {

                    if (poemList[i].set!="") 
                    {
                        if (i==0 || (i>0 && (poemList[i].set != poemList[i-1].set )) ) 
                        {
                            printPoemSetName(poemList[i]);
                        }

                        printPoemFromSet(poemList[i]);
                    }
                    else
                    {
                        printSinglePoem(poemList[i]);
                    }
                }
            }


            function printPoemSetName(entry)
            {
                var row = addRow("poemsList");

                var preCell = row.insertCell(0);
                preCell.width="20%";

                var cell = row.insertCell(1);
                cell.colSpan = "2";
                cell.className = "subtitle"; 
                cell.innerHTML = entry.set;

            }
            function printPoemFromSet(entry)
            {
                var row = addRow("poemsList");

                var preCell = row.insertCell(0);
                preCell.width="20%";


                var cell_1 = row.insertCell(1);
                cell_1.width = "5%";

                var cell_2 = row.insertCell(2);
                cell_2.innerHTML = "<a class='url' href=\"javascript:loadPoem('"+entry.file+"')\">"+entry.title+"</a>";
            }
            function printSinglePoem(entry)
            {
                var row = addRow("poemsList");

                var preCell = row.insertCell(0);
                preCell.width="20%";


                var cell = row.insertCell(1);
                cell.colSpan = "2";
                cell.innerHTML = "<a class='url' href=\"javascript:loadPoem('"+entry.file+"')\">"+entry.title+"</a>";
            }

            function loadPoem(poemFileName)
            {
                advAJAX.get({
                     url:"poems/"+poemFileName, 
                     onSuccess: function(obj){ printPoem(obj); }, 
                     onError: function(obj) {alert(obj.status);} 
                 });
            }

            function printPoem(obj)
            {
                var poemBody = new PoemBody(obj);

                clearTable("poemsList");

                var row, cell;

                row = addRow("poemsList");
                cell = row.insertCell(0);
                cell.innerHTML = "<div class=\"zs_return\"><a class=\"url\" href=\"javascript:poemReturn();\" >Powr&#243t</a></div>";

                row = addRow("poemsList");
                cell = row.insertCell(0);
                cell.className = "subtitle"; 
                cell.innerHTML = poemBody.title;

                row = addRow("poemsList");
                cell = row.insertCell(0);
                cell.className = "longtext"; 
                cell.innerHTML = poemBody.body;

                var row2 = addRow("poemsList");
                var cell_2 = row2.insertCell(0);
                cell_2.innerHTML = "&nbsp;";


           }

           function poemReturn()
           {
               loadPoems();
           }


            function PoemBody(obj)
            {
                var arr = getBodyArray(obj);

                this.title = arr[0];
                this.body = "";
                for (i = 1; i < arr.length; i++) 
                {
                    this.body += arr[i];
                    if (i < arr.length - 1) {
                        this.body += "<br>";
                    }
                }
            }



            function PoemListEntry(obj)
            {
                var arr = obj.split("|");

                this.title = arr[0];
                this.file = arr[1];
                if (arr.length>=3) 
                {
                    this.set = arr[2];
                }
                else
                    this.set = "";

            }
    
    function addRow(tableId)
    {
        var table = document.getElementById(tableId);
        return table.insertRow(table.rows.length);
    }

    function getBodyArray(obj)
    {
        var raw = obj.responseText;
        return raw.split("\n");
    }    
    
    function openMis1()
    {
        var w = 1371, h = 600;
        openPicture('fairytales/images/mis_1.jpg', "Mis",10,10, w, h);
    }
    function openMis2()
    {
        var w = 1371, h = 600;
        openPicture('fairytales/images/mis_2.jpg', "Mis",10,10, w, h);
    }
    
    function openPicture(url, title, left,top,width,height)
    {
        var w=window.open(url,title,
        "left="+left+", top="+top+", width="+width+", height="+height);
            //+", scrollbars=yes, resizable=yes, alwaysRaised=true");
        w.focus();
    
    }

