fix slideshow, web_path was not set correctly
[phpfspot.git] / phpfspot.js
1 /***************************************************************************
2  *
3  * phpfspot, presents your F-Spot photo collection in Web browsers.
4  *
5  * Copyright (c) by Andreas Unterkircher
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  ***************************************************************************/
22
23 /**
24  * show photo
25  *
26  * this function will be called by client and fetches
27  * the single-photo view via AJAX from the server.
28  * Furthermore it will scrollup the browser to the top
29  * position so the image become visibile immediatley.
30  */
31 function showPhoto(id, scrollup)
32 {
33    /* is phpfspot skeleton really displayed? */
34    if(!document.getElementById('content'))
35       return;
36
37    var content = document.getElementById('content');
38
39    /* blank the screen */
40    if(scrollup != undefined) {
41       content.innerHTML = "";
42    }
43
44    /* fetch single-photo view from server */
45    HTML_AJAX.replace(content, encodeURI(web_path + '/rpc.php?action=showphoto&id=' + id));
46
47    /* scroll the window up to the top */
48    if(scrollup != undefined) {
49       window.scrollTo(0,0);
50    }
51
52    /* delete some global vars */
53    delete(origHeight); origHeight = undefined;
54    delete(origWidth); origWidth = undefined;
55    delete(photo_details_pos); photo_details_pos = undefined;
56
57 } // showPhoto()
58
59 /**
60  * scroll browser to the last shown photo
61  *
62  * this function will be called when user returns from single-photo
63  * to the photo index. It will scroll down the window (if possible)
64  * to the position of the last shown photo.
65  */
66 function moveToThumb(thumb_id)
67 {
68    if(thumb_id == undefined)
69       return;
70
71    if(thumbimg = document.getElementById('thumbimg' + thumb_id)) {
72       window.scrollTo(0, findPos(thumbimg,'top')-100);
73    }
74
75 } // moveToThumb()
76
77 /**
78  * return position of object
79  *
80  * this function returns the position of an object.
81  * depending on the parameter 'direction' it will either
82  * return the X or Y position.
83  */
84 function findPos(obj, direction) {
85    var cur = 0;
86    if (obj.offsetParent) {
87       do {
88          if(direction == 'left')
89             cur += obj.offsetLeft;
90          if(direction == 'top')
91             cur += obj.offsetTop;
92       } while (obj = obj.offsetParent);
93    }
94    return [cur];
95
96 } // findPos()
97
98 /**
99  * opens the credits page
100  */
101 function showCredits()
102 {
103    var credits = document.getElementById("content");
104    credits.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=showcredits'));
105
106 } // showCredits()
107
108 /**
109  * tag-selection handling
110  *
111  * this function is getting called by client to either
112  * - add
113  ∗ - delete
114  * - modify tag-match condition
115  *
116  * It will then fetch the result from the server via AJAX
117  * and updates the tag-selection.
118  */
119 function Tags(mode, id)
120 {
121    var objTemp = new Object();
122
123    if(mode == "add") {
124       // add tag to users session
125       objTemp['action'] = 'addtag';
126       objTemp['id'] = id;
127    }
128    else if(mode == "del") {
129       // del tag from users session
130       objTemp['action'] = 'deltag';
131       objTemp['id'] = id;
132    }
133    else if(mode == "condition") {
134       setCheckedValue(id, id.value);
135       objTemp['action'] = 'tagcondition';
136       objTemp['mode'] = id.value;
137    }
138
139    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
140    if(retr == "ok") {
141       refreshAvailableTags();
142       refreshSelectedTags();
143       refreshPhotoIndex();
144    }
145    else {
146       window.alert("Server message: "+ retr);
147    }
148
149 } // Tags()
150
151 /**
152  * update available-tags tag-cloud
153  *
154  * this function queries an actual version of the tag-cloud
155  * for the available (not-selected) tags from the server via
156  * AJAX.
157  */
158 function refreshAvailableTags()
159 {
160    // update available tags
161    var avail_tags = document.getElementById('available_tags');
162    if(avail_tags != undefined) {
163       avail_tags.innerHTML = "Loading...";
164       avail_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_available_tags'));
165    }
166
167 } // refreshAvailableTags()
168
169 /**
170  * update selected-tags list
171  *
172  * this function queries an actual version of the tag-list
173  * for the selected tags from the server via AJAX.
174  */
175 function refreshSelectedTags()
176 {
177    // update selected tags
178    var selected_tags = document.getElementById("selected_tags");
179    if(selected_tags != undefined) {
180       selected_tags.innerHTML = "Loading...";
181       selected_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_selected_tags'));
182    }
183
184 } // refreshSelectedTags()
185
186 /**
187  * show photo index
188  *
189  * this function will fetch the photo-index view from
190  * the server via AJAX. It's also used to browse through
191  * the photo-index pages
192  */
193 function showPhotoIndex(begin_with, last_photo)
194 {
195    var url = web_path + "/rpc.php?action=show_photo_index";
196    if(begin_with != undefined)
197       url = url + '&begin_with=' + begin_with;
198    if(last_photo != undefined)
199       url = url + '&last_photo=' + last_photo;
200
201    HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
202
203 } // showPhotoIndex()
204
205 /**
206  * update photo index
207  *
208  * this function will be called, to request a refresh of the
209  * photo index. this, for example, can be caused, when changing
210  * the tag-selection.
211  */
212 function refreshPhotoIndex()
213 {
214    /* only invoke showPhotoIndex(), if photo-index is really shown */
215    if(document.getElementById("index") != undefined || startup == 1) {
216       showPhotoIndex();
217       startup = 0;
218    }
219
220 } // refreshPhotoIndex()
221
222 /**
223  * blur cursor focus
224  *
225  * this function removes the focus-rectangle which may appear
226  * when click on a link. Not always beautiful.
227  */
228 function click(object)
229 {
230    if(object.blur)
231       object.blur();
232
233 } // click()
234
235 /**
236  * change current radio-button setting
237  *
238  * This function will check the radio-button with the given value.
239  * If no radio-button is currently displayed, this function will do
240  * nothing.
241  * If the given value does not exist, the existing radio buttons will
242  * be reseted.
243  */
244 function setCheckedValue(condition, value) {
245
246    var count = condition.length;
247    if(count == undefined) {
248       condition.checked = (condition.value == value.toString());
249       return;
250    }
251    for(var i = 0; i < count; i++) {
252       condition[i].checked = false;
253       if(condition[i].value == value.toString()) {
254          condition[i].checked = true;
255       }
256    }
257
258 } // setCheckedValue()
259
260 /**
261  * Invoke a search
262  *
263  * This function will be invoked by starting
264  * any kind of search (tag-name, photo-name, date, ...).
265  */
266 function startSearch()
267 {
268    from_year = document.getElementById('fromyear').value;
269    from_month = document.getElementById('frommonth').value;
270    from_day = document.getElementById('fromday').value;
271    from = from_year +"-"+ from_month +"-"+ from_day;
272    to_year = document.getElementById('toyear').value;
273    to_month = document.getElementById('tomonth').value;
274    to_day = document.getElementById('today').value;
275    to = to_year +"-"+ to_month +"-"+ to_day;
276
277    var objTemp = new Object();
278    objTemp['action'] = 'search';
279
280    if(document.getElementsByName('searchfor_tag')[0] != undefined &&
281       document.getElementsByName('searchfor_tag')[0].value != "") {
282       objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
283    }
284    if(document.getElementsByName('searchfor_name')[0] != undefined &&
285       document.getElementsByName('searchfor_name')[0].value != "") {
286       objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
287    }
288    if(document.getElementsByName('consider_date')[0] != undefined &&
289       document.getElementsByName('consider_date')[0].checked == true) {
290       objTemp['from'] = from;
291       objTemp['to'] = to;
292    }
293    if(document.getElementsByName('consider_rate')[0] != undefined &&
294       document.getElementsByName('consider_rate')[0].checked == true) {
295       objTemp['rate_from'] = rate_search['from'];
296       objTemp['rate_to'] = rate_search['to'];
297    }
298
299    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
300    if(retr == "ok") {
301       refreshAvailableTags();
302       refreshSelectedTags();
303       showPhotoIndex();
304    }
305    else {
306       window.alert("Server message: "+ retr);
307    }
308
309 } // startSearch()
310
311 /**
312  * enable/disable date search
313  *
314  * this function will either enable or disable the
315  * input fields for the date-search
316  */
317 function datesearch()
318 {
319    var mode = true;
320
321    if(document.getElementsByName('consider_date')[0].checked == true) {
322       mode = false;
323    }
324       
325    document.getElementById('fromyear').disabled = mode;
326    document.getElementById('frommonth').disabled = mode;
327    document.getElementById('fromday').disabled = mode;
328    document.getElementById('toyear').disabled = mode;
329    document.getElementById('tomonth').disabled = mode;
330    document.getElementById('today').disabled = mode;
331  
332 } // datesearch()
333
334 /**
335  * set view mode
336  *
337  * called for photo-index export. will return the
338  * selected mode via AJAX from the server.
339  */
340 function setViewMode(mode)
341 {
342    var exprt = document.getElementById('output');
343    exprt.innerHTML = "Loading...";
344    exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
345
346 } // setViewMode()
347
348 /**
349  * reset all search-fields
350  */
351 function clearSearch()
352 {
353    if(document.getElementsByName('searchfor_tag')[0] != undefined)
354       document.getElementsByName('searchfor_tag')[0].value = '';
355    if(document.getElementsByName('searchfor_name')[0] != undefined)
356       document.getElementsByName('searchfor_name')[0].value = '';
357
358    if(document.getElementsByName('consider_date')[0] != undefined &&
359       document.getElementsByName('consider_date')[0].checked == true) {
360       document.getElementsByName('consider_date')[0].checked = false;
361       datesearch();
362    }
363    if(document.getElementsByName('consider_rate')[0] != undefined &&
364       document.getElementsByName('consider_rate')[0].checked == true) {
365       document.getElementsByName('consider_rate')[0].checked = false;
366    }
367
368 } // clearSearch()
369
370 /**
371  * if the client is planless, ask the server what to do
372  * next.
373  */
374 function AskServerWhatToDo()
375 {
376    return HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=what_to_do'));
377
378 } // AskServerWhatToDo()
379
380 /**
381  * init phpfspot
382  *
383  * this function will be called when the browser opens phpfspot
384  * the first time. It will fetch the tag-lists and will then
385  * switch to the right view, which the browser got told from
386  * the server (maybe someone hit the refresh button...).
387  *
388  * as parameter the server can set the correct webpath.
389  * espacialley when using user-friendly url's, the browser
390  * does not know the correct URLs to address images, stylesheets,
391  * ... then.
392  */
393 function init_phpfspot(srv_webpath)
394 {
395    if(srv_webpath != undefined)
396       web_path = srv_webpath;
397    else
398       web_path = '';
399
400    /* always load list of available tags */
401    //this should not be more necessary since 4.5.08
402    //refreshAvailableTags();
403
404    /* ask the server what we are currently displaying */
405    whattodo = AskServerWhatToDo();
406
407    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
408       showPhotoIndex();
409    }
410    if(whattodo == 'showpi_tags') {
411       refreshSelectedTags();
412       showPhotoIndex();
413    }
414    if(whattodo == 'show_photo') {
415       if(photo = getPhotoToShow()) {
416          showPhoto(photo);
417          refreshSelectedTags();
418       }
419    }
420
421 } // init_phpfspot()
422
423 /**
424  * change background-color on mouse-over
425  */
426 function setBackGrdColor(item, color)
427 {
428    if(color == 'mouseover')
429       item.style.backgroundColor='#c6e9ff';
430    if(color == 'mouseout')
431       item.style.backgroundColor='#eeeeee';
432    if(color == 'mouseclick')
433       item.style.backgroundColor='#93A8CA';
434
435 } // setBackGrdColor()
436
437 /**
438  * ask server, which photo needs to be shown
439  *
440  * when user press the refresh-button in a single-photo
441  * view or maybe enters the link via an external URL, the
442  * client does not know, what photo will be shown (dimensions...).
443  * But the server can tell this the browser.
444  */
445 function getPhotoToShow()
446 {
447    var photo_to_show = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_photo_to_show'));
448
449    // if no image needs to be shown, return false from here
450    if(photo_to_show == "")
451       return false;
452    
453    return photo_to_show;
454
455 } // getPhotoToShow()
456
457 /**
458  * a fake-zoom for photo
459  *
460  * a quick to let the browser do some zooming on
461  * photos.
462  */
463 function zoom(mod)
464 {
465    var photo;
466
467    if(mod == undefined)
468       return;
469
470    /* internet explorer */
471    if(document.images['photo'].width)
472       photo = document.images['photo'];
473
474    /* all others */
475    if(photo == undefined && document.getElementById('photo').width)
476       photo = document.getElementById('photo');
477
478    if(photo != undefined) {
479
480       if(origWidth == undefined)
481          origWidth = photo.width;
482       if(origHeight == undefined)
483          origHeight = photo.height;
484
485       if(mod != 0) {
486          new_w = photo.width * (1 + mod/100);
487          new_h = photo.height * (1 + mod/100);
488          photo.width = new_w;
489          photo.height = new_h;
490
491          if(photo_details_pos == undefined) {
492             photo_details_pos = findPos(document.getElementById('photo_details'),'left');
493          }
494
495          if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
496             hidePhotoDetails('true');
497          }
498          else {
499             hidePhotoDetails('false');
500          }
501       }
502       else {
503          photo.width = origWidth;
504          photo.height = origHeight;
505          hidePhotoDetails('false');
506       }
507    }
508
509 } // zoom()
510
511 /**
512  * hides the photo details layin
513  *
514  * if the photo is getting zoomed quiet large, this will
515  * auto-hide (and also restore) the photo-details-box.
516  */
517 function hidePhotoDetails(mode)
518 {
519    var photo_details;
520
521    if(photo_details = document.getElementById('photo_details')) {
522       if(mode == 'true') {
523          photo_details.style.visibility = 'hidden';
524          photo_details.style.display = 'none';
525       }
526       else {
527          photo_details.style.visibility = 'visible';
528          photo_details.style.display = '';
529       }
530    }
531 } // hidePhotoDetails()
532
533 /**
534  * show calendar
535  */
536 function showCalendar(date_box, click_obj)
537 {
538    var calendar = document.getElementById('calendar');
539    var year = document.getElementById(date_box+'year').value;
540    var month = document.getElementById(date_box+'month').value;
541    if(date_box == 'from') {
542       var xpos = document.getElementById('frompic').offsetLeft;
543       var ypos = document.getElementById('frompic').offsetTop;
544       calendar_mode = 'from';
545    }
546    if(date_box == 'to') {
547       var xpos = document.getElementById('topic').offsetLeft;
548       var ypos = document.getElementById('topic').offsetTop;
549       calendar_mode = 'to';
550    }
551    calendar.style.left = xpos + 100 + 'px';
552    calendar.style.top = ypos + 80 + 'px';
553
554    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
555       calendar.style.visibility = 'visible';
556       calendar.innerHTML = "Loading...";
557       calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
558       calendar_shown = 1;
559    }
560    else {
561       hideCalendar();
562    }
563
564 } // showCalendar()
565
566 /**
567  * hide calendar
568  */
569 function hideCalendar()
570 {
571    var calendar = document.getElementById('calendar');
572    if(calendar.style.visibility != 'hidden') {
573       calendar.style.visibility = 'hidden';
574       calendar_shown = 0;
575    }
576 } // hideCalendar()
577
578 /**
579  * switch month in calendar
580  */
581 function setMonth(year, month, day)
582 {
583    var calendar = document.getElementById('calendar');
584    calendar.innerHTML = "Loading...";
585    calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
586 }
587
588 /**
589  * get the user-selected date from the calendar and
590  * put it into the date-search boxes
591  */
592 function setCalendarDate(year, month, day)
593 {
594    document.getElementById(calendar_mode+'year').value = year;
595    document.getElementById(calendar_mode+'month').value = month;
596    document.getElementById(calendar_mode+'day').value = day;
597    hideCalendar();
598
599 } // setCalendarDate()
600
601 /**
602  * reset phpfspot complelely and move to the begining
603  */
604 function resetAll()
605 {
606    HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset'));
607    clearSearch();
608    refreshAvailableTags();
609    refreshSelectedTags();
610    refreshPhotoIndex();
611
612 } // resetAll()
613
614 /**
615  * find objects with their class-name
616  */
617 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
618    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
619    var arrReturnElements = new Array();
620    var arrRegExpClassNames = new Array();
621    if(typeof oClassNames == "object"){
622       for(var i=0; i<oClassNames.length; i++){
623          arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
624       }
625    }
626    else{
627       arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
628    }
629    var oElement;
630    var bMatchesAll;
631    for(var j=0; j<arrElements.length; j++){
632       oElement = arrElements[j];
633       bMatchesAll = true;
634       for(var k=0; k<arrRegExpClassNames.length; k++){
635          if(!arrRegExpClassNames[k].test(oElement.className)){
636             bMatchesAll = false;
637             break;
638          }
639       }
640       if(bMatchesAll){
641          arrReturnElements.push(oElement);
642       }
643    }
644    return (arrReturnElements)
645
646 } // WSR_getElementsByClassName()
647
648 /**
649  * javascript based photo preloading
650  */
651 function preloadPhotos(image_url) {
652
653    var i;
654    var timeout = 1000;
655    var waiting = 100;
656    var counting;
657
658    lbImg=WSR_getElementsByClassName(document,"img","thumb");
659    for(i=0;i<lbImg.length;i++){
660       lbImg[i].src=image_url[i];
661       // to not bomb the server with requests, give the page some time
662       // to load the images one by one. if a image exceeds the timeout,
663       // the next image will be loaded.
664       if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
665          counting = 0;
666          while(lbImg[i].complete != true && counting < timeout) {
667             window.setTimeout("noop()", waiting);
668             counting+=waiting;
669          }
670       }
671    }
672
673 } // preloadPhotos()
674
675 /* a function that does nothing */
676 function noop() {}
677
678 /**
679  * start slideshow
680  */
681 function startSlideShow(srv_webpath)
682 {
683    if(srv_webpath != undefined)
684       web_path = srv_webpath;
685    else
686       web_path = '';
687
688    if(!sliding) {
689       HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
690       nextSlide();
691       sliding = setInterval("nextSlide()", sliding_time*1000);
692       document.getElementById('stop_ico').src = web_path + "/resources/32_stop.png";
693    }
694    else {
695       clearInterval(sliding);
696       sliding = 0;
697       document.getElementById('stop_ico').src = web_path + "/resources/32_play.png";
698    }
699
700 } // startSlideShow()
701
702 /**
703  * switch to next slide
704  */
705 function nextSlide()
706 {
707    var next_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_next_slideshow_img'));
708    document.getElementById('slide_img').src = next_img;
709
710 } // nextSlide()
711
712 /**
713  * switch to previous slide
714  */
715 function prevSlide()
716 {
717    var prev_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_prev_slideshow_img'));
718    document.getElementById('slide_img').src = prev_img;
719
720 } // prevSlide()
721
722 /**
723  * interrupt slide show
724  */
725 function pauseSlideShow()
726 {
727    if(!sliding_paused) {
728       sliding_paused = 1;
729       clearInterval(sliding);
730       document.getElementById('pause_ico').src = web_path + "/resources/32_play.png";
731    }
732    else {
733       sliding_paused = 0;
734       sliding = setInterval("nextSlide()", sliding_time*1000);
735       document.getElementById('pause_ico').src = web_path + "/resources/32_pause.png";
736    }
737
738 } // pauseSlideShow()
739
740 /**
741  * start auto-browse
742  */
743 function startAutoBrowse()
744 {
745    if(!autobrowse) {
746       autoBrowse();
747       autobrowse = setInterval("autoBrowse()", 5000);
748    }
749    else {
750       clearInterval(autobrowse);
751       autobrowse = 0;
752       document.getElementById('autobrowse_ico').src = web_path + "/resources/32_play.png";
753    }
754
755 } // startAutoBrowser()
756
757 /**
758  * auto-browsing
759  */
760 function autoBrowse()
761 {
762    if(document.getElementById('next_link')) {
763       var next_link = document.getElementById('next_link').href;
764       window.location.href = next_link;
765       document.getElementById('autobrowse_ico').src = web_path + "/resources/32_pause.png";
766    }
767    /* we have reached the last photo */
768    else {
769       if(ab_ico = document.getElementById('autobrowse_ico'))
770          ab_ico.src = web_path + "/resources/32_play.png";
771       clearInterval(autobrowse);
772    }
773
774 } // autoBrowse()
775
776 /**
777  * initiate slider to modify slide-switching-speed
778  */
779 function initSlider()
780 {
781    var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
782    var inputEl = document.forms[0]["slider-input-1"];
783    var s = new Slider(sliderEl, inputEl);
784    s.setMinimum(1);
785    s.setMaximum(10);
786    s.setValue(sliding_time);
787    document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
788    s.onchange = function () {
789       sliding_time = s.getValue();
790       document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
791       if(!sliding_paused && sliding) {
792          clearInterval(sliding);
793          sliding = setInterval("nextSlide()", sliding_time*1000);
794       }
795    };
796    window.onresize = function () {
797       s.recalculate();
798    };
799
800 } // initSlider()
801
802 /**
803  * if the sort-order (photo-name, date, ...) has been
804  * changed, update the photo-index view.
805  */
806 function update_sort_order(obj)
807 {  
808    var objTemp = new Object();
809    objTemp['value'] = obj.options[obj.selectedIndex].value;
810
811    var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_sort_order', objTemp);
812
813    if(retr == "ok") {
814       showPhotoIndex();
815    }
816    else {
817       window.alert("Server message: "+ retr);
818    }
819
820 } // update_sort_order()
821
822 /**
823  * show rate stars
824  *
825  * this function will show the requested amount of
826  * rate-stars.
827  *
828  * @param string mode
829  * @param int level
830  */
831 function show_rate(mode, level)
832 {
833    var i;
834
835    for(i = 1; i <= 5; i++) {
836       if(i <= level) {
837          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
838       }
839       else {
840          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
841       }
842    }
843
844 } // show_rate()
845
846 /**
847  * set rate stars
848  *
849  *
850  * this function will set the requested rate-stars-amount into a global
851  * variable (which will then later be used on form-submit) and will also
852  * update the display.
853  *
854  * @param string mode
855  * @param int level
856  */
857 function set_rate(mode, level)
858 {
859    rate_search[mode] = level;
860    show_rate(mode, level);
861
862 } // set_rate()
863
864 /**
865  * reset rate stars
866  *
867  * this function will reset the rate-star to their initial value.
868  *
869  * @param string mode
870  */
871 function reset_rate(mode)
872 {
873    if(rate_search[mode] == undefined)
874       rate_search[mode] = 0;
875
876    show_rate(mode, rate_search[mode]);
877
878 } // reset_rate()
879
880 /**
881  * handle key events
882  */
883 function keyDown(e) {
884    var evt = (e) ? e:(window.event) ? window.event:null;
885
886    if(evt) {
887       var key = (evt.charCode) ? evt.charCode :
888          ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
889
890
891       if(key == 37) /* left curosr */ {
892          if(document.getElementById('prev_link')) {
893             var prev_link = document.getElementById('prev_link').href;
894             window.location.href = prev_link;
895          }
896          return;
897       }
898       if(key == 38) /* up cursor */ {
899       }
900       if(key == 39) /* right curosr */ {
901          if(document.getElementById('next_link')) {
902             var next_link = document.getElementById('next_link').href;
903             window.location.href = next_link;
904          }
905          return;
906       }
907       if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
908          showPhotoIndex();
909          return;
910       }
911       if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
912          resetAll();
913          return;
914       }
915    }
916 }
917
918 document.onkeydown=keyDown;
919 if(document.layers) {
920    document.captureEvents(Event.KEYDOWN);
921 }
922
923 // will be reseted by first viewing photo-index
924 var startup = 1;
925 // calendar specific
926 var calendar_shown = 0;
927 var calendar_mode = '';
928 // auto-browsing & sliding
929 var autobrowse = 0;
930 var sliding = 0;
931 var sliding_paused = 0;
932 var sliding_time = 3;
933 // zooming
934 var origHeight;
935 var origWidth;
936 // position of the last shown photo in photo-index
937 var photo_details_pos;
938 var web_path;
939 var rate_search = new Array();