$(document).ready(function() {

    var ifrem = $();

    var cid = getParameterByName("cid");
    if (!cid || typeof(cid) == "undefined")
        cid = "ut"
    var main = $("#hack_main").on('mouseover', 'iframe', function(e) {
        $(this).focus();
    });
    api_stat(function(data) {
        var str = '  <h4 class="col-md-offset-1">在线人数：<span>{online} </span></h4><h4  class="col-md-offset-1">参赛人数：<span>{total}</span></h4>';
        $('#stat').html(str.format(data));
    })
    $(document).bind('tiemer', function(e, d) {
        var $timer = $('#end_timer');
        var timerTmpe = '{day}天{hour}小时{minute}分钟{second}秒';
        if (d.end_time) {
            var enddate = new Date(d.end_time)
            Countdown(enddate, function(timer) {
                if (timer) {
                    $timer.text(timerTmpe.format(timer))
                } else {
                    $('#timer').text('本次活动已结束，非常感谢您的参与。')
                }
            })
        } else {
            $('#timer').text('本次活动已结束，非常感谢您的参与。')
        }
    });
    var smscress = $('.smallscreen').on('click', 'a', function(e) {
        ifrem.removeClass('work-full');
        smscress.hide();
    })
    $('.nav a[data-action="fullscreen"]').bind('click', function(e) {
        ifrem.addClass('work-full')
        smscress.show();
    });
    /*$(document, 'html,body,iframe').keydown(function(e) {
        e = window.event || e || e.which;
        if (e.ctrlKey && e.which == 113) {
            ifrem.toggleClass('work-full', function(e) {
                console.log();
            });
            e.preventDefault()
            return false;
        }
    });*/

    function checkstart(id, callback) {
        setTimeout(loopstart);

        function loopstart() {
            hget('/api/user/experiment?id=' + id,
                function(data) {
                    if (data.status == 2) { // expr is running
                        callback(data)
                    } else {
                        setTimeout(loopstart, 60000);
                    }
                },
                function(err) {
                    callback(err);
                }
            );
        };
    }

    hpost('/api/user/experiment', {
            "cid": cid,
            "hackathon": CONFIG.hackathon.name
        },
        function(resp) {
            var data = resp
            var tmpe = '<div class="row ">\
                        <div class="col-md-12 text-center">\
                            <a href="javascript:;" title="" class="vm-box"  id="{name}"  data-url="{url}">\
                                <img src="/static/pic/dseries.png" alt="">\
                            </a>\
                            <h4>{name}<h4>\
                        </div>\
                    </div>';
            checkstart(data.expr_id, function(data) {
                var servers = data.guacamole_servers;
                var work_center = $('.center').on('mouseover', 'iframe', function(e) {
                    $(this).focus();
                });
                var hnav = $(".hackathon-nav").on('click', 'a.vm-box', function(e) {
                    hnav.find('.vm-box').removeClass('active')
                    var a = $(this).addClass('active');
                    var url = a.data('url');
                    var name = a.attr('id')
                    ifrem = work_center.find('#' + name);
                    work_center.find('iframe').addClass('invisible');
                    if (ifrem.length > 0) {
                        ifrem.removeClass('invisible');
                    } else {
                        ifrem = $('<iframe>').attr({
                            src: url + "&token=" + get_token(),
                            id: name,
                            width: '100%',
                            height: '100%',
                            frameborder: 'yes',
                            marginwidth: '10',
                            scrolling: 'yes'
                        }).appendTo(work_center)
                    }
                });
                $.each(servers, function(i, s) {
                    hnav.append(tmpe.format(s));
                });
                hnav.find('a.vm-box:eq(0)').trigger('click');
            })
        },
        function(data) {
            $('#load').hide();
            $('#error').show();
        }
    );
})

@@ -2695,16 +2695,30 @@
      %3Ch4
+ name=%22dserie%22
 %3E%7Bname%7D%3C
@@ -2866,16 +2866,39 @@
 ervers =
+ data.remote_service %7C%7C
  data.gu
@@ -4073,32 +4073,33 @@
             %7D);%0A
+%0A
                 
@@ -4155,34 +4155,414 @@
     
-hnav.append(tmpe.format(s)
+var puburls = s.public_urls %7C%7C data.public_urls%0A                    var vm = $(tmpe.format(s))%0A                    $.each(puburls, function(i, urls) %7B%0A                        vm.find('h4%5Bname%5D').append('%3Ch4 class=%22col-md-offset-1%22%3E%E6%82%A8%E5%9C%A8%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%83%A8%E7%BD%B2%E7%9A%84%E5%BA%94%E7%94%A8%E6%88%96%E7%BD%91%E7%AB%99%E5%8F%AF%E8%AE%BF%E9%97%AE%E4%B8%8B%E9%9D%A2%E5%9C%B0%E5%9D%80%EF%BC%9A%3C/h4%3E%3Ch4 class=%22col-md-offset-1%22%3E%3Ca href=%22%7Burl%7D%22 target=%22_blank%22%3E%7Burl%7D%3C/a%3E%3C/h4%3E'.format(urls))%0A                    %7D);%0A                    hnav.append(vm
 );%0A 

update public urls