IE compatibility
[mkgallery.git] / include / gallery.js
1 /*
2         $Id$
3
4         This is a part of mkgallery.pl suite
5         http://www.average.org/mkgallery/
6
7         Uses mootools (1.2) http://www.mootools.net/
8         Uses multibox http://www.phatfusion.net/multibox/
9         Inspired by slideshow http://www.phatfusion.net/slideshow/
10 */
11
12 /*
13         Use slideshow classes with the index generated by mkgallery.pl
14 */
15
16 /* Initialize everything, to be called on domready */
17 function init_gallery() {
18
19         /* List of lists of img variations. Each image variation is
20          * a three-element array: [width, height, url]. Index of the
21          * outer array is the global ID.
22          *
23          * [
24          *  [ id, title, [
25          *                [ width, height, url ]
26          *                ...
27          *               ]
28          *   ...
29          *  ]
30          *  ...
31          * ]
32         */
33         var vimgs=[];
34
35         /* resolve string ID to index No which is the index in vimgs[] array */
36         var rimgs=[];
37
38         /* Populate images list */
39
40         $$('div.varimages').each(function(el,i){
41                 var rel=el.get('id');
42                 rimgs[rel] = i;
43                 vimgs[i] = [rel, el.title, []];
44                 el.getElements('a').each(function(ael,j){
45                         dim = /(\d+)[^\d](\d+)/.exec(ael.rel);
46                         w = dim[1];
47                         h = dim[2];
48                         vimgs[i][2][j]=[w,h,ael.href];
49                 });
50         });
51
52                         /* debugging output
53         var msg='loaded '+vimgs.length+' image descriptions:';
54         vimgs.each(function(vimg,i){
55                 msg+='\nid='+i+' ('+vimg[0]+') title='+vimg[1];
56                 vimg[2].each(function(vv,i){
57                         msg+='\n     w='+vv[0]+' h='+vv[1]+' url='+vv[2];
58                 });
59         });
60         alert(msg);
61                         /* end debugging output */
62
63         /* Initialize objects */
64
65         var ovlparams = {};
66         ovl = new overlay(ovlparams);
67
68         var iboxparams = {
69                 overlay: ovl,
70                 showNumbers: false,
71                 showControls: true,
72                 openFromLink: false,
73                 movieWidth: 640,
74                 movieHeight: 480,
75                 descClassName: 'infoBoxDesc'
76         };
77         ibox = new multiBox('infoBox', iboxparams);
78
79         var winparms = {
80                 tohide: 'indexContainer'
81         };
82         var showwin = new showWindow('slideshowContainer',winparms);
83
84         var ctlparams = {
85         };
86         var ctl = new Controls('slideshowControls','slideshowContainer',
87                                 ctlparams);
88
89         var showparms = {
90                 cbStart: function(){ showwin.show(); },
91                 cbExit: function(){ showwin.hide(); }
92         };
93         var show = new Show(vimgs,showwin,ctl,showparms);
94
95         document.addEvent('keypress', function(ev){
96                 if (ev.key == 'esc') {
97                         show.exit();
98                 } else if (ev.key == 'left') {
99                         show.prev();
100                 } else if (ev.key == 'right') {
101                         show.next();
102                 } else if (ev.key == 'space') {
103                         show.toggleplay();
104                 } else {
105                         /* alert('keypress: '+ev.key); */
106                 }
107         });
108
109         /* Update HTML */
110
111         $$('.conceal').each(function(el){
112                 el.setStyle('display', 'none');
113         });
114         $$('a.infoBox').each(function(el){
115                 var url=el.get('href');
116                 el.set('href',url+'?conceal');
117         });
118
119         $$('a.showStart').each(function(el){
120                 el.addEvent('click',
121                         show.start.bind(show,[rimgs[el.get('rel')],1]));
122         });
123         $$('a.showImage').each(function(el){
124                 el.addEvent('click',
125                         show.start.bind(show,[rimgs[el.get('rel')],0]));
126         });
127
128         /* Determine if we need to go directly into show mode */
129
130         parsedurl = parseUrl(document.URL);
131         /* alert('Anchor: '+parsedurl['anchor']+'\nURL: '+document.URL); */
132         if ($chk(parsedurl['anchor'])){
133                 show.start(rimgs[parsedurl['anchor']],0);
134         }
135 }
136
137 /* Initialization */
138 window.addEvent('domready',init_gallery);
139