function render(v) {
    $.ajax({
        url: '/c/render/'+parseInt(v),
        dataType: 'text',
        success: function(a, b, c) {
            if (b == 'success') {
                $('#search_issue').append(a);
            }
        }
    });
}

function searching() {
    var query = $('#search_text').attr('value');
    $.ajax({
        url: '/search',
        dataType: 'json',
        data: {
            q: query
        },
        success: function(a, b, c) {
            $('#search_issue').hide();
            if (b == 'success') {
                var items = jQuery.parseJSON(a['items']);
                $('#search_issue').empty();
                $.each(items, function(i, v) {
                    render(v);
                });
                $('#search_issue').fadeIn('slow');
            }

        }
    });
}

function view_news(id) {
    news_in = $('#news_target').html();
    $.ajax({
        url: '/start/view_news/'+id,
        dataType: 'html',
        success: function(a, b, c) {
            $('#news_target').fadeOut('fast');
            $('#news_target').html(a);
            $('#news_target').fadeIn('slow');
        }
    });
}

function revert_news() {
    $('#news_target').fadeOut('fast');
    $('#news_target').html(news_in);
    $('#news_target').fadeIn('slow');
}

function save_star(target, vid, vote) {
    $.ajax({
        url: '/c/vote',
        dataType: 'json',
        data: {
            target: target,
            vid: vid,
            vote: vote
        },
        success: function(a, b, c) {
            $('.voting_before').hide();
            $('.voting_before').show();
        }
    });
}

function initArray() {
    this.length = initArray.arguments.length
    for (var i = 0; i < this.length; i++) this[i+1] = initArray.arguments[i];
}

