Copyright date updated
[brisk.git] / web / room.js
1 /*
2  *  brisk - room.js
3  *
4  *  Copyright (C) 2006-2012 Matteo Nastasi
5  *                          mailto: nastasi@alternativeoutput.it 
6  *                                  matteo.nastasi@milug.org
7  *                          web: http://www.alternativeoutput.it
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details. You should have received a
18  * copy of the GNU General Public License along with this program; if
19  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20  * Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23
24
25 /* 
26    data = [ [ flags, name ],  ... ]
27    
28 */
29
30 var l_list_all = 0x00;
31 var l_list_auth = 0x01;
32 var l_list_isol = 0x02;
33
34 function state_add(flags)
35 {
36     var content = "", supercont = "";
37     var st, superst, name = "", supername = "", supersfx = "";
38     var tit = "", supertit = "";
39
40
41     if ((flags & 0xf00) != 0) {
42         st = flags & 0xf00;
43         // MLANG 4,12,16,20,24,28
44         switch (st) {
45         case 0x100:
46             name = "st_pau.png";
47             tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
48             break;
49         case 0x200:
50             name = "st_out.png";
51             tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
52             break;
53         case 0x300:
54             name = "st_dog.png";
55             tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
56             break;
57         case 0x400:
58             name = "st_eat.png";
59             tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
60             break;
61         case 0x500:
62             name = "st_wrk.png";
63             tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
64             break;
65         case 0x600:
66             name = "st_smk.png";
67             tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
68             break;
69         case 0x700:
70             name = "st_eye.png";
71             tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
72             break;
73         case 0x800:
74             name = "st_rabbit.png";
75             tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
76             break;
77         case 0x900:
78             name = "st_soccer.png";
79             tit = (g_lang == 'en' ? "Soccer time" : "c'รจ la partita!!");
80             break;
81         case 0xa00:
82             name = "st_baby.png";
83             tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
84             break;
85         case 0xb00:
86             name = "st_mop.png";
87             tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
88             break;
89         default:
90             break;
91         }
92     }
93
94     if ((flags & 0xf0000) != 0) {
95         superst = flags & 0xf0000;
96         if (name != "") {
97             supersfx = "_side";                
98         }
99
100         switch (superst) {
101         case 0x20000:
102             supername = "superuser"+supersfx+".png";
103             supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
104             break;
105         }
106     }
107
108     if (supername != "") {
109         content += '&nbsp;<img title="'+supertit+'" class="inline" src="img/'+supername+'">';
110     }
111     
112     if (name != "") {
113         content += '&nbsp;<img title="'+tit+'" class="inline" src="img/'+name+'">';
114     }
115
116     return content;
117 }
118
119 var standup_data_old = null;
120
121 // TODO !!
122 // appendChild , removeChild
123
124 function table_add(curtag, td)
125 {
126     var tbody  = null, tr, ct;
127
128     do {
129         // console.log("wt: "+curtag.tagName);
130
131         if (curtag.tagName.toLowerCase() == "div" || 
132             curtag.tagName.toLowerCase() == "table") {
133             curtag = curtag.firstChild;
134         }
135         else if (curtag.tagName.toLowerCase() == "tbody") {
136             tbody = curtag;
137             break;
138         }
139         else
140             curtag = null;
141     } while (curtag != null);
142     
143     curtag = tbody.firstChild;
144     ct = 0;
145     do {
146         if (curtag.tagName.toLowerCase() == "tr") {
147             if (curtag.firstChild != null) {
148                 curtag = curtag.firstChild;
149                 ct++;
150             }
151             else {
152                 curtag.appendChild(td);
153                 return(true);
154             }
155         }
156         else if (curtag.tagName.toLowerCase() == "td") {
157             if (curtag.nextSibling != null) {
158                 curtag = curtag.nextSibling;
159                 ct++;
160             }
161             else {
162                 if (ct < 4) {
163                     curtag.parentNode.appendChild(td);
164                     return (true);
165                 }
166                 else {
167                     ct = 0;
168                     curtag = curtag.parentNode.nextSibling;
169                 }
170             }
171         }
172         else {
173             curtag = curtag.parentNode;
174         }
175
176     } while (curtag != null);
177
178     tr = document.createElement("tr");
179     tr.appendChild(td);
180     tbody.appendChild(tr);
181
182     return (true);
183 }
184
185 function spcs(c1, c2, n)
186 {
187     var ret = "";
188     var i;
189
190     for (i = 0 ; i < n ; i++) {
191         if ((i % 2) == 0)
192             ret += c1;
193         else
194             ret += c2;
195     }
196
197     return (ret);
198 }
199
200
201 function table_walk(curtag)
202 {
203     do {
204         // console.log("wt: "+curtag.tagName);
205         if (curtag.tagName.toLowerCase() == "div" || 
206             curtag.tagName.toLowerCase() == "table" ||
207             curtag.tagName.toLowerCase() == "tbody") {
208             curtag = curtag.firstChild;
209         }
210         else if (curtag.tagName.toLowerCase() == "tr") {
211             if (curtag.firstChild != null)
212                 curtag = curtag.firstChild;
213             else if (curtag.tagName != '')
214                 curtag = curtag.nextSibling;
215             else
216                 curtag = null;
217         }
218         else if (curtag.tagName.toLowerCase() == "td") {
219             if (curtag.nextSibling != null)
220                 curtag = curtag.nextSibling;
221             else {
222                 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
223                     curtag = curtag.parentNode.nextSibling;
224                 else
225                     curtag = null;
226             }
227         }
228         else
229             curtag = null;
230
231     } while (curtag != null && curtag.tagName.toLowerCase() != "td");
232
233     if (1 == 0) {
234         if (curtag == null)
235             alert("outtag == null"); 
236         else
237             alert("outtag: "+curtag.tagName);
238     }
239     return (curtag);
240 }
241
242 function j_stand_tdcont(el)
243 {
244     return (user_dec_and_state(el));
245 }
246
247 function j_stand_cont(ddata)
248 {
249     var i, ii;
250     var content;
251     var st = 0, name = "";
252     var curtag, nextag;
253
254     var data;
255
256     if (g_listen & l_list_isol) {
257         data = new Array();
258
259         for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
260             if ((ddata[ii][0] & 0x02) == 0) {
261                 continue;
262             }
263             data[i++] = ddata[ii];
264         }
265     }
266     else
267         data = ddata;
268
269     if (standup_data_old == null || data.length < 4) {
270     // if (standup_data_old == null) {
271         
272         content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
273         for (i = 0 ; i < data.length ; i++) {
274             if ((i % 4) == 0)
275                 content += '<tr>';
276             content += '<td id="'+i+'" class="room_standup">';
277             content += j_stand_tdcont(data[i]);
278             content += '</td>';
279             
280             if ((i % 4) == 3)
281                 content += '</tr>';
282         }
283         if ((i % 4) < 3)
284             content += '</tr>';
285         content += '</table>';
286         
287         $("standup").innerHTML = content;
288
289         // console.log("inizio");
290         // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ;  curtag = table_walk(curtag), i++ ) {
291         //     console.log("inloop["+i+"]: "+curtag.tagName+"  ID: "+curtag.id);
292         // }
293         // console.log("fine "+i);
294
295         // walktable($("standup"), nextag);
296         // console.log($("standup").firstChild);
297         // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
298
299         // log_walk($("standup"));
300
301         standup_data_old = data;
302     }
303     else {
304         var idx_del, arr_add, idx_mod, arr_mod;
305         var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
306         var i, e;
307         var i_del, i_mod, i_add;
308         var td;
309
310         idx_del = new Array();
311         arr_add = new Array();
312         map_add = new Array();
313         idx_mod = new Array();
314         arr_mod = new Array();
315         map_cur = new Array();
316         
317         // find removed entries
318         for (i = 0 ; i < standup_data_old.length ; i++) {
319             for (e = 0 ; e < data.length ; e++) {
320                 if (standup_data_old[i][1] == data[e][1]) {
321                     break;
322                 }
323             }
324             if (e == data.length) {
325                 idx_del[idx_del_n++] = i;
326                 map_cur[i] = -1;
327             }
328             else {
329                 /* modified entries */
330                 if (standup_data_old[i][0] != data[e][0]) {
331                     arr_mod[idx_mod_n] = data[e];
332                     idx_mod[idx_mod_n++] = i;
333                 }
334                 map_cur[i] = e;
335             }
336         }
337
338         // find new entries
339         for (e = 0 ; e < data.length ; e++) {
340             for (i = 0 ; i < standup_data_old.length ; i++) {
341                 if (data[e][1] == standup_data_old[i][1] ) {
342                     break;
343                 }
344             }
345             if (i == standup_data_old.length) {
346                 // console.log("ADD: "+data[e][1]);
347                 arr_add[idx_add_n]   = data[e];
348                 map_add[idx_add_n++] = e;
349             }
350         }
351         
352         // TODO: qui travaso add in del
353
354         i_del = 0;
355         // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
356         for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ;  curtag = table_walk(curtag), i++ ) {
357             // console.log("cur.id: "+curtag.id);
358
359             // alert("i: "+i+"  tagname: "+curtag.tagName+"  innerHTML: ["+curtag.innerHTML+"]");
360             // console.log("inloop["+i+"]: "+curtag.tagName+"  ID: "+curtag.id);
361             if (curtag.innerHTML == "") {
362                 // console.log("innerHTML == none");
363                 if (i_add < idx_add_n) {
364                     // console.log("  to be new");
365                     // console.log("  add:   CONT:"+j_stand_tdcont(arr_add[i_add]));
366                     curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
367                     curtag.id = map_add[i_add];
368                     i_add++
369                 }
370             }
371
372             // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
373             else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
374                 // console.log("to be cancel["+i+"]:  ID: "+curtag.id);
375                 if (i_add < idx_add_n) {
376                     // console.log("  to be new");
377                     // console.log("  add:   CONT:"+j_stand_tdcont(arr_add[i_add]));
378                     curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
379                     curtag.id = map_add[i_add];
380                     i_add++
381                 }
382                 else {
383                     // console.log("  to be del");
384                     curtag.innerHTML = "";
385                     curtag.id = -1;
386                 }
387                 i_del++;
388             }
389             // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
390             else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
391                 // console.log("  to be mod");
392                 // console.log("mod: "+idx_mod[i_mod]+ "  CONT:"+j_stand_tdcont(arr_mod[i_mod]));
393                 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
394                 curtag.id = map_cur[curtag.id];
395                 i_mod++;
396             }
397             else
398                 curtag.id = map_cur[curtag.id];
399         }
400         // console.log("fineloop");
401
402         for (i ; i_add < idx_add_n ; i_add++, i++) {
403             // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
404             td = document.createElement("td");
405             td.className = "room_standup";
406             td.id = map_add[i_add];
407             td.innerHTML = j_stand_tdcont(arr_add[i_add]);
408
409             table_add($("standup"), td);
410         }
411
412         standup_data_old = data;
413         return;
414     }
415     // $("esco").innerHTML =  '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
416 }
417
418 function esco_cb() {
419     window.onbeforeunload = null; 
420     window.onunload = null; 
421     // nonunload = true; 
422     act_logout();
423  };
424
425
426
427 function j_tab_cont(table_idx, data)
428 {
429     var i;
430     var content = '';
431
432     for (i = 0 ; i < data.length ; i++) {
433         // content += user_decorator(data[i]);
434         // content += state_add(data[i][0]);
435         content += j_stand_tdcont(data[i]);
436
437         content += '<br>';
438     }
439     $("table"+table_idx).innerHTML = content;
440 }
441
442 function j_tab_act_cont(idx, act)
443 {
444     if (act == 'sit') {
445         // MLANG 1
446         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
447     }
448     else if (act == 'sitreser') {
449         // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
450         // MLANG 1
451         $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
452     }
453     else if (act == 'wake') {
454         // MLANG 1
455         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup"  value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
456     }
457     else if (act == 'reserved') {
458         // MLANG 1
459         $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" style="margin-right: 20px;" src="img/onlyauth.png">';
460     }
461     else {
462         $("table_act"+idx).innerHTML = '';
463     }
464 }
465
466 function j_login_manager(form)
467 {
468     var token;
469
470     if (form.elements['passid'].value == '')
471         return (true);
472
473     else {
474         // console.log("richiesta token");
475         /* richiede token */
476         token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
477         tokens = token.split('|');
478         
479         // console.log('XX token: '+token);
480         // console.log(tokens);
481         if (token == null)
482             return (false);
483
484         token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
485         
486         form.elements['passid_private'].value = token;
487         form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
488
489         return (true);
490     }
491     
492     return (false);
493 }
494
495 function login_formtext_hilite()
496 {
497     formtext_hilite($("nameid"));
498     formtext_hilite($("passid"));
499     formsub_hilite($("sub"));
500 }
501
502 function login_init()
503 {
504     menu_init();
505     login_formtext_hilite();
506 }
507
508 function warrant_formtext_hilite(form)
509 {
510     /*
511     formtext_hilite($("nameid"));
512     formtext_hilite($("emailid"));
513     formsub_hilite($("subid"));
514     formsub_hilite($("cloid"));
515     */
516     formtext_hilite(form.elements['name']);
517     formtext_hilite(form.elements['email']);
518     formsub_hilite(form.elements['sub']);
519     formsub_hilite(form.elements['clo']);
520 }
521
522 function mesgtoadm_formtext_hilite(form)
523 {
524     /*
525     formtext_hilite($("subjid"));
526     formtext_hilite($("mesgid"));
527     formsub_hilite($("subid"));
528     formsub_hilite($("cloid"));
529     */
530     formtext_hilite(form.elements['subj']);
531     formtext_hilite(form.elements['mesg']);
532     formsub_hilite(form.elements['sub']);
533     formsub_hilite(form.elements['clo']);
534 }
535
536
537 function j_check_email(email)
538 {
539     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
540         return (true);
541     return (false);
542 }
543
544 function j_authbox(form)
545 {
546     var no; 
547
548     do {
549         if (form.elements['realsub'].value == "chiudi") {
550             $('authbox').style.visibility = "hidden";
551             break;
552         }
553
554         if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
555             // MLANG 2-4
556             no = new notify(gst, 
557                             (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
558                              "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
559                             1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
560             break;
561         }
562
563         // submit the request
564         token = server_request('mesg', 'warranty', 
565                                'cli_name', encodeURIComponent(form.elements['name'].value),
566                                'cli_email', encodeURIComponent(form.elements['email'].value) );
567         if (token == "1") {
568             $('authbox').style.visibility = "hidden";
569             form.elements['name'].value = "";
570             form.elements['email'].value = "";
571             break;
572         }
573     } while (0);
574
575     return (false);
576 }
577
578 function authbox(w, h)
579 {
580     var box;
581
582     box = $('authbox');
583
584     box.style.zIndex = 200;
585     box.style.width  = w+"px";
586     box.style.marginLeft  = -parseInt(w/2)+"px";
587     box.style.height = h+"px";
588     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
589
590     warrant_formtext_hilite($('auth_form'));
591
592     box.style.visibility = "visible";
593     $("nameid").focus();
594 }
595
596 function j_mesgtoadmbox(form)
597 {
598     var no; 
599
600     do {
601         if (form.elements['realsub'].value == "chiudi") {
602             $('mesgtoadmbox').style.visibility = "hidden";
603             break;
604         }
605
606         if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
607             // MLANG 1-3
608             no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
609                                   "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1, 
610                                   (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
611             break;
612         }
613                 
614         // submit the request
615         token = server_request('mesg', 'mesgtoadm', 
616                                'cli_subj', encodeURIComponent(form.elements['subj'].value),
617                                'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
618         if (token == "1") {
619             $('mesgtoadmbox').style.visibility = "hidden";
620             form.elements['subj'].value = "";
621             form.elements['mesg'].value = "";
622             break;
623         }
624     } while (0);
625
626     return (false);
627 }
628
629 function mesgtoadmbox(w, h)
630 {
631     var box;
632
633     box = $('mesgtoadmbox');
634
635     box.style.zIndex = 200;
636     box.style.width  = w+"px";
637     box.style.marginLeft  = -parseInt(w/2)+"px";
638     box.style.height = h+"px";
639     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
640
641     mesgtoadm_formtext_hilite($('mesgtoadm_form'));
642
643     box.style.visibility = "visible";
644     $('mesgtoadm_form').elements['subj'].focus();
645 }
646
647 function j_pollbox(form)
648 {
649     var no, i, choose; 
650
651     do {
652         // submit the request
653         
654         for (i = 0 ; i < form.elements.length ; i++) {
655             if (form.elements[i].checked == true)
656                 break;
657         }
658         if (i == form.elements.length) {
659             // MLANG 1-3
660             no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
661                                   "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1, 
662                             (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
663             return false;
664         }
665         else
666             choose = form.elements[i].value;
667
668         token = server_request('mesg', 'poll', 
669                                'cli_choose', encodeURIComponent(choose) );
670
671         if (token == "1") {
672             // TODO: mesg to user
673             // $('mesgtoadmbox').style.visibility = "hidden";
674             break;
675         }
676     } while (0);
677
678     return (false);
679 }
680
681
682
683
684 function list_set(what, is_update, info)
685 {
686     // console.log(what);
687     var i;
688     var relo = false;
689     var old_st = readCookie("CO_list");
690     
691     if (what == 'auth') {
692         $('list_auth').style.color = 'red';
693         $('list_isol').style.color = 'black';
694         $('list_all').style.color = 'black';
695         if (old_st == 'isolation')
696             relo = true;
697         g_listen = l_list_auth;
698     }
699     else if (what == 'isolation') {
700         $('list_auth').style.color = 'black';
701         $('list_isol').style.color = 'red';
702         $('list_all').style.color = 'black';
703         if (old_st != 'isolation')
704             relo = true;
705         g_listen = l_list_isol;
706     }
707     else {
708         $('list_auth').style.color = 'black';
709         $('list_isol').style.color = 'black';
710         $('list_all').style.color = 'red';
711         if (old_st == 'isolation')
712             relo = true;
713         g_listen = l_list_all;
714     }
715
716     set_checked_value($('ra_listen_auth'), what);
717     set_checked_value($('ra_listen_isol'), what);
718     set_checked_value($('ra_listen_all'),  what);
719
720     $('list_info').innerHTML = info;
721     if (is_update) {
722         createCookie("CO_list", what, 24*365, cookiepath);
723     }
724
725
726     if (relo || !is_update) {
727         for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
728             
729             if (i % 4 == 0) {
730                 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
731             }
732             
733             $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
734         }
735         if (what == 'isolation') {
736             tra.hide_noauth();
737         }
738         else {
739             tra.show_noauth();
740         }
741             
742         if (false) {
743             // ricalculation of standup area
744             if (standup_data_old != null) {
745                 standup_data = standup_data_old;
746                 standup_data_old = null;
747                 j_stand_cont(standup_data);
748             }
749         }
750     }
751 }
752
753 function sideslide(domobj, height, step)
754 {
755     this.st = 'wait';
756     this.twait = 5000;
757
758     this.domobj = domobj;
759     this.height = height;
760     this.step = step;
761
762     this.start();
763 }
764
765 sideslide.prototype = {
766     id: null,
767     st: 'wait',
768     twait: 0,
769     scroll: 0,
770     countdown: 0,
771
772     domobj: null,
773     height: 0,
774     step: 0,
775
776     start: function() {
777         var instant = this;
778         
779         this.st = 'wait';
780         this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
781     },
782
783     sideslide_cb: function() {
784         var instant = this;
785
786         if (this.st == 'wait') {
787             this.st = 'scroll';
788             this.countdown = 10;
789             this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
790         }
791         else if (this.st == 'scroll') {
792             this.scroll += (this.step / 10);
793             if (this.scroll >= this.height - this.step) {
794                 this.scroll = 0;
795             }
796             this.domobj.scrollTop = this.scroll;
797             this.countdown--;
798             if (this.countdown == 0) {
799                 this.stop();
800                 this.st = 'wait';
801                 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
802             }
803         }
804     },
805
806
807     stop: function() {
808         if (this.id != null) {
809             clearInterval(this.id);
810             this.id = null;
811         }
812     }
813
814 }