$(function () {
    $("#topnews p").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400);
});



function popisekPodFotku(text) {
    $("#cboxContent").livequery(function () {
        $(this).append("<div id='cboxKecy'>" + text + "</div>");
    });
}

$(function () {

    var cbox = $("a[rel=colorbox]");

    cbox.colorbox({
        current: "{" + "current} / {" + "total}",
        previous: "p\u0159edchozí",
        next: "následující",
        close: "zav\u0159ít",
        slideshow: true,
        slideshowAuto: false,
        slideshowStart: "přehrát prezentaci",
        slideshowStop: "zastavit prezentaci"
    });

    $().bind('cbox_complete', function() {
        $("#cboxTitle span").remove();
        if ($("#cboxLoadedContent iframe").size() > 0) return;
        $("#cboxTitle").append(
        "<span> - <a href='' onclick='poslatDotaz(); return false' class='mail'>zeptejte se nás</a></span>"
    );
    });
});



// venesis
$(function () {
    $(".sidebar-tabs .box:not(.active)").hide();
    $(".sidebar-tabs .tabs a").click(function () {
        $(this).parents(".tabs").find("a").removeClass("active");
        $(this).parents(".sidebar-tabs").find(".box").hide();
        $(this).addClass("active");
        $($(this).attr("href")).show();
        return false;
    });
    
    $(".gallery-menu > div.toggle > a").click(function () {
        if ($(this).parent().find("ul").size() < 1) return true;

        $(this).parent().siblings().removeClass("active");

        $(this).parent().find("ul").slideToggle();
        $(this).parent().toggleClass("active");
        return false;
    });

    $(".gallery-menu > div.toggleAndOpen > a").click(function () {
        if ($(this).parent().find("ul").size() < 1) return true;

        $(this).parent().siblings().removeClass("active");

        $(this).parent().find("ul").slideToggle();
        $(this).parent().toggleClass("active");
    });
    
    $(".cboxelement").colorbox();

});

// konec venesis

$(function () {
    $("a.blank").click(function () {
        window.open(this.href);
        return false;
    });
});

// ajax
$(function () {
    // přidám spinner do stránky
    $('<div id="ajax-spinner"></div>').hide().ajaxStop(function () {
        // nastavení původních vlastností, třeba kvůli odesílání formuláře
        $(this).hide().css({
            position: "fixed",
            left: "50%",
            top: "50%"
        });
    }).appendTo("body");
});

// links
$("a.ajax").live("click", function (event) {
    event.preventDefault();

    if ($(this).is(".ask")) {
        if (!confirm("Opravdu?")) return;
    }

    $.get(this.href);

    // spinner position
    $("#ajax-spinner").css({
        position: "absolute",
        left: event.pageX + 20,
        top: event.pageY + 40
    }).show();
});

// neajaxové ptací odkazy
$("a.ask:not(.ajax)").live("click", function (event) {
    if (!confirm("Opravdu?")) {
        event.preventDefault();
    }
});

// form buttons
$("form.ajax :submit, :submit.ajax").live("click", function (event) {
    event.preventDefault();

    var form = $(this).is("form") ? $(this) : $(this.form);

    if (form.get(0).onsubmit && !form.get(0).onsubmit()) return false;

    $(this).ajaxSubmit({
        complete: function () {
            // enable
            form.find(":input").each(function () {
                $(this).attr("disabled", $(this).data("defaultDisabled"));
            });
        }
    });

    // spinner position
    if (event.pageX && event.pageY) {
        $("#ajax-spinner").css({
            position: "absolute",
            left: event.pageX + 20,
            top: event.pageY + 40
        });
    }

    $("#ajax-spinner").show();

    // set default disabled
    form.find(":input").each(function () {
        $(this).data("defaultDisabled", $(this).attr("disabled"));
    }).attr("disabled", true);
});

// forms
$("form.ajax").livequery("submit", function (event) {
    event.preventDefault();

    $(this).ajaxSubmit();
    $("#ajax-spinner").show();
});

// Zmizení flash zpráv
$("div.flash").livequery(function () {
    var el = $(this);
    setTimeout(function () {
        el.slideUp();
    }, 5000);
});

// date
$("input.datepicker").livequery(function () {
    $(this).datepicker();
});

/* Czech initialisation for the jQuery UI date picker plugin. */
/* Written by Tomas Muller (tomas@tomas-muller.net). */
jQuery(function($){
    
    $.datepicker.regional['cs'] = {
        closeText: 'Zavřít',
        prevText: '&#x3c;Dříve',
        nextText: 'Později&#x3e;',
        currentText: 'Nyní',
        monthNames: ['leden','únor','březen','duben','květen','červen',
            'červenec','srpen','září','říjen','listopad','prosinec'],
        monthNamesShort: ['leden','únor','březen','duben','květen','červen',
            'červenec','srpen','září','říjen','listopad','prosinec'],
        dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
        dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
        dayNamesMin: ['ne','po','út','st','čt','pá','so'],
        dateFormat: 'dd.mm.yy', firstDay: 1,
        isRTL: false};
    $.datepicker.setDefaults($.datepicker.regional['cs']);
});

//function poslatDotaz() {
//    $.fn.colorbox({
//        href: {plink Photo:dotaz} + "?image=" + encodeURIComponent($("#cboxLoadedContent img").attr("src"))
//            + "&description=" + encodeURIComponent($("#cboxTitle").text()),
//        iframe: true,
//        open: true,
//        width: 500,
//        height: 370
//    });
//};

//$(".photos-sortable").livequery(function () {
//    $(this).sortable({
//        handle: "img",
//        stop: function () {
//            $.get({link saveSort! $id} + "&" + $(".photos-sortable").sortable("serialize"));
//        }
//    });
//});
