<html>
<head>
<!-- Start WB Insert -->
<script>
  wbinfo = {}
  wbinfo.capture_str = " ";
  wbinfo.is_embed = false;
  wbinfo.prefix = "{{ wbrequest.wb_prefix }}";
  wbinfo.capture_url = "{{ url }}";
  wbinfo.is_frame = true;
</script>
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.js'> </script>
<script>

var update_wb_url = push_state;

function make_outer_url(url, ts)
{
    if (ts) {
        return wbinfo.prefix + ts + "/" + url;
    } else {
        return wbinfo.prefix + url;
    }
}

function make_inner_url(url, ts)
{
    if (ts) {
        return wbinfo.prefix + ts + "mp_/" + url;
    } else {
        return wbinfo.prefix + "mp_/" + url;
    }
}

function push_state(url, timestamp, capture_str, is_live) {
    var curr_href = null;
    
    if (window.frames[0].WB_wombat_location) {
        curr_href = window.frames[0].WB_wombat_location.href;
    }
        
    if (url != curr_href) {
        update_status(capture_str, is_live);
        return;
    }
    
    if (!timestamp) {
        timestamp = extract_ts(window.frames[0].location.href);
    }
    
    var state = {}
    state.timestamp = timestamp;
    state.outer_url = make_outer_url(url, state.timestamp);
    state.inner_url = make_inner_url(url, state.timestamp);
    state.url = url;
    state.capture_str = capture_str;
    state.is_live = is_live;
    
    window.history.replaceState(state, "", state.outer_url);

    update_status(state.capture_str, is_live);
}

function pop_state(state) {
    update_status(state.capture_str, state.is_live);
    
    window.frames[0].src = state.outer_url;
}

function extract_ts(url)
{
    var inx = url.indexOf("mp_");
    if (inx < 0) {
        return "";
    }
    url = url.substring(0, inx);
    inx = url.lastIndexOf("/");
    if (inx <= 0) {
        return "";
    }
    return url.substring(inx + 1);
}

function update_status(str, is_live) {
    var capture_info = document.getElementById("_wb_capture_info");
    if (capture_info) {
        capture_info.innerHTML = str;
    }

    var label = document.getElementById("_wb_label");
    if (label) {
        if (is_live) {
            label.innerHTML = _wb_js.labels.LIVE_MSG;
        } else {
            label.innerHTML = _wb_js.labels.REPLAY_MSG;
        }
    }
}

window.onpopstate = function(event) {
    var curr_state = event.state;
    
    if (curr_state) {
        pop_state(curr_state);
    }
}

</script>
<link rel='stylesheet' href='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.css'/>
<!-- End WB Insert -->
<body style="margin: 0px; padding: 0px;">
<div class="wb_iframe_div">
<iframe src="{{ wbrequest.wb_prefix + embed_url }}" seamless="seamless" frameborder="0" scrolling="yes" class="wb_iframe"/>
</div>
</body>
</html>
