be62cfbe8d4910e931443e2a0419fbc9be8af859
[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].value != "") {
281       objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
282    }
283    if(document.getElementsByName('searchfor_name')[0].value != "") {
284       objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
285    }
286    if(document.getElementsByName('consider_date')[0].checked == true) {
287       objTemp['from'] = from;
288       objTemp['to'] = to;
289    }
290    if(document.getElementsByName('consider_rate')[0].checked == true) {
291       objTemp['rate_from'] = rate_search['from'];
292       objTemp['rate_to'] = rate_search['to'];
293    }
294
295    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
296    if(retr == "ok") {
297       refreshAvailableTags();
298       refreshSelectedTags();
299       showPhotoIndex();
300    }
301    else {
302       window.alert("Server message: "+ retr);
303    }
304
305 } // startSearch()
306
307 /**
308  * enable/disable date search
309  *
310  * this function will either enable or disable the
311  * input fields for the date-search
312  */
313 function datesearch()
314 {
315    var mode = true;
316
317    if(document.getElementsByName('consider_date')[0].checked == true) {
318       mode = false;
319    }
320       
321    document.getElementById('fromyear').disabled = mode;
322    document.getElementById('frommonth').disabled = mode;
323    document.getElementById('fromday').disabled = mode;
324    document.getElementById('toyear').disabled = mode;
325    document.getElementById('tomonth').disabled = mode;
326    document.getElementById('today').disabled = mode;
327  
328 } // datesearch()
329
330 /**
331  * set view mode
332  *
333  * called for photo-index export. will return the
334  * selected mode via AJAX from the server.
335  */
336 function setViewMode(mode)
337 {
338    var exprt = document.getElementById('output');
339    exprt.innerHTML = "Loading...";
340    exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
341
342 } // setViewMode()
343
344 /**
345  * reset all search-fields
346  */
347 function clearSearch()
348 {
349    document.getElementsByName('searchfor_tag')[0].value = '';
350    document.getElementsByName('searchfor_name')[0].value = '';
351
352    if(document.getElementsByName('consider_date')[0].checked == true) {
353       document.getElementsByName('consider_date')[0].checked = false;
354       datesearch();
355    }
356    if(document.getElementsByName('consider_rate')[0].checked == true) {
357       document.getElementsByName('consider_rate')[0].checked = false;
358       datesearch();
359    }
360
361 } // clearSearch()
362
363 /**
364  * if the client is planless, ask the server what to do
365  * next.
366  */
367 function AskServerWhatToDo()
368 {
369    return HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=what_to_do'));
370
371 } // AskServerWhatToDo()
372
373 /**
374  * init phpfspot
375  *
376  * this function will be called when the browser opens phpfspot
377  * the first time. It will fetch the tag-lists and will then
378  * switch to the right view, which the browser got told from
379  * the server (maybe someone hit the refresh button...).
380  *
381  * as parameter the server can set the correct webpath.
382  * espacialley when using user-friendly url's, the browser
383  * does not know the correct URLs to address images, stylesheets,
384  * ... then.
385  */
386 function init_phpfspot(srv_webpath)
387 {
388    if(srv_webpath != undefined)
389       web_path = srv_webpath;
390    else
391       web_path = '';
392
393    /* always load list of available tags */
394    //this should not be more necessary since 4.5.08
395    //refreshAvailableTags();
396
397    /* ask the server what we are currently displaying */
398    whattodo = AskServerWhatToDo();
399
400    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
401       showPhotoIndex();
402    }
403    if(whattodo == 'showpi_tags') {
404       refreshSelectedTags();
405       showPhotoIndex();
406    }
407    if(whattodo == 'show_photo') {
408       if(photo = getPhotoToShow()) {
409          showPhoto(photo);
410          refreshSelectedTags();
411       }
412    }
413
414 } // init_phpfspot()
415
416 /**
417  * change background-color on mouse-over
418  */
419 function setBackGrdColor(item, color)
420 {
421    if(color == 'mouseover')
422       item.style.backgroundColor='#c6e9ff';
423    if(color == 'mouseout')
424       item.style.backgroundColor='#eeeeee';
425    if(color == 'mouseclick')
426       item.style.backgroundColor='#93A8CA';
427
428 } // setBackGrdColor()
429
430 /**
431  * ask server, which photo needs to be shown
432  *
433  * when user press the refresh-button in a single-photo
434  * view or maybe enters the link via an external URL, the
435  * client does not know, what photo will be shown (dimensions...).
436  * But the server can tell this the browser.
437  */
438 function getPhotoToShow()
439 {
440    var photo_to_show = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_photo_to_show'));
441
442    // if no image needs to be shown, return false from here
443    if(photo_to_show == "")
444       return false;
445    
446    return photo_to_show;
447
448 } // getPhotoToShow()
449
450 /**
451  * a fake-zoom for photo
452  *
453  * a quick to let the browser do some zooming on
454  * photos.
455  */
456 function zoom(mod)
457 {
458    var photo;
459
460    if(mod == undefined)
461       return;
462
463    /* internet explorer */
464    if(document.images['photo'].width)
465       photo = document.images['photo'];
466
467    /* all others */
468    if(photo == undefined && document.getElementById('photo').width)
469       photo = document.getElementById('photo');
470
471    if(photo != undefined) {
472
473       if(origWidth == undefined)
474          origWidth = photo.width;
475       if(origHeight == undefined)
476          origHeight = photo.height;
477
478       if(mod != 0) {
479          new_w = photo.width * (1 + mod/100);
480          new_h = photo.height * (1 + mod/100);
481          photo.width = new_w;
482          photo.height = new_h;
483
484          if(photo_details_pos == undefined) {
485             photo_details_pos = findPos(document.getElementById('photo_details'),'left');
486          }
487
488          if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
489             hidePhotoDetails('true');
490          }
491          else {
492             hidePhotoDetails('false');
493          }
494       }
495       else {
496          photo.width = origWidth;
497          photo.height = origHeight;
498          hidePhotoDetails('false');
499       }
500    }
501
502 } // zoom()
503
504 /**
505  * hides the photo details layin
506  *
507  * if the photo is getting zoomed quiet large, this will
508  * auto-hide (and also restore) the photo-details-box.
509  */
510 function hidePhotoDetails(mode)
511 {
512    var photo_details;
513
514    if(photo_details = document.getElementById('photo_details')) {
515       if(mode == 'true') {
516          photo_details.style.visibility = 'hidden';
517          photo_details.style.display = 'none';
518       }
519       else {
520          photo_details.style.visibility = 'visible';
521          photo_details.style.display = '';
522       }
523    }
524 } // hidePhotoDetails()
525
526 /**
527  * show calendar
528  */
529 function showCalendar(date_box, click_obj)
530 {
531    var calendar = document.getElementById('calendar');
532    var year = document.getElementById(date_box+'year').value;
533    var month = document.getElementById(date_box+'month').value;
534    if(date_box == 'from') {
535       var xpos = document.getElementById('frompic').offsetLeft;
536       var ypos = document.getElementById('frompic').offsetTop;
537       calendar_mode = 'from';
538    }
539    if(date_box == 'to') {
540       var xpos = document.getElementById('topic').offsetLeft;
541       var ypos = document.getElementById('topic').offsetTop;
542       calendar_mode = 'to';
543    }
544    calendar.style.left = xpos + 100 + 'px';
545    calendar.style.top = ypos + 80 + 'px';
546
547    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
548       calendar.style.visibility = 'visible';
549       calendar.innerHTML = "Loading...";
550       calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
551       calendar_shown = 1;
552    }
553    else {
554       hideCalendar();
555    }
556
557 } // showCalendar()
558
559 /**
560  * hide calendar
561  */
562 function hideCalendar()
563 {
564    var calendar = document.getElementById('calendar');
565    if(calendar.style.visibility != 'hidden') {
566       calendar.style.visibility = 'hidden';
567       calendar_shown = 0;
568    }
569 } // hideCalendar()
570
571 /**
572  * switch month in calendar
573  */
574 function setMonth(year, month, day)
575 {
576    var calendar = document.getElementById('calendar');
577    calendar.innerHTML = "Loading...";
578    calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
579 }
580
581 /**
582  * get the user-selected date from the calendar and
583  * put it into the date-search boxes
584  */
585 function setCalendarDate(year, month, day)
586 {
587    document.getElementById(calendar_mode+'year').value = year;
588    document.getElementById(calendar_mode+'month').value = month;
589    document.getElementById(calendar_mode+'day').value = day;
590    hideCalendar();
591
592 } // setCalendarDate()
593
594 /**
595  * reset phpfspot complelely and move to the begining
596  */
597 function resetAll()
598 {
599    HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset'));
600    clearSearch();
601    refreshAvailableTags();
602    refreshSelectedTags();
603    refreshPhotoIndex();
604
605 } // resetAll()
606
607 /**
608  * find objects with their class-name
609  */
610 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
611    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
612    var arrReturnElements = new Array();
613    var arrRegExpClassNames = new Array();
614    if(typeof oClassNames == "object"){
615       for(var i=0; i<oClassNames.length; i++){
616          arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
617       }
618    }
619    else{
620       arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
621    }
622    var oElement;
623    var bMatchesAll;
624    for(var j=0; j<arrElements.length; j++){
625       oElement = arrElements[j];
626       bMatchesAll = true;
627       for(var k=0; k<arrRegExpClassNames.length; k++){
628          if(!arrRegExpClassNames[k].test(oElement.className)){
629             bMatchesAll = false;
630             break;
631          }
632       }
633       if(bMatchesAll){
634          arrReturnElements.push(oElement);
635       }
636    }
637    return (arrReturnElements)
638
639 } // WSR_getElementsByClassName()
640
641 /**
642  * javascript based photo preloading
643  */
644 function preloadPhotos(image_url) {
645
646    var i;
647    var timeout = 1000;
648    var waiting = 100;
649    var counting;
650
651    lbImg=WSR_getElementsByClassName(document,"img","thumb");
652    for(i=0;i<lbImg.length;i++){
653       lbImg[i].src=image_url[i];
654       // to not bomb the server with requests, give the page some time
655       // to load the images one by one. if a image exceeds the timeout,
656       // the next image will be loaded.
657       if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
658          counting = 0;
659          while(lbImg[i].complete != true && counting < timeout) {
660             window.setTimeout("noop()", waiting);
661             counting+=waiting;
662          }
663       }
664    }
665
666 } // preloadPhotos()
667
668 /* a function that does nothing */
669 function noop() {}
670
671 /**
672  * start slideshow
673  */
674 function startSlideShow()
675 {
676    if(!sliding) {
677       HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
678       nextSlide();
679       sliding = setInterval("nextSlide()", sliding_time*1000);
680       document.getElementById('stop_ico').src = web_path + "/resources/32_stop.png";
681    }
682    else {
683       clearInterval(sliding);
684       sliding = 0;
685       document.getElementById('stop_ico').src = web_path + "/resources/32_play.png";
686    }
687
688 } // startSlideShow()
689
690 /**
691  * switch to next slide
692  */
693 function nextSlide()
694 {
695    var next_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_next_slideshow_img'));
696    document.getElementById('slide_img').src = next_img;
697
698 } // nextSlide()
699
700 /**
701  * switch to previous slide
702  */
703 function prevSlide()
704 {
705    var prev_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_prev_slideshow_img'));
706    document.getElementById('slide_img').src = prev_img;
707
708 } // prevSlide()
709
710 /**
711  * interrupt slide show
712  */
713 function pauseSlideShow()
714 {
715    if(!sliding_paused) {
716       sliding_paused = 1;
717       clearInterval(sliding);
718       document.getElementById('pause_ico').src = web_path + "/resources/32_play.png";
719    }
720    else {
721       sliding_paused = 0;
722       sliding = setInterval("nextSlide()", sliding_time*1000);
723       document.getElementById('pause_ico').src = web_path + "/resources/32_pause.png";
724    }
725
726 } // pauseSlideShow()
727
728 /**
729  * start auto-browse
730  */
731 function startAutoBrowse()
732 {
733    if(!autobrowse) {
734       autoBrowse();
735       autobrowse = setInterval("autoBrowse()", 5000);
736    }
737    else {
738       clearInterval(autobrowse);
739       autobrowse = 0;
740       document.getElementById('autobrowse_ico').src = web_path + "/resources/32_play.png";
741    }
742
743 } // startAutoBrowser()
744
745 /**
746  * auto-browsing
747  */
748 function autoBrowse()
749 {
750    if(document.getElementById('next_link')) {
751       var next_link = document.getElementById('next_link').href;
752       window.location.href = next_link;
753       document.getElementById('autobrowse_ico').src = web_path + "/resources/32_pause.png";
754    }
755    /* we have reached the last photo */
756    else {
757       if(ab_ico = document.getElementById('autobrowse_ico'))
758          ab_ico.src = web_path + "/resources/32_play.png";
759       clearInterval(autobrowse);
760    }
761
762 } // autoBrowse()
763
764 /**
765  * initiate slider to modify slide-switching-speed
766  */
767 function initSlider()
768 {
769    var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
770    var inputEl = document.forms[0]["slider-input-1"];
771    var s = new Slider(sliderEl, inputEl);
772    s.setMinimum(1);
773    s.setMaximum(10);
774    s.setValue(sliding_time);
775    document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
776    s.onchange = function () {
777       sliding_time = s.getValue();
778       document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
779       if(!sliding_paused && sliding) {
780          clearInterval(sliding);
781          sliding = setInterval("nextSlide()", sliding_time*1000);
782       }
783    };
784    window.onresize = function () {
785       s.recalculate();
786    };
787
788 } // initSlider()
789
790 /**
791  * if the sort-order (photo-name, date, ...) has been
792  * changed, update the photo-index view.
793  */
794 function update_sort_order(obj)
795 {  
796    var objTemp = new Object();
797    objTemp['value'] = obj.options[obj.selectedIndex].value;
798
799    var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_sort_order', objTemp);
800
801    if(retr == "ok") {
802       showPhotoIndex();
803    }
804    else {
805       window.alert("Server message: "+ retr);
806    }
807
808 } // update_sort_order()
809
810 /**
811  * show rate stars
812  *
813  * this function will show the requested amount of
814  * rate-stars.
815  *
816  * @param string mode
817  * @param int level
818  */
819 function show_rate(mode, level)
820 {
821    var i;
822
823    for(i = 1; i <= 5; i++) {
824       if(i <= level) {
825          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
826       }
827       else {
828          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
829       }
830    }
831
832 } // show_rate()
833
834 /**
835  * set rate stars
836  *
837  *
838  * this function will set the requested rate-stars-amount into a global
839  * variable (which will then later be used on form-submit) and will also
840  * update the display.
841  *
842  * @param string mode
843  * @param int level
844  */
845 function set_rate(mode, level)
846 {
847    rate_search[mode] = level;
848    show_rate(mode, level);
849
850 } // set_rate()
851
852 /**
853  * reset rate stars
854  *
855  * this function will reset the rate-star to their initial value.
856  *
857  * @param string mode
858  */
859 function reset_rate(mode)
860 {
861    if(rate_search[mode] == undefined)
862       rate_search[mode] = 0;
863
864    show_rate(mode, rate_search[mode]);
865
866 } // reset_rate()
867
868 /**
869  * handle key events
870  */
871 function keyDown(e) {
872    var evt = (e) ? e:(window.event) ? window.event:null;
873
874    if(evt) {
875       var key = (evt.charCode) ? evt.charCode :
876          ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
877
878
879       if(key == 37) /* left curosr */ {
880          if(document.getElementById('prev_link')) {
881             var prev_link = document.getElementById('prev_link').href;
882             window.location.href = prev_link;
883          }
884          return;
885       }
886       if(key == 38) /* up cursor */ {
887       }
888       if(key == 39) /* right curosr */ {
889          if(document.getElementById('next_link')) {
890             var next_link = document.getElementById('next_link').href;
891             window.location.href = next_link;
892          }
893          return;
894       }
895       if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
896          showPhotoIndex();
897          return;
898       }
899       if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
900          resetAll();
901          return;
902       }
903    }
904 }
905
906 document.onkeydown=keyDown;
907 if(document.layers) {
908    document.captureEvents(Event.KEYDOWN);
909 }
910
911 // will be reseted by first viewing photo-index
912 var startup = 1;
913 // calendar specific
914 var calendar_shown = 0;
915 var calendar_mode = '';
916 // auto-browsing & sliding
917 var autobrowse = 0;
918 var sliding = 0;
919 var sliding_paused = 0;
920 var sliding_time = 3;
921 // zooming
922 var origHeight;
923 var origWidth;
924 // position of the last shown photo in photo-index
925 var photo_details_pos;
926 var web_path;
927 var rate_search = new Array();