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

var_max        = 6  -- number of info dials
var_info       = 1  -- first info dial
var_sw     = false  -- no stopwatch initially
var_agenda = false  -- no agenda initially
var_weather =false  -- no weather initially
first       = true  -- controls the markers animation
tweens.markers = 0  -- controls the markets location
tweens.pic     = 0  -- controls the pictures animation
tweens.agenda =  0  -- controls the agenda opacity
tweens.text   =  0  -- controls the agenda text opacity
tweens.weather = 0  -- controls the weather opacity
tweens.wtext   = 0  -- controls the weather text opacity
tweens.sec = {drs}  -- controls the second hand
tweens.min = {drm}  -- controls the minute hand
tweens.hrs = {drh}  -- controls the hour hand
tweens.time    = 0  -- controls the digital time
count         = -1  -- sets the pictures animation
tweens.tap     = 0  -- controls the double tap
var_names      = 8  -- the number of players names
var_n          = 1  -- the first players name
var_pic        = 1  -- the first player picture

var_name = {'R  O  G  E  R        F  E  D E  R  E  R      ',           'S T E F F I                G R A F             ','M A R T.       N A V R Á T I L O V Á    ','P E T E                S A M P R A S           ','S E R E N A          W I L L I A M S         ','B J Ö R N                 B O R G            ','V E N U S            W I L L I A M S          ','N O V A K          D J O K O V I Ć         '}
var_days = {'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'}


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

function var_hand(i)
if i == 1 then return({dd}*12) end
if i == 2 then return({dn}*30) end
if i == 3 then return(math.abs({wt}*9)) end
if i == 4 then return(({shr}-40)*2.25) end
if i == 5 then return({ssc}*0.036) end
if i == 6 then return({drs}) end
end


function on_second()
if {abright} then
   if not var_sw then
      tweens.sec = {drs}
      tweens.min = {drm}
      tweens.hrs = {drh}
   end
   if count>-1 then
      if count==0 then
         var_tween('pic',0,200,3,linear)
      end
      count=count+1
      if count>3 then
         var_tween('pic',200,0,3,linear)
         count=-1
      end
   end
   if first then
      var_tween('markers',30,0,3,inOutBack)
      first=false
   end
  else
   count=-1
   tweens.pic=0
   first=true
   tweens.markers=6
end
end


function on_millisecond()
if var_sw then tweens.sec = {swrss} end
end


function on_minute()
   var_n = var_n %var_names + 1
   var_pic = var_pic%4 + 1
   if not var_sw then count = 0 end
end


function var_times()
r = string.char(10)
m = ''
if {c1ex} then m = {c1b} end
if {c2ex} then m = m .. r .. {c2b} end
if {c3ex} then m = m .. r .. {c3b} end
if {c4ex} then m = m .. r .. {c4b} end
return(m)
end


function var_calendar()
r = string.char(10)
if {c1ex} then t = {c1t} else t = 'No entries' end
if {c2ex} then t = t .. r .. {c2t} end
if {c3ex} then t = t .. r .. {c3t} end
if {c4ex} then t = t .. r .. {c4t} end
return(t)
end


function on_display_bright()
var_agenda = false
tweens.agenda = 0
tweens.text = 0
var_weather = false
tweens.weather = 0
tweens.wtext = 0
tweens.pic = 0
count = -1
if var_sw then tweens.min = 0 tweens.hrs = 0 end
end


function on_display_not_bright()
tweens.min = {drm}
tweens.hrs = {drh}
end


-------------------------------------
--       ANIMATION
-------------------------------------

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