function havinev(ev,ho,nap) {

    if (ho==1)

    {
        var napok = new initArray("ÚJÉV, Fruzsina","Ábel","Genovéva, Benjámin","Titusz, Leona",

            "Simon","Boldizsár","Attila, Ramóna","Gyöngyvér","Marcell",

            "Melánia","Ágota","ErnO","Veronika","Bódog","Lóránt, Loránd",

            "Gusztáv","Antal, Antónia","Piroska","Sára, Márió","Fábián, Sebestyén",

            "Ágnes","Vince, Artúr","Zelma, Rajmund","Timót","Pál","Vanda, Paula",

            "Angelika","Károly, Karola","Adél","Martina, Gerda","Marcella","")
    }

    if (ho==2)

        if ((ev!=2000) && (ev!=2004) && (ev!=2008) && (ev!=2012)  && (ev!=2016) && ev!=1996)

        {
            var napok=new initArray("Ignác","Karolina, Aida","Balázs","Ráhel, Csenge","Ágota, Ingrid",

                "Dorottya, Dóra","Tódor, Rómeó","Aranka","Abigél, Alex","Elvira",

                "Bertold, Marietta","Lívia, Lídia","Ella, Linda","Bálint, Valentin",

                "Kolos, Georgina","Julianna, Lilla","Donát","Bernadett","Zsuzsanna",

                "Aladár, Álmos","Eleonóra","Gerzson","Alfréd",

                "Mátyás","Géza","Edina","Ákos, Bátor","Elemér","","")
        }

        else

        {
            var napok=new initArray("Ignác","Karolina, Aida","Balázs","Ráhel, Csenge","Ágota, Ingrid",

                "Dorottya, Dóra","Tódor, Rómeó","Aranka","Abigél, Alex","Elvira",

                "Bertold, Marietta","Lívia, Lídia","Ella, Linda","Bálint, Valentin",

                "Kolos, Georgina","Julianna, Lilla","Donát","Bernadett","Zsuzsanna",

                "Aladár, Álmos","Eleonóra","Gerzson","Alfréd",

                "Szokonap","Mátyás","Géza","Edina","Ákos, Bátor","Elemér","","")
        }

    if (ho==3)

    {
        var napok=new initArray("Albin","Lujza","Kornélia","Kázmér","Adorján, Adrián","Leonóra, Inez",

            "Tamás","NEMZ.NONAP, Zoltán","Franciska, Fanni","Ildikó","Szilárd",

            "Gergely","Krisztián, Ajtony","Matild","NEMZETI ÜNNEP, Kristóf",

            "Henrietta","Gertrúd, Patrik","Sándor, Ede","József, Bánk","Klaudia",

            "Benedek","Beáta, Izolda","Emoke","Gábor, Karina","Irén, Irisz",

            "Emánuel","Hajnalka","Gedeon, Johanna","Auguszta","Zalán","Árpád","" )
    }

    if (ho==4)

    {
        var napok=new initArray("Hugó","Áron","Buda, Richárd","Izidor","Vince","Vilmos, Bíborka",

            "Herman","Dénes","Erhard","Zsolt","Leó, Szaniszló","Gyula","Ida",

            "Tibor","Anasztázia, Tas","Csongor","Rudolf","Andrea, Ilma","Emma",

            "Tivadar","Konrád","Csilla, Noémi","Béla","György","Márk","Ervin",

            "Zita","Valéria","Péter","Katalin, Kitti","" )
    }

    if (ho==5)

    {
        var napok=new initArray("MUNKA ÜNN.,Fülöp, Jakab","Zsigmond","Tímea, Irma","Mónika, Flórián",

            "Györgyi","Ivett, Frida","Gizella","Mihály","Gergely","Ármin, Pálma",

            "Ferenc","Pongrác","Szervác, Imola","Bonifác","Zsófia, Szonja",

            "Mózes, Botond","Paszkál","Erik, Alexandra","Ivó, Milán",

            "Bernát, Felícia","Konstantin","Júlia, Rita","Dezso","Eszter, Eliza",

            "Orbán","Fülöp, Evelin","Hella","Emil, Csanád","Magdolna",

            "Janka, Zsanett","Angéla, Petronella","" )
    }

    if (ho==6)

    {
        var napok=new initArray("Tünde","Kármen, Anita","Klotild","Bulcsú","Fatime","Norbert, Cintia",

            "Róbert","Medárd","Félix","Margit, Gréta","Barnabás","Villo",

            "Antal, Anett","Vazul","Jolán, Vid","Jusztin","Laura, Alida",

            "Arnold, Levente","Gyárfás","Rafael","Alajos, Leila","Paulina",

            "Zoltán","Iván","Vilmos","János, Pál","László","Levente, Irén",

            "Péter, Pál","Pál","" )
    }

    if (ho==7)

    {
        var napok=new initArray("Tihamér, Annamária","Ottó","Kornél, Soma","Ulrik","Emese, Sarolta",

            "Csaba","Appolónia","Ellák","Lukrécia","Amália","Nóra, Lili",

            "Izabella, Dalma","Jeno","Ors, Stella","Henrik, Roland","Valter",

            "Endre, Elek","Frigyes","Emília","Illés","Dániel, Daniella",

            "Magdolna","Lenke","Kinga, Kincso","Kristóf, Jakab","Anna, Anikó",

            "Olga, Liliána","Szabolcs","Márta, Flóra","Judit, Xénia","Oszkár","" )
    }

    if (ho==8)

    {
        var napok=new initArray("Boglárka","Lehel","Hermina","Domonkos, Dominika","Krisztina",

            "Berta, Bettina","Ibolya","László","Emod","Lörinc",

            "Zsuzsanna, Tiborc","Klára","Ipoly","Marcell","Mária","Ábrahám",

            "Jácint","Ilona","Huba","ALKOTMÁNY ÜNN., István","Sámuel, Hajna",

            "Menyhért, Mirjam","Bence","Bertalan","Lajos, Patrícia","Izsó",

            "Gáspár","Ágoston","Beatrix, Erna","Rózsa","Erika, Bella")
    }

    if (ho==9)

    {
        var napok= new initArray("Egyed, Egon","Rebeka, Dorina","Hilda","Rozália","Viktor, Lorinc",

            "Zakariás","Regina","Mária, Adrienn","Ádám","Nikolett, Hunor",

            "Teodóra","Mária","Kornél","Szeréna, Roxána","Eniko, Melitta","Edit",

            "Zsófia","Diána","Vilhelmina","Friderika","Máté, Mirella","Móric",

            "Tekla","Gellért, Mercédesz","Eufrozina, Kende","Jusztina","Adalbert",

            "Vencel","Mihály","Jeromos","" )
    }

    if (ho==10)

    {
        var napok= new initArray("Malvin","Petra","Helga","Ferenc","Aurél","Brúnó, Renáta","Amália",

            "Koppány","Dénes","Gedeon","Brigitta","Miksa","Kálmán, Ede","Helén",

            "Teréz","Gál","Hedvig","Lukács","Nándor","Vendel","Orsolya","Elod",

            "KÖZT.KIKIÁLT., Gyöngyi","Salamon","Blanka, Bianka","Dömötör",

            "Szabina","Simon, Szimonetta","Nárcisz","Alfonz","Farkas","" )
    }

    if (ho==11)

    {
        var napok=new initArray("Marianna","Achilles","Gyozo","Károly","Imre","Lénárd","Rezso",

            "Zsombor","Tivadar","Réka","Márton","Jónás, Renátó","Szilvia",

            "Aliz","Albert, Lipót","Ödön","Hortenzia, Gergo","Jeno","Erzsébet",

            "Jolán","Olivér","Cecília","Kelemen, Klementina","Emma","Katalin",

            "Virág","Virgil","Stefánia","Taksony","András, Andor","" )
    }

    if (ho==12)

    {
        var napok=new initArray("Elza","Melinda, Vivien","Ferenc, Olívia","Borbála, Barbara","Vilma",

            "Miklós","Ambrus","Mária","Natália","Judit","Árpád","Gabriella",

            "Luca, Otília","Szilárda","Valér","Etelka, Aletta","Lázár, Olimpia",

            "Auguszta","Viola","Teofil","Tamás","Zéno","Viktória","Ádám, Éva",

            "KARÁCSONY, Eugénia","KARÁCSONY, István","János","Kamilla",

            "Tamás, Tamara","Dávid","Szilveszter","")
    }

    return napok[nap]

}

