# tpminka 9/9/00
# ali rahimi 9/12/00
# Draw a red line at the current time.

#puts "Running site.tcl"

set timeline_color red1

append-hook dayview-startup {view} {
    upvar #0 $view slot
    timeline_update $slot(apptlist)
    center_current_time $slot(apptlist)
}

proc center_current_time {apptlist} {
    upvar #0 $apptlist slot
    set c $slot(window).c
    set now [expr int([ical_time now])]
    set time [expr [ical_time minute $now] + [ical_time hour $now]*60]
    # subtract 5 hours
    set time [expr $time - 5*60]
    if {$time < 0} {set time 0}
    $c yview moveto [expr int(($time*2)/30)]
}

proc timeline_update {apptlist} {
   global timeline_color
    upvar #0 $apptlist slot

    set c $slot(window).c
    set now [expr int([ical_time now])]
    set time [expr [ical_time minute $now] + [ical_time hour $now]*60]
    set ypos [expr int(($time*$slot(font_height))/30)]
    set width [expr $slot(width)]
    $c delete [$c find withtag timeline]
    $c delete [$c find withtag timeline_time]
    $c create line 0 $ypos [expr 3*$width] $ypos -fill $timeline_color -tags timeline
    $c create text 0 $ypos -anchor sw -text "[ical_time hour $now]:[ical_time minute $now]" -font 5x7 -fill $timeline_color -tags timeline_time

    global timeline_cmd
    set timeline_cmd [after 60000 timeline_update $apptlist]
}

append-hook dayview-close {view} {
    global timeline_cmd
    after cancel $timeline_cmd
}
