1. var Time24 = false;
  2.  
  3. /* dont change anything below this line unless you know what you are doing :-) */
  4.  
  5.  
  6.  
  7. var d = new Date();
  8.  
  9. var hours = d.getHours();
  10.  
  11. var minutes = d.getMinutes();
  12.  
  13. var seconds = d.getSeconds();
  14.  
  15. var time, reacthours, reactmin, reactphase;
  16.  
  17.  
  18.  
  19.  
  20.  
  21. function initiate() {
  22.  
  23. phasenum = phase();
  24.  
  25. $('#time, #shadow').html(Time());
  26.  
  27. $('#date, #date-shadow').html(cDate());
  28.  
  29.  
  30.  
  31. $('#swap-two').css({'background-image' : 'url(Images/' + phasenum + '.gif)', 'opacity' : 1}).doTimeout(2000, function() {
  32.  
  33. $('#swap-one').css({'background-image' : 'url(Images/' + phasenum + '.gif)'});
  34.  
  35. $(this).css({'opacity' : 0});
  36.  
  37. $('#time, #shadow, #date, #date-shadow').css({'opacity' : 1});
  38.  
  39. });
  40.  
  41.  
  42.  
  43. update(); // starts normal clock updating process
  44.  
  45. }
  46.  
  47.  
  48.  
  49. function update() {
  50.  
  51. d = new Date();
  52.  
  53. hours = d.getHours();
  54.  
  55. minutes = d.getMinutes();
  56.  
  57. seconds = d.getSeconds();
  58.  
  59.  
  60.  
  61. bg_change = react(); // check if background should be change (this is mainly to prevent unnecessary battery drain) important !
  62.  
  63.  
  64.  
  65. //console.log(bg_change + ' ' + hours); //debug
  66.  
  67.  
  68.  
  69. if (bg_change) {
  70.  
  71. phasenum = phase();
  72.  
  73.  
  74.  
  75. $('#time, #shadow, #date, #date-shadow').css({'opacity' : 0}).doTimeout(1000, function() {
  76.  
  77. $('#swap-two').css({'background-image' : 'url(Images/' + phasenum + '.gif)', 'opacity' : 1}).doTimeout(2000, function() {
  78.  
  79. $('#swap-one').css({'background-image' : 'url(Images/' + phasenum + '.gif)'});
  80.  
  81. $(this).css({'opacity' : 0});
  82.  
  83. $('#time, #shadow, #date, #date-shadow').css({'opacity' : 1});
  84.  
  85. });
  86.  
  87. });
  88.  
  89. } else {
  90.  
  91. $('#time, #shadow').html(Time());
  92.  
  93. $('#date, #date-shadow').html(cDate());
  94.  
  95. }
  96.  
  97.  
  98.  
  99. setTimeout(update, 1000);
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107. function phase () {
  108.  
  109. phasen = hours;
  110.  
  111.  
  112.  
  113. return phasen;
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121. function react () {
  122.  
  123. if (reacthours != undefined) {
  124.  
  125. if (reactphase != phase()) {
  126.  
  127. reacthours = hours; // new value (changes every hour) :-)
  128.  
  129. reactmin = minutes; //new value (used for debug purposes mostly)
  130.  
  131. reactphase = phase(); // new value
  132.  
  133.  
  134.  
  135. return true; // background should be changed
  136.  
  137. } else {
  138.  
  139. return false;
  140.  
  141. }
  142.  
  143. } else {
  144.  
  145. //defines variable in the begining
  146.  
  147. reacthours = hours;
  148.  
  149. reactmin = minutes;
  150.  
  151. reactphase = phase();
  152.  
  153.  
  154.  
  155. return false;
  156.  
  157. }
  158.  
  159. }
  160.  
  161.  
  162.  
  163.  
  164.  
  165. function Time () {
  166.  
  167. if (Time24) {
  168.  
  169. if (hours < 10) hours = '0' + hours;
  170.  
  171. if (minutes < 10) minutes = '0' + minutes;
  172.  
  173. if (seconds < 10) seconds = '0' + seconds;
  174.  
  175.  
  176.  
  177. return hours + ":" + minutes + ('<span>' + seconds + '</span>');
  178.  
  179. } else {
  180.  
  181. if (hours < 13) am = "am";
  182.  
  183. else am = "pm";
  184.  
  185. if (hours > 12) hours -= 12;
  186.  
  187.  
  188.  
  189. if (hours < 1) hours = '12';
  190.  
  191. if (hours < 10) hours = '0' + hours;
  192.  
  193. if (minutes < 10) minutes = "0" + minutes;
  194.  
  195.  
  196.  
  197. return hours + ":" + minutes + ('<span>' + am + '</span>');
  198.  
  199. }
  200.  
  201. }
  202.  
  203.  
  204.  
  205.  
  206.  
  207. function cDate () {
  208.  
  209. var month = d.getMonth() + 1;
  210.  
  211. if (month < 10) month = '0' + month;
  212.  
  213.  
  214.  
  215. if (d.getDate() < 10) {
  216.  
  217. var daynum = "0" + d.getDate();
  218.  
  219. } else {
  220.  
  221. var daynum = d.getDate();
  222.  
  223. }
  224.  
  225.  
  226.  
  227. return Day() + ' ' + daynum + '.' + month;
  228.  
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235. function Day () {
  236.  
  237. day = new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
  238.  
  239. return day[d.getDay()];
  240.  
  241. }