function honev(ho) {

    var month = new initArray("Január","Február","Március","Április","Május",

        "Junius","Július","Augusztus","Szeptember","Október","November","December");

    return month[ho]

}

/* Nap neve */

function napnev(szam) {

    var napok = new initArray("Vasárnap","Hétfo","Kedd","Szerda","Csütörtök","Péntek","Szombat","Vasárnap")

    return napok[szam]

}


function view_gallery(id) {
    $.ajax({
        url: '/a/gallery/'+id,
        success: function(a) {
            $('.popup').html(a);
        }
    });
    var galleries = $('.ad-gallery').adGallery({
        loader_image: '/img/loader.gif',
        width: 600, // Width of the image, set to false and it will read the CSS width
        height: 400, // Height of the image, set to false and it will read the CSS height
        thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
        // Note that this effect combined with other effects might be resource intensive
        // and make animations lag
        start_at_index: 0, // Which image should be displayed at first? 0 is the first image
        description_wrapper: $('#descriptions'), // Either false or a jQuery object, if you want the image descriptions
        // to be placed somewhere else than on top of the image
        animate_first_image: false, // Should first image just be displayed, or animated in?
        animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
        display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
        display_back_and_forward: true, // Are you allowed to scroll the thumb list?
        scroll_jump: 0, // If 0, it jumps the width of the container
        slideshow: {
            enable: true,
            autostart: true,
            speed: 5000,
            start_label: 'Start',
            stop_label: 'Stop',
            stop_on_scroll: true, // Should the slideshow stop if the user scrolls the thumb list?
            countdown_prefix: '(', // Wrap around the countdown
            countdown_sufix: ')',
            onStart: function() {
            // Do something wild when the slideshow starts
            },
            onStop: function() {
            // Do something wild when the slideshow stops
            }
        },
        effect: 'slide-hori', // or 'slide-vert', 'resize', 'fade', 'none' or false
        enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
        cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
        // All callbacks has the AdGallery objects as 'this' reference
        callbacks: {
            // Executes right after the internal init, can be used to choose which images
            // you want to preload
            init: function() {
                // preloadAll uses recursion to preload each image right after one another
                this.preloadAll();
                // Or, just preload the first three
                this.preloadImage(0);
                this.preloadImage(1);
                this.preloadImage(2);
            },
            // This gets fired right after the new_image is fully visible
            afterImageVisible: function() {
                // For example, preload the next image
                var context = this;
                this.loading(true);
                this.preloadImage(this.current_index + 1,
                    function() {
                        // This function gets executed after the image has been loaded
                        context.loading(false);
                    }
                    );

                // Want slide effect for every other image?
                if(this.current_index % 2 == 0) {
                    this.settings.effect = 'slide';
                } else {
                    this.settings.effect = 'fade';
                }
            },
            // This gets fired right before old_image is about to go away, and new_image
            // is about to come in
            beforeImageVisible: function(new_image, old_image) {
            // Do something wild!
            }
        }
    });

    centerPopup();
    loadPopup();

}

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}


//centering popup
function centerPopup(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });

}


//Press Escape event!
$(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
        disablePopup();
    }
});

