        var headline_count;
        var headline_interval;
        var old_headline = 0;
        var current_headline=0;

    $(document).ready(function()
    {
        $('#bbIframe').ready( function()
        {
            ifReload();
        });

        exists = function(id)
        {
            return $(id).length > 0;
        }

        $('#forumSearchForm').submit( function() {
            var fphrase = $('#forumSearch').attr('value');
            var fcontent = $('#forumSearchContent').attr('checked');

            if ('' != fphrase)
            {
                $.ajax({
                    url: '/api/forum_search.php',
                    type: 'POST',
                    data: {
                        phrase: fphrase,
                        content: fcontent
                    },
                    dataType: 'html',
                    timeout: 40000,
                    beforeSend: function ()
                    {
                        $('#return').empty();
                        $('#return').html('<div id="lwEditorMsg" class="lwEditorMsgGreen">Trwa przeszukiwanie forum. Proszę czekać…</div>');
                        $('#lwEditorMsg').fadeIn('medium');
                    },
                    error: function()
                    {
                        $('#return').html('<div id="lwEditorMsg" class="lwEditorMsgRed">Wystąpił błąd!<br />Spróbuj ponownie. Jeśli problem będzie się powtarzał skontaktuj się z admninistracją.</div>');
                        $('#lwEditorMsg').fadeIn('medium');
                    },
                    success: function(html)
                    {
                        $('#return').html(html);
                    }
                });
            }
            else
            {
                $('#return').empty();
                $('#return').html('<div id="lwEditorMsg" class="lwEditorMsgYellow">Aby rozpocząć przeszukiwanie forum należy wpisać tekst w pole wyszukiwania.</div>');
                $('#lwEditorMsg').fadeIn('medium');
            }

            return false;

        });

        if (exists('#lwEditor'))
        {
            if (exists('#lwEditorForm'))
            {
                var fhtml = '';
                var ftitle = '';
                var fcontent = '';
                var fpreview = '';

                quote = function(id)
                {
                    if (exists(id))
                    {
                        if (!$('#lwEditorFormContent').val())
                        {
                            $('#lwEditorFormContent').val(
                                '[quote=' +
                                $(id + ' > p:eq(0) > a:eq(0)').text() +
                                ']' +
                                $(id + ' > p.noformat').text() +
                                '[/quote]'
                            );
                        }
                        else
                        {
                            $('#lwEditorFormContent').val(
                                $('#lwEditorFormContent').val() +
                                "\n" +
                                '[quote=' +
                                $(id + ' > p:eq(0) > a:eq(0)').text() +
                                ']' +
                                $(id + ' > p.noformat').text() +
                                '[/quote]'
                            );
                        }
                        return true;
                    }
                    return false;
                }

                lwEditorFormSubmitListener = function()
                {
                    return false;
                }

                $('#lwEditorForm').submit(lwEditorFormSubmitListener);

                lwEditorFormCancelClickListener = function()
                {
                    $('#lwEditorForm').html(fhtml);
                    $('#lwEditorFormTitle').val(ftitle);
                    $('#lwEditorFormContent').val(fcontent);
                    $('#lwEditorFormForumId').val(fforumId);
                    $('#lwEditorFormThreadId').val(fthreadId);
                    $('#lwEditorFormPage').val(fpage);
                    $('#lwEditorFormPortion').val(fportion);
                    $('#lwEditorFormSubmit').click(lwEditorFormSubmitClickListener);
                    $('a[href=#lwEditor]').css('display','block');
                }

                lwEditorFormPublishClickListener = function()
                {
                    $('#lwEditorFormPublish').attr('disabled', true);
                    if (exists('#lwEditorMsg'))
                    {
                        $('#lwEditorMsg').remove();
                    }
                    fpreview = $('#lwEditorForm').html();
                    $.ajax({
                        url: '/Ajax/Response.php?hash=zapiszWatek',
                        type: 'POST',
                        data: {title: ftitle, content: fcontent,
                               forumId: fforumId, threadId: fthreadId,
                               page: fpage, portion: fportion},
                        dataType: 'html',
                        timeout: 40000,
                        beforeSend: function ()
                        {
                            $('#lwEditorForm').empty();
                            $('#lwEditorForm').html('<div id="lwEditorMsg" class="lwEditorMsgGreen">Trwa publikowanie wiadomości. Proszę czekać…</div>');
                            $('#lwEditorMsg').fadeIn('medium');
                        },
                        error: function()
                        {
                            $('#lwEditorForm').html('<div id="lwEditorMsg" class="lwEditorMsgRed">Wystąpił błąd. Proszę spróbować ponownie.</div>' + fpreview);
                            $('#lwEditorFormCancel').click(lwEditorFormCancelClickListener);
                            $('#lwEditorFormPublish').click(lwEditorFormPublishClickListener);
                            $('#lwEditorMsg').fadeIn('medium');
                        },
                        success: function()
                        {
                            $('#lwEditorMsg').fadeOut(
                                'medium',
                                function()
                                {
                                    $('#lwEditorForm').html('<div id="lwEditorMsg" class="lwEditorMsgGreen">Wiadomość opublikowana.</div>');
                                    $('#lwEditorMsg').fadeIn(
                                        'medium',
                                        function()
                                        {
                                            window.location.reload();
                                        }
                                    );
                                }
                            );
                        }
                    });
                }

                lwEditorFormSubmitClickListener = function()
                {
                    if (exists('#lwEditorMsg'))
                    {
                        $('#lwEditorMsg').remove();
                    }
                    fhtml = $('#lwEditorForm').html();
                    ftitle = $('#lwEditorFormTitle').val();
                    fcontent = $('#lwEditorFormContent').val();
                    fforumId = $('#lwEditorFormForumId').val();
                    fthreadId = $('#lwEditorFormThreadId').val();
                    fpage = $('#lwEditorFormPage').val();
                    fportion = $('#lwEditorFormPortion').val();
                    $('a[href=#lwEditor]').css('display','none');

                    $.ajax({
                        url: '/Ajax/Response.php?hash=generujPodglad',
                        type: 'POST',
                        data: {title: ftitle, content: fcontent,
                               forumId: fforumId, threadId: fthreadId,
                               page: fpage, portion: fportion},
                        // tu zmienić, bo dostaniemy jsona
                        dataType: 'html',
                        timeout: 40000,
                        beforeSend: function ()
                        {
                            $('#lwEditorForm').empty();
                            $('#lwEditorForm').html('<div id="lwEditorMsg" class="lwEditorMsgGreen">Trwa generowanie podglądu. Proszę czekać…</div>');
                            $('#lwEditorMsg').fadeIn('medium');
                        },

                        error: function()
                        {
                            $('#lwEditorMsg').fadeOut(
                                'medium',
                                function()
                                {
                                    $('#lwEditorForm').html('<div id="lwEditorMsg" class="lwEditorMsgRed">Wystąpił błąd. Proszę spróbować ponownie.</div>' + fhtml);
                                    $('#lwEditorMsg').fadeIn('medium');
                                    $('#lwEditorFormTitle').val(ftitle);
                                    $('#lwEditorFormContent').val(fcontent);
                                    $('#lwEditorFormForumId').val(fforumId);
                                    $('#lwEditorFormThreadId').val(fthreadId);
                                    $('#lwEditorFormPage').val(fpage);
                                    $('#lwEditorFormPortion').val(fportion);
                                    $('#lwEditorFormSubmit').click(lwEditorFormSubmitClickListener);
                                }
                            );
                        },
                        success: function(html)
                        {
                            $('#lwEditorMsg').fadeOut(
                                'medium',
                                function()
                                {
                                    $('#lwEditorForm').html(html);
                                    $('#lwEditorFormCancel').click(lwEditorFormCancelClickListener);
                                    $('#lwEditorFormPublish').click(lwEditorFormPublishClickListener);
                                }
                            );
                        }
                    });

                }
                $('#lwEditorFormSubmit').click(lwEditorFormSubmitClickListener);
            }
        }

        function error(target, loc)
        {
            target.load(loc+'Ajax/error.html');
        }

        var visibleDivs = new Array();
        var timexId = 0;

        profileShow = function(loc, id, visible)
        {
            for (i=0; i<visibleDivs.length; i++) {
                divToHideId = '#profilChmurka'+visibleDivs[i];
                $(divToHideId).hide();
                visibleDivs.shift();
            }
            divId = '#profilChmurka'+id;
            if (visible==true && timexId==id) {
                $.ajax({
                    url: loc+'Ajax/Response.php?hash=profil&bohaterId='+id+'&pathBack='+loc,
                    type: 'GET',
                    dataType: 'html',
                    timeout: 4000,
                    error: function(){
                        $(divId).show();
                        $(divId).html('');
                    },
                    success: function(html){
                            $(divId).show();
                            $(divId).html(html);
                            visibleDivs.push(id);
                    }
                });

            } else {
                $(divId).hide();
            }
        }

        profile = function(loc, id, visible)
        {
            if (visible==true) {
                timexId=id;
            } else {
                timexId=0;
            }
            setTimeout ("profileShow('"+loc+"', "+id+", "+visible+")", 900);
        }

        $("#ScrollButton").click(function ()
        {
            $("#scrollNews1").fadeOut("slow");
            $("#scrollNews2").fadeIn("slow");
        });


        moderacjaZglos = function(loc, obId, obTypId, powodId, obUrl)
        {
            if (powodId == 0)
            {
                alert('Nie można przyjąć zgłoszenia do moderacji, \nponieważ nie wybrano rodzaju naruszenia regulaminu.');
                exit;
            }
            divId = '#moderacjaZgloszenieForm_'+obId;
            $.ajax({
                url: loc+'Ajax/Response.php?hash=moderacjaZglos&obId='+obId+'&obTypId='+obTypId+'&powodId='+powodId+'&obUrl='+obUrl+'&pathBack='+loc,
                type: 'GET',
                dataType: 'html',
                timeout: 1000,
                error: function(){
                    $(divId).html('');
                },
                success: function(html){
                    $(divId).html(html);
                }
            });
        }

        poleStrzel = function(loc, x, y)
        {
            divId = '#Pole_'+x+y;
            $.ajax({
                url: loc+'Ajax/Response.php?hash=poleStrzel&x='+x+'&y='+y+'&pathBack='+loc,
                type: 'GET',
                dataType: 'html',
                timeout: 4000,
                error: function(){

                },
                success: function(html){
                    $(divId).removeClass();
                    $(divId).addClass(html);
                    $(divId).removeAttr("onclick");
                    $(divId).bind("click", function(e) {
                        void(null);
                    });
                }
            });
        }

        reloadOnlineUsers = function(loc) {
            $.ajax({
                url: loc+'Ajax/Response.php?hash=onlineUsers',
                type: 'GET',
                dataType: 'html',
                timeout: 1500,
                error: function(){
                    $('#onlineUsers').html('Ladowanie listy…');
                },
                success: function(html){
                        $('#onlineUsers').html(html);
                }
            });
        }

        odbijKarte = function(loc, odbij) {
            $.ajax({
                url: loc+'Ajax/Response.php?hash=odbijKarte&odbij='+odbij,
                type: 'GET',
                dataType: 'html',
                timeout: 4000,
                beforeSend: function()
                {
                    $('#kartaPracy').html('Proszę czekać…');
                },
                error: function(){
                    setTimeout('window.location.reload(true)', 500);
                },
                success: function(html){
                    $('#kartaPracy').html('Karta odbita.');
                    setTimeout('window.location.reload(true)', 500);
                }
            });
        }

        headline_count = $("div.headline").size();
        $("div.headline:eq("+current_headline+")").css('top','0px');

        headline_interval = setInterval(headline_rotate,6000); //time in milliseconds
        $('#scroll').hover(function() {
            clearInterval(headline_interval);
        },
        function() {
            headline_interval = setInterval(headline_rotate,6000); //time in milliseconds
            headline_rotate();
        });

        function headline_rotate()
        {
            current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
            $("div.headline:eq(" + old_headline + ")").animate({top: -25},"slow", function() {
                $(this).css('top','210px');
            });
            $("div.headline:eq(" + current_headline + ")").show().animate({top: 0},"slow");
            old_headline = current_headline;
        }
        //wywołaj f-cję obliczającą ilość wyników wyszukiwania przy załadowaniu strony szukaj_znajomych
        if ( $("#szukaj").length > 0 ) {
            szukajKontaktow();
        }

        //jeśli nie korzystamy z usług domu mediowego to odkomentować i będą szły tylko nasze reklamy
        //arbo_no_ad('bmone2n-1855.1.1.31');
        //arbo_no_ad('bmone2n-1855.1.1.30');
        //arbo_no_ad('bmone2n-1855.1.1.36');
        //arbo_no_ad('loginAd');
    });

    schowSchema = function(id)
    {
        if ('none' == $('#'+id).css('display'))
        {
            $('#'+id).css('display', 'block');
        }
        else
        {
            $('#'+id).css('display', 'none');
        }
        return false;
    }

    function loginLoad ()
    {
        t = 2500;
        document.getElementById('graczLoginPanel').style.display='none';
        document.getElementById('graczLoginLoader').style.display='block';
        submitForm = function () { document.getElementById('graczLoginForm').submit(); }
        setTimeout(submitForm, t);
    }

    //zaznacza wiele pól typu checkbox
    function setCheckbox(what,pref,state)
    {
        for(i=0;i<what.elements.length;i++)
        {
            if(what.elements[i].type == "checkbox" && what.elements[i].name.substring(0,pref.length) == pref)
        {
                what.elements[i].checked=state;
            }
        }
        document.getElementById(pref).disabled = true;
        szukajKontaktow();
    }

    //zapewnia aby przynajmniej 1 checkbox przy wyborze światopoglądow dla wyszukiwarki był zaznaczony
    function atLeastOneChecked(what,pref,actual)
    {
        isChecked = false;
        isUnchecked = false;
        for (i = 0; i < what.elements.length; i++)
        {
            if(what.elements[i].type == "checkbox" && what.elements[i].name.substring(0,pref.length) == pref && what.elements[i].checked)
            {
                isChecked = true;
            }
            if(what.elements[i].type == "checkbox" && what.elements[i].name.substring(0,pref.length) == pref && !what.elements[i].checked)
            {
                isUnchecked = true;
            }
        }
        if (!isChecked)
        {
            actual.checked = true;
        }
        if (isUnchecked)
        {
            document.getElementById(pref).disabled = false;
        }
        else
        {
            document.getElementById(pref).disabled = true;
        }
        szukajKontaktow();
    }

    szukajKontaktow = function()
    {
        var serializedForm = $('#formularzSzukaj').serialize();
        divId = '#iloscWynikow';
        $.ajax({
            url: '/Ajax/Response.php?hash=szukajZnajomych',
            type: 'POST',
            data: serializedForm,
            dataType: 'html',
            timeout: 3000,
            error: function(){
                $(divId).html('');
            },
            success: function(html){
                $(divId).html(html);
            }
        });
    }

    szukajAdresata = function()
    {
        var serializedForm = $('#formularzSzukaj').serialize();
        divId = '#wynikWyszukiwania';
        $.ajax({
            url: '/Ajax/Response.php?hash=szukajAdresatow',
            type: 'POST',
            data: serializedForm,
            dataType: 'html',
            timeout: 3000,
            error: function(){
                $(divId).html('');
            },
            success: function(html){
                $(divId).html(html);
            }
        });
    }

    //funkcja odpalana, gdy arbo nie emituje rekalmy
    arbo_no_ad = function(field_id)
    {
        var divId = '';
        if ('bmone2n-1855.1.1.31' == field_id
        || 'bmone2n-1855.2.1.31' == field_id
        )
        {
            type_id = 2;
            divId = '#adSky';
        }
        if ('bmone2n-1855.1.1.30' == field_id
        || 'bmone2n-1855.2.1.30' == field_id
        )
        {
            type_id = 1;
            divId = '#adBb';
        }
        if ('bmone2n-1855.1.1.36' == field_id
        || 'bmone2n-1855.2.1.36' == field_id
        )
        {
            type_id = 3;
            divId = '#adBox';
        }
        if ('loginAd' == field_id)
        {
            type_id = 4;
            divId = '#loginAd';
        }

        $.ajax({
            url: '/Ajax/Response.php?hash=loadAd',
            type: 'POST',
            data: {type: type_id, target_div: divId},
            dataType: 'html',
            timeout: 3000,
            error: function()
            {
                void(null);
            },
            success: function(html)
            {
                if ('' != html)
                {
                    $(divId).append(html);
                }
            }
        });
    }

    //reload if
    ifReload = function()
    {
        setTimeout(function()
        {
            window.frames['billboardIframe'].location.reload();
            ifReload();
        }, 30000);
    }






