$(document).ready(function ($) {
    $("#galleryImages").easySlider({
        auto: true,
        continuous: true,
        controlsShow: true,
        nextId: 'imgNext',
        prevId: 'imgPrev',
        prevText: 'Poprzednie',
        nextText: 'Następne'
    });

    //Rezerwacje:
    $('#reservationDlg').dialog({
        autoOpen: false,
        width: 750,
        height: 450,
        modal: true,
        resizable: false,
        title: 'Rezerwacja on-line',
        buttons: [
        {
            text: "Wyślij",
            click: function () {
                var errors = 0;
                $('.req').each(function () {
                    if ($(this).val() == '' || $(this).val() == ' ') {
                        errors++;
                        $(this).addClass('error');
                    }
                    else {
                        $(this).removeClass('error');
                    }
                });

                if (!errors) {

                    $(this).dialog("close");
                    $.post('/formsend.php', $('#reservationForm').serialize(), function (data) {
                        $('<div>Dziękujemy za wysłanie formularza.</div>').dialog({
                            modal: true,
                            resizable: false,
                            title: 'Rezerwacja on-line',
                            buttons: [
                        {
                            text: "Zamknij",
                            click: function () { $(this).dialog("close"); }
                        }
                        ]
                        });
                    });
                }
            }
        },
        {
            text: "Anuluj",
            click: function () { $(this).dialog("close"); }
        }
        ]
    });
    $("#rezerwacjaBtn").attr('href', 'javascript:;');
    $("#rezerwacjaBtn").click(function () {
        $('#reservationDlg').dialog('open');
    });

    $("a[rel^='prettyPhoto']").prettyPhoto();

    /*$(".gal_image_obj").each(function () {
    $(this).css('cursor', 'pointer');
    $(this).click(function () {
    $.prettyPhoto.open($(this).attr('data-image', '', ''));
    });
    });*/

    //$(".callendar").datepicker();

    if ($('#infownd').html() != '') {
        var initiated = 0;
        $('#infownd img').each(function () {
            if (!initiated) {
                initiated = 1;
                $.prettyPhoto.open( $(this).attr('src'), '', '');
            }
        });
    }

});

function showMore(element, directory, source) {
    //alert(source);
    var elements = '<div id="imagesMoreBlock_' + directory + '" style="display: none;">';
    for (var i = 0; i < source.length; i++) {
        elements = elements + '<div style="margin-right: 5px; margin-bottom: 5px; position: relative; float: left; border-color: #e98e0c !important;" class="gal_image_obj ui-widget-content ui-corner-all"><div style="background-position: center center; background-repeat: no-repeat; border: 0 none !important; height: 100px; margin: 3px; width: 100px; float: left; background-image: url(/image,150,150/media/__gallery/' + directory + '/' + source[i] + ') !important;" class="ui-widget-content ui-corner-all"><a href="/media/__gallery/' + directory + '/' + source[i] + '" rel="prettyPhoto" style="display: block; width: 100%; height: 100%;"></a></div></div>';
    }
    elements = elements + '</div>';
    $(element).parent().html(elements);

    $('#imagesMoreBlock_' + directory).fadeIn();

    $("a[rel^='prettyPhoto']").prettyPhoto();
}
