---------------------
--    VARIABLES    --
---------------------

var_face=1
var_i=0
var_date=true
var_sw=false
var_ba=false
var_se=false
var_top=0

tweens.hr={drh}
tweens.mi={drm}
tweens.se={drs}
park=0

tweens.corv=100
tweens.time=0

tweens.tap=0
tweens.z=0
tweens.o=0
tweens.b=0
tweens.s=0
tweens.c=0


---------------------
--      ARRAYS     --
---------------------

day={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}

back_col={'515a2c','e1e0d1','201f1f'}
fron_col={'d28557','dce9ce','6a6a6a'}
text_col={'ffffff','473d0d','cccccc'}


---------------------
--    FUNCTIONS    --
---------------------

function var_agenda(e)
if wm_tag('{c' .. e .. 'ex}') then
  t=wm_tag('{c' .. e .. 't}')
  b=wm_tag("{c" .. e .. "b}")
  c="   " .. b .. ": " .. t
  if string.sub(t,3,3)==":" then
--  swap time and day
    p=string.sub(t,1,2) .. " "
    q=string.sub(t,5)
    c=p .. b .. ": " .. q
  end
  if string.sub(c,1,4)~="   :" then
    return(string.sub(c,1,31))
   else
    return("")
  end
 else
 if e==1 then return('    No calendar entries') else return("") end
end
end


function entries()
e=0
for i=1,6 do
 if wm_tag('{c' .. i .. 't}')~="" then e=e+1 end
end
if e==0 then e=1 end
return(-(e-1)*20)
end

-- var_top=entries()
-- e is the number of agenda entries,
-- var_top is the y-position of the first entry.



function on_second()
if park>0 then
  if park==10 then
    var_tween('dh',0,{drh},1,linear)
    var_tween('mi',0,{drm},1,linear)
    var_tween('se',0,{drs}+2,1,linear)
  end
  park=park+1
  if park==2 then
    var_tween('corv',100,0,1,linear)
    var_tween('time',0,100,1,linear)
  end
  if park==10 then
    var_tween('corv',0,100,1,linear)
    var_tween('time',100,0,1,linear)
  end
  if park>10 then park=0 end
 else
  tweens.dh={drh}
  tweens.mi={drm}
  tweens.se={drs}
end
if var_i<1 then var_i=0 end
end



function on_display_not_bright()
var_i=0
tweens.z=0
end


function var_tap(Du)
wm_schedule{action = 'tween', tween = 'tap', from = 100, to = 0, duration = Du, easing = linear} 
end


function var_tween(Tw,Fr,To,Du,Ea)
wm_schedule { 
   {action='tween', tween=Tw, from=Fr, to=To, duration=Du, easing=Ea}
}
end