--- ./station_schedule.module.orig	2007-11-18 01:44:24.000000000 +0100
+++ ./station_schedule.module	2008-02-09 13:35:08.000000000 +0100
@@ -104,17 +104,22 @@ function station_schedule_menu($may_cach
       'weight' => 10,
     );
   }
-  else {
-    // days of the week schedule...
+  else {  	
+  	// days of the week schedule...
     $today = station_today();
-    foreach (station_day_name() as $day => $dayname) {
+    $day_offset = variable_get('date_first_day', 0);
+
+    for ($i = 0; $i < 7; $i++) {
+  	  $day = ($i+$day_offset) % 7;
+  	  $dayname = station_day_name($day);
+
       $items[] = array(
         'path' => 'station/schedule/' . strtolower($dayname),
         'title' => t(substr($dayname, 0, 3)),
         'callback' => 'station_schedule_day_page',
         'callback arguments' => array($day),
         'type' => ($today == $day) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-        'weight' => $day,
+        'weight' => $i,
       );
     }
   }
@@ -136,6 +141,19 @@ function station_schedule_perm() {
 function station_schedule_admin_settings() {
   $form = array();
 
+  $station_schedule_schedule_start_hour_options = array();
+  for ($i = 0; $i < 24; $i++) {
+    $station_schedule_schedule_start_hour_options[$i] = $i;
+  }
+  
+  $form['station_schedule_schedule_start_hour'] = array(
+    '#type' => 'select',
+    '#title' => t('Schedule day start hour'),
+    '#default_value' => variable_get('station_schedule_schedule_start_hour', 0),
+    '#options' => $station_schedule_schedule_start_hour_options,
+    '#description' => t("This is the start hour of a day's schedule."),
+  );
+
   $form['station_schedule_increment'] = array(
     '#type' => 'select',
     '#title' => t('Time increment'),
@@ -593,7 +611,7 @@ function station_schedule_load_at($minut
 
 function station_schedule_load_day($day) {
   // there are 1440 minutes in a day (60minute * 24hours = 1day)
-  $start = $day * 1440;
+  $start = $day * 1440 + variable_get('station_schedule_schedule_start_hour', 0) * 60;
   $finish = $start + 1440;
 
   $ret = array();
@@ -615,15 +633,20 @@ function station_schedule_load_day($day)
 function station_schedule_admin_list() {
   drupal_add_css(drupal_get_path('module', 'station_schedule') .'/station_schedule.css');
 
-  $cols = station_day_name();
+  $day_offset = variable_get('date_first_day', 0);
+  
   $row = array();
   for ($i = 0; $i < 7; $i++) {
-    $cell = '';
+    $day = ($i+$day_offset) % 7;
+    $dayname = station_day_name($day);
+    $cols[] = $dayname;
+
+  	$cell = '';
     // find the minute that the day starts and finishes
-    $day_start = $i * 1440;
+    $day_start = $day * 1440;
     $day_finish = $day_start + 1440;
     $last_finish = $day_start;
-    foreach (station_schedule_load_day($i) as $s) {
+    foreach (station_schedule_load_day($day) as $s) {
       // display blocks for unscheduled time periods
       if ($last_finish != $s->start) {
         $cell .= theme('station_schedule_admin_nonitem', $last_finish, $s->start);
@@ -869,11 +892,13 @@ function station_schedule_week_page() {
   drupal_set_title(t('Weekly Schedule'));
 
   $today = station_today();
+  $day_offset = variable_get('date_first_day', 0);
 
   // build the headers
   $cols = array('data' => t('Time'));
-  foreach (station_day_name() as $name) {
-    $cols[] = array('data' => $name);
+  for ($i = 0; $i < 7; $i++) {
+  	$day = ($i+$day_offset) % 7;
+  	$cols[] = array('data' => station_day_name($day));
   }
   // ... add a class to indicate what day it is.
   $cols[$today]['class'] = 'station-sch-now-day';
@@ -881,17 +906,19 @@ function station_schedule_week_page() {
   $row = array();
   // put in a column of hours
   for ($i = 0; $i < 24; $i++) {
-    $cell .= theme('station_schedule_hour', $i);
+    $cell .= theme('station_schedule_hour', ($i + variable_get('station_schedule_schedule_start_hour', 0)) % 24);
   }
   $row[] = array('data' => $cell, 'id' => 'station-sch-hours');
   // now a column for each day
+  
   for ($i = 0; $i < 7; $i++) {
+  	$day = ($i+$day_offset) % 7;
     $cell = '';
     // find the minute that the day starts and finishes
-    $day_start = $i * 1440;
+    $day_start = $day * 1440 + variable_get('station_schedule_schedule_start_hour', 0) * 60;
     $day_finish = $day_start + 1440;
     $last_finish = $day_start;
-    foreach (station_schedule_load_day($i) as $s) {
+    foreach (station_schedule_load_day($day) as $s) {
       // display blocks for unscheduled time before this program
       if ($last_finish != $s->start) {
         $cell .= theme('station_schedule_spacer', $last_finish, $s->start);
