showwindow in a separate file
[mkgallery.git] / include / showwin.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 slideshow http://www.phatfusion.net/slideshow/
9 */
10
11 /*
12         Hidable "fullscreen" Window for Slideshow
13 */
14
15 var showWindow = new Class({
16
17         getOptions: function(){
18                 return {
19                         embed: [],
20                         zIndex: 2,
21                         container: document.body,
22                         onClick: $empty,
23                 }
24         },
25
26         initialize: function(name,options){
27                 this.setOptions(this.getOptions(), options);
28
29                 this.options.container = $(this.options.container);
30
31                 this.container = new Element('div').addClass(name).
32                 setProperties({
33                         id: name,
34                         name: name,
35                 }).setStyles({
36                         position: 'absolute',
37                         left: '0px',
38                         top: '0px',
39                         width: '100%',
40                         zIndex: this.options.zIndex,
41                         overflow: 'hidden',
42                         display: 'none'
43                 }).addEvent('click', function(){
44                         this.options.onClick()
45                 }.bind(this)).injectInside(this.options.container);
46
47                 this.embedded = [];
48                 this.options.embed.each(function(el){
49                         var sub = new Element('div');
50                         sub.addClass(el).setProperties({
51                                 id: el,
52                                 name: el,
53                         }).injectInside(this.container);
54                         this.embedded.push(sub);
55                 },this);
56
57                 this.position();
58
59                 window.addEvent('resize', this.position.bind(this));
60                 window.addEvent('scroll', this.position.bind(this));
61         },
62
63         position: function(){
64                 if(this.options.container == document.body){
65                         this.h = window.getHeight();
66                         this.s = window.getScrollTop();
67                 }else{
68                         var myCoords = this.options.container.getCoordinates();
69                         this.h = myCoords.height;
70                         this.s = myCoords.top;
71                 }
72                 this.container.setStyles({
73                         top: this.s+'px',
74                         height: this.h+'px'
75                 })
76         },
77
78         show: function(){
79                 this.container.setStyle('display', 'block');
80         },
81
82         hide: function(){
83                 this.container.setStyle('display', 'none');
84         }
85 })
86 showWindow.implement(new Options);
87