 
 current_state = {}
 
-update_years = (year_a_idx, opacity) ->
+update_years = (state) ->
+    year_a_idx = state.layer_a_idx
+    opacity = 1 - state.layer_b_opacity
+    console.log year_a_idx
+    console.log opacity
     for year_el, idx in $("#year_list div")
         if idx == year_a_idx
             opa = opacity * (1 - MIN_OPACITY)

            opa = 0
        $(year_el).css {"opacity": MIN_OPACITY + opa}

update_screen = (val) ->
    if val == current_state.val
        return
    current_state.val = val
    layer_a_idx = Math.floor val / N_STEPS
    if val == slider_max
        layer_a_idx = layer_count - 2
    current_state.layer_a_idx = layer_a_idx

    layer_b_op = (val % N_STEPS) / N_STEPS
    if val == (layer_a_idx + 1) * N_STEPS
        layer_b_op = 1.0

    visible_layers = [orto_layers[layer_a_idx], orto_layers[layer_a_idx+1]]
    visible_layers[0].setOpacity 1 - layer_b_op
    visible_layers[1].setOpacity layer_b_op
    current_state.visible_layers = visible_layers

    update_years layer_a_idx, 1 - layer_b_op

    $("#year_a").html orto_years[layer_a_idx]
    $("#year_b").html orto_years[layer_a_idx + 1]
    $("#year_a").css {opacity: 1 - layer_b_op}
    $("#year_b").css {opacity: layer_b_op}

    # Set visibility flags on all layers and hide the non-visible layers.
    for al in orto_layers

    layer = L.tileLayer GWC_BASE_URL + "tms/1.0.0/hel:orto#{year}@EPSG:900913@jpeg/{z}/{x}/{y}.jpeg",
        tms:true
    return layer

orto_years = [
    1943, 1964, 1976, 1988, 2012
