make initialization in js file rather than embedded
[mkgallery.git] / include / gallery.js
1 /*
2         This is a part of mkgallery.pl suite
3         http://www.average.org/mkgallery/
4
5         Uses mootools (1.1) http://www.mootools.net/
6         Uses slideshow http://www.phatfusion.net/slideshow/
7 */
8
9 function showIbox(iboxid) {
10  var ibox = document.getElementById(iboxid);
11  var bwidth = 400;
12  var bheight = 300;
13
14  var wwidth = window.getWidth();
15  var wheight = window.getHeight();
16
17  ibox.style.top = window.getScrollTop() + ((wheight - bheight) / 2) + 'px';
18  ibox.style.left = ((wwidth - bwidth) / 2) + "px";
19  ibox.style.width = bwidth + "px";
20  ibox.style.height = bheight + "px";
21  // alert('wwidth='+wwidth+'; bwidth='+bwidth+'; wheight='+wheight+'; bheight='+bheight);
22  ibox.zIndex = '0';
23  ibox.style.display = 'block';
24  return false;
25 }
26 function HideIbox(iboxid) {
27  var ibox = document.getElementById(iboxid);
28  ibox.zIndex = '1000';
29  ibox.style.display = 'none';
30  return false;
31 }
32
33 /*
34         Slideshow
35 */
36
37 var ShowWindow = new Class({
38
39         getOptions: function(){
40                 return {
41                         zIndex: 2,
42                         container: document.body,
43                         onClick: Class.empty
44                 };
45         },
46
47         initialize: function(div,options){
48                 this.setOptions(this.getOptions(), options);
49
50                 this.options.container = $(this.options.container);
51
52                 this.div = $(div);
53                 this.div.setStyles({
54                         position: 'absolute',
55                         left: '0px',
56                         top: '0px',
57                         width: '100%',
58                         zIndex: this.options.zIndex,
59                         overflow: 'hidden',
60                         display: 'none'
61                 });
62                 this.div.addEvent('click', function(){
63                         this.options.onClick();
64                 }.bind(this));
65
66                 this.position();
67
68                 window.addEvent('resize', this.position.bind(this));
69                 window.addEvent('scroll', this.position.bind(this));
70         },
71
72         position: function(){
73                 if(this.options.container == document.body){
74                         var h = window.getHeight()+'px';
75                         var s = window.getScrollTop()+'px';
76                         this.div.setStyles({top: s, height: h});
77                 }else{
78                         var myCoords = this.options.container.getCoordinates();
79                         this.div.setStyles({
80                                 top: myCoords.top+'px',
81                                 height: myCoords.height+'px',
82                                 left: myCoords.left+'px',
83                                 width: myCoords.width+'px'
84                         });
85                 }
86         },
87
88         show: function(){
89                 this.div.setStyles({display: 'block'});
90         },
91
92         hide: function(){
93                 this.div.setStyles({display: 'none'});
94         }
95 });
96 ShowWindow.implement(new Options);
97
98 /* Make overlay window and start slideshow */
99 function run_slideshow(startid) {
100  showwin.show();
101  show.stop();
102  if (startid < 0) {
103   show.play(0);
104  } else {
105   show.play(startid);
106   show.stop();
107  }
108  return false;
109 }
110
111 /* Stop slideshow and return to index page */
112 function stop_slideshow() {
113  show.stop();
114  showwin.hide();
115  return false;
116 }
117
118 /* Initialize everything, to be called on domready */
119 function init_gallery() {
120  var winparms = {}
121  showwin = new ShowWindow('slideshowWindow',winparms)
122
123  var showparms = {
124   wait: 3000,
125   effect: 'fade',
126   duration: 1000,
127   loop: true, 
128   thumbnails: true,
129   onClick: function(i){alert(i)}
130  }
131  show = new SlideShow('slideshowContainer','slideshowThumbnail',showparms)
132
133  parsedurl = parseUrl(document.URL)
134  // alert('Anchor: '+parsedurl['anchor']+'\nURL: '+document.URL)
135  if ($chk(parsedurl['anchor'])){
136   run_slideshow(parsedurl['anchor'])
137  }
138 }
139
140 /* Initialization */
141 window.addEvent('domready',init_gallery)