$(document).ready(function () {
    $('#presentation_info').hide();

    $("a[rel='colorbox']").colorbox({width:"800px", height:"450px"});

    $("#eur_switcher").click(function (event) {
        $("#fees_rub").hide();
        $("#fees_eur").show();
        $("#eur_switcher").removeClass("switcher")
        $("#eur_switcher").addClass("switcher_selected")
        $("#rub_switcher").removeClass("switcher_selected")
        $("#rub_switcher").addClass("switcher")
    });

    $("#rub_switcher").click(function (event) {
        $("#fees_eur").hide();
        $("#fees_rub").show();
        $("#rub_switcher").removeClass("switcher")
        $("#rub_switcher").addClass("switcher_selected")
        $("#eur_switcher").removeClass("switcher_selected")
        $("#eur_switcher").addClass("switcher")
    });

    $('#schedule td.lecture, td.talk').each(function (i) {
        var tdel = $(this);
        var idx = tdel.attr('id');
        if (!(idx === undefined)) {
            $.getJSON('/wsc8/program/presentations/info/?idx=' + idx, function (data) {
                if (!$.isEmptyObject(data)) {
                    var abstract_file = data[0].fields.abstract_file;
                    if (abstract_file.length > 1) {
                        var ael = $('<a href="/media/' + abstract_file + '">' + data[0].fields.speaker.fields.last_name + '</a> ');
                    } else {
                        var ael = $('<span>' + data[0].fields.speaker.fields.last_name + '</span> ');
                    }

                    ael.appendTo(tdel);
                    ael.mouseenter(
                        function () {
                            html = '';
                            imgsrc = data[0].fields.speaker.fields.photo;
                            if (imgsrc.length < 1) {
                                imgsrc = 'files/persons/nophoto.jpg';
                            }
                            html += '<img src="/media/' + imgsrc + '" />';
                            html += '<div class="title">' + idx + '. ' + data[0].fields.title + '</div>';
                            html += '<div class="author">';
                            html += data[0].fields.speaker.fields.last_name + ' ' + data[0].fields.speaker.fields.first_name;
                            html += '</div>';

                            tdel.append($('#presentation_info'));
                            $('#presentation_info').html(html);
                            $('#presentation_info').css({top:ael.position().top + 20, left:ael.position().left - 100});
                            $('#presentation_info').show();

                        }).mouseleave(function () {
                            $('#presentation_info').hide();
                            $('#presentation_info').html('');
                        });

                }

            });
        }
    });

});
