function load_gallery(id)
{
    $("#picture").slideUp(500, function()
    {
        $("#picture").html('');
        $("#thumbnails").slideDown(500);
        $("#link_koncerty").removeClass('active');
        $("#link_lifestyle").removeClass('active');
        $("#link_peoples").removeClass('active');
        if (id==1) $("#link_koncerty").addClass('active');
        if (id==2) $("#link_lifestyle").addClass('active');
        if (id==3) $("#link_peoples").addClass('active');
        $("#gallery").animate({opacity: '0', height: 'toggle'}, 500, function(){
        $.ajax({
                   type: "POST",
                   url: "ajax/gallery_images/" + id,
                   success: function(html)
                   {
                       $("#gallery").html(html);
                       $("#gallery").animate({opacity: '1', height: 'toggle'}, 500);
                   }
                 });
        });
});
    
}
function close_image()
{
    $("#picture").slideUp(500, function()
        {
            $("#picture").html('');
            $("#thumbnails").slideDown(500);
        });
}


function show_image(image)
{
$('<img />')
    .attr('src', image)
    .load(function(){
        $("#thumbnails").slideUp(500, function(){
            $("#picture").html('<img src="'+image+'" alt="" onclick="close_image()" />').slideDown(1000);
        });
    });
}

function show_news(id)
{
    $("#newslist").slideUp(500, function(){
        $("#news_"+id).show(500);
    });
}
function hide_news(id)
{
    $("#news_"+id).hide(500, function(){
        $("#newslist").slideDown(500);
    })
}

function encodeutf(string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                    utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
            }

    }

    return utftext;
}

function load_guestbook(page, limit)
{
    $("#guestbook_list").hide(500);
    $.ajax({
               type: "POST",
               url: "ajax/load_guestbook/" + page+"-"+limit,
               success: function(html)
               {
                   $("#guestbook_list").html(html);
                   $("#guestbook_list").show(500);
               }
             });
}

function submit_questbook()
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    var validated = true;
    var inputs = [];
    $('.input_area').each(function() {
        if ((this.value == '') || ((this.name == 'mail') && !pattern.test(this.value)))
        {
            $(this).addClass('errorform');
            validated = false;
        } else
        {
            $(this).removeClass('errorform');
        }
        inputs.push(this.name + '=' + escape(encodeutf(this.value)));
    })

    if (validated)
    {
        $("#guestbook_form").hide(500);
        $("#guestbook_form").fadeOut(100);
        $.ajax({
                   type: "POST",
                   data: inputs.join('&'),
                   url: "ajax/submit_guestbook/",
                   success: function(html)
                   {
                       $("#guestbook_form").html('<span style="font size 13px; font-weight: bold;">'+html+'</span>');
                       $("#guestbook_form").show(500);
                       $("#guestbook_form").fadeIn(100);
                   }
                 });
    } else
    {
        $(".error").remove();
        $("#guestbook_form").append('<div class="error" style="color: #f00;">Zaznaczone pola są błędnie wypełnione.</div>');
    }
}
