--Main script 

var_secondary = true
var_secondaryTime = 0
tweens.park = 144
var_park = true
var_parkTime = 0.5

var_messSpeed = 3
tweens.mess = 0
var_dim = 1

tweens.tap = 0
tweens.reset = 1
var_resetTime = 0.5
var_doubleTapDelay = 0.5

wm_action('sw_reset')

tweens.zoom = 1
tweens.move = 1
var_reset = 0.5

-------------------

function tap()
	wm_schedule{action = 'tween', tween = 'tap', from = 1, to = 0, duration = var_doubleTapDelay, easing = linear} 
end

-- double chronograph by Ron D.

function park()
	wm_schedule{{action = 'tween', tween = 'reset', from = 1, to = 0, duration = var_resetTime, easing = linear},
{action = 'run_function', run_function = parkEnd}} 
end

function parkEnd()
   var_park = true

wm_action('sw_reset')
   tweens.reset = 1

wm_schedule{{action = 'tween', tween = 'park', from = 0, to = 138, duration = var_parkTime, easing = linear},{action = 'run_function', run_function = reset}} 
end

function reset()
   var_secondary = true
   var_secondaryTime = 0
end

function start()
	wm_schedule{{action = 'tween', tween = 'park', from = 180, to = 0, duration = var_parkTime, easing = linear},{action = 'run_function', run_function = run}} 
end

function run()
   var_park = false
end

-------------------

var_messSpeed = 3
tweens.mess = 0
var_dim = 1

-----Zoom
var_zoomout = 0.97
var_zoomring = 0.947
var_zoombez = 0.8
var_zoomdial = 0.97
var_zoomed = 0
tweens.zoom = var_zoomout

function zoom() 
  if var_zoomed == 2 then 
    wm_schedule { action='tween', tween='zoom', to=var_zoomdial, duration=1, easing=outBack } 
    var_zoomed = 0 
 else 
  if var_zoomed == 2 then 
    wm_schedule { action='tween', tween='zoom', to=var_zoomout, duration=1, easing=outBack } 
    var_zoomed = 0
 else 
  if var_zoomed ==  1 then 
    wm_schedule { action='tween', tween='zoom', to=var_zoombez, duration=1, easing=outBack } 
    var_zoomed = 2
 else
    wm_schedule { action='tween', tween='zoom', to=var_zoomring, duration=1, easing=outBack } 
    var_zoomed = 1
 end end end end


function dimmess()
	 wm_schedule{action = 'tween', tween = 'mess', from = 200, to = 0, duration = var_messSpeed, easing = outInExpo} 
end

tweens.rotate=360

function rotate_tick()
  wm_schedule {
    action='tween',
    tween='rotate',
    to=tweens.rotate-6,
    duration=0.3,
    easing=outQuad }
    tweens.rotate=tweens.rotate-6
end

function rotate_min()
if tweens.rotate<={drm} and tweens.rotate>0 then
 wm_schedule {
    action='tween',
    tween='rotate',
    to=0,
    duration=1.5,
    easing=outQuad }
    tweens.rotate=360
else
if tweens.rotate>{drm} then
 wm_schedule {
    action='tween',
    tween='rotate',
    to={drm},
    duration=1.5,
    easing=outQuad }
    tweens.rotate={drm} 
else 
if tweens.rotate==0 then
   tweens.rotate=360
 wm_schedule {
    action='tween',
    tween='rotate',
    to={drm},
    duration=1.5,
    easing=outQuad }
    tweens.rotate={drm}
end
end
end
end

-- Tap activation

var_lock=1

function lock()
    if var_lock == 2 then
        var_lock=1
    else
        var_lock=var_lock+1
    end
end
-- Theme set

var_settheme=1

function settheme()
    if var_settheme ==2 then
        var_settheme=1
    else
        var_settheme=var_settheme+1
    end
end

var_screen=1 
function screen()
  if var_screen==2 then
   var_screen=1
   else
   var_screen=var_screen+1
  end
end

var_tz=1
function tz()
 if var_tz <3 then
    var_tz = var_tz +1
else
var_tz =1
end
end

var_dcol=7

var_dcol1={'b5ffac','70ffe4','78dcff','ff4242','ffa740','feff00','02ff70'} 
var_dcol2={'1dff00','00ffb4','00b4ff','b20000','f3811e','b9a900','02ff70'} 
function dcol()
    if var_dcol == 7 then
        var_dcol=1
    else
        var_dcol=var_dcol+1
    end
end

var_color1={'ffffff','36D977','373737','E00C25','FF5230','FD7450','FF9501','F9DA0F','9EFF2F','ADEC9D','BCFFF4','7BE2FF','19BAFF','63AEEF','C0D8FC','80ACFF','9E81FF','B29AA7','F3C2BD','F4B1AB','FF5963','F5ACA5','B18664','AF9981','D4B694','9C8E8D','CC00FF','F100C1','008545','7F7A40','8C5B23'}
var_colornum=1

function setcolor()
if var_colornum==31 then
var_colornum=1
else
var_colornum=var_colornum+1
end
end

var_12hr=0


-- Bright set

var_bright=1

function bright()
    if var_bright == 5 then
        var_bright=1
    else
        var_bright=var_bright+1
    end
end

var_lock =1 
tweens.tap=0 
function taplock()
	wm_schedule{action = 'tween', tween = 'tap', from = 1, to = 0, duration =0.5 , easing = linear} 
end
tweens.delay=2000
function tapdelay()
	wm_schedule{action = 'tween', tween = 'delay', from = 2000, to = 1, duration =0.7 , easing = linear} 
end

function lock()
if tweens.tap == 0 then
tapdelay()
var_lock=1 
   taplock()
else
  var_lock=0 
menu()
end
fade_lock()
end--function

tweens.lock=0 
function fade_lock()
wm_schedule { action='tween', tween='lock', from=200,to=0, duration=10, easing=outExpo}
end


function tap()
      wm_schedule{action = 'tween', tween = 'tap', from = 1, to = 0, duration = 0.25, easing = linear} 
end

function startstop()
	  wm_action('sw_start_stop') 
end

function reset()
   wm_action('sw_reset')
end

var_park = 360
tweens.rotate_sec = math.floor({drss}/1.2)*1.2
tweens.rotate_min = {drm}
tweens.rotate_hour = {drh}

function tweenme(rot,f,t,d,e)
	 if d == nil then 
       d = 1
end
	 if e == nil then 
       e = inOutQuint
end
	 wm_schedule {action='tween', tween=rot, from =f, to = t, duration=d, easing=e} 
end

function park()
    tweenme('rotate_sec',tweens.rotate_sec,var_park)
    tweenme('rotate_min',tweens.rotate_min,var_park)
    tweenme('rotate_hour',tweens.rotate_hour,var_park)
end

function unpark()
    tweenme('rotate_sec',tweens.rotate_sec,math.floor({drss}/1.2)*1.2)
    tweenme('rotate_min',tweens.rotate_min,{drm})
    tweenme('rotate_hour',tweens.rotate_hour,{drh})
end

function on_millisecond()
    if {swsst} == 0 then
    tweens.rotate_sec = math.floor({drss}/1.2)*1.2
    tweens.rotate_min = {drm}
    tweens.rotate_hour = {drh}
   end
end