var done = {};

function d(s){
    var st = [];
    for (var i = 0; i < arguments.length; i++) {
        st.push(arguments[i]);
    }
    s = st.join(',');

    var d = $('doneDebug');
    if (!d) {
        d = new Element('div');
        d.setProperty('id', 'doneDebug');
        d.style.background = '#fff';
        document.body.appendChild(d);
    }
    var t = new Element('div');
    t.innerHTML = s;
    d.appendChild(t);
}

done.events = new Events();

done.gallery = new Class({

    initialize: function(container){
        this.dom = $(container);
        var i = 0;
        var popup = new done.gallery.popup();

        if (this.dom) {
            var as = this.dom.getElements('a');
            var imgs = this.dom.getElements('img')
            if (as.length == imgs.length) {
               this.length = as.length;
               var scroll = new done.gallery.scroll(this.dom, {
                   width: this.dom.getSize().x
               });
               imgs.each(function(img){

                  scroll.add(i, img.src, as[i].get('href'));
                  popup.add(i, img.src, as[i].get('href'), as[i].get('title'), img.get('alt'));
                  as[i].destroy();
                  i++;
               }, this);
            }
        }

         //wyjatek :/
        $$('#content img.left').each(function(el){
            el.style.cursor = 'pointer';
            var src = el.get('src');
            popup.add(i, src, src.replace(/\/gmin\//, '/gmax/'), el.get('alt'), '');
            el.addEvent('click',function(e){
               done.events.fireEvent('gallery.scroll.click', [i, el]);
            })
        });


        return true;
    }
});

done.gallery.fx = new Class({
    Extends: Fx,

    set: function(now){
        this.fireEvent('onStep', now);
    }
});


done.gallery.popup = new Class({
    Implements: [Events, Options],
    initialize: function(){
        done.events.addEvent('gallery.scroll.click', this.open.bind(this));
        done.events.addEvent('gallery.popup.show', this.show.bind(this));
        this.imgs = {};
    },
    create: function(){
        if (this.isCreate) {
            this.dom.style.display = 'block';
            return false;
        }

        var s = window.getSize();
        var o = window.getScroll();
        this.width = s.x;
        this.height = s.y;
        this.dom = new Element('div', {
            'id': 'g-popup'
        });
        this.wrap = new Element('div', {
            'class': 'wrap'
        });
        var _self = this;
        this.tween = new Fx.Tween(this.wrap, {
            duration: 300,
            transition: Fx.Transitions.Quad.easeOut,
            onComplete: function(){
                if (_self.isShow) {
                    _self.close();
                }
                else {
                    _self.isShow = true;
                }
            }
        });
        this.dom.addEvent('mousewheel', function(e){
            new Event(e).stop();
            _self.wheel(e.wheel > 0 ? 1 : -1);
        });
        this.dom.addEvent('click', function(e){
            _self.close();
        });

        window.addEvent('resize', this.resize.bind(this));
        this.resize(true);
        this.dom.appendChild(this.wrap);
        document.body.appendChild(this.dom);
        this.isCreate = true;
    },
    wheel: function(wheel){

        if (this.imgs[this.active + wheel] && this.imgs[this.active + wheel].isLoad){
            this.show(this.active + wheel);

        }
    },
    resize: function(init){
        var s = window.getSize();
        var o = window.getScroll();
        this.width = s.x;
        this.height = s.y;
        this.dom.setStyles({
            'width': s.x,
            'height': s.y,
            'top': o.y
        })
        var t = init === true ? -s.y : 0;
        this.wrap.setStyles({
            'width': s.x,
            'height': s.y,
            'top': t
        });
        if (this.next) {
            this.next.setPos(this.width - 110, 10);
        }
        if (this.imgs[this.active]) {
            this.imgs[this.active].setPos(this.width / 2, 10);
        }
    },
    add: function(sid, thumb, src, title, txt){
        this.imgs[sid] = new done.gallery.popup.img(sid, thumb, src, title, txt);
    },
    open: function(sid, img){
        this.create();
        this.resize(true);
        if (this.imgs[sid]) {

            var img = this.imgs[sid];
            img.onLoad(function(){
                this.show(sid);
                done.events.fireEvent('gallery.scroll.clickload');
            }, this);
        }
    },
    close: function(){
        Mask.hide();
        Tool.showFlash();
        this.isShow = false;
        this.dom.style.display = 'none';

        if(this.next) this.next.remove();
        if(this.prev) this.prev.remove();
        if(this.imgs[this.active]) this.imgs[this.active].remove();
        done.events.fireEvent('gallery.scroll.close');
    },
    show: function(sid){

        if (this.isAnimations()) {
            return false;
        }
        var img = this.imgs[sid];
        if (!img) {
            return false;
        }
        if (this.isShow) {
            if (this.active == sid) {
                this.tween.start('top', 0, -this.height);
            }
            else {
                var act = this.imgs[this.active];
                if (sid > this.active) {
                    //w prawo
                    if (this.prev) {
                        this.prev.remove();
                    }
                    act.toMin(90);
                    this.prev = act;
                    this.setNext(this.getNext(sid), true);
                }
                else {
                    if (this.next) {
                        this.next.remove();
                    }
                    act.toMin(this.width - 110);
                    this.next = act;
                    this.setPrev(this.getPrev(sid), true);
                }
                img.toMax(this.width / 2 + 5);
                this.active = sid;
            }
        }
        else {
            Mask.show();
            Tool.hideFlash();
            this.setPrev(this.getPrev(sid));
            this.setNext(this.getNext(sid));


            this.active = sid;
            this.wrap.appendChild(img.dom);
            img.setMaxSize();
            img.show();
            img.toBottom();
            img.setPos(this.width / 2 + 5, 10);


            this.tween.start('top', -this.height, 0);
        }
    },
    isAnimations: function(){
        for (var i in this.imgs) {
            if (this.imgs[i].isAnim) {
                return true;
            }
        }
        return false;
    },
    setNext: function(n, anim){
        this.next = null;
        if (n) {
            n.reset(this.width - 110);
            this.wrap.appendChild(n.dom);
            n.show(anim);
            this.next = n;
        }
    },
    setPrev: function(p, anim){
        this.prev = null;
        if (p) {
            p.reset(90);
            this.wrap.appendChild(p.dom);
            p.show(anim);
            this.prev = p;
        }
    },
    getNext: function(sid){
        if (this.imgs[sid + 1]) {
            return this.imgs[sid + 1];
        }
        return null;
    },
    getPrev: function(sid){
        if (this.imgs[sid - 1]) {
            return this.imgs[sid - 1];
        }
        return null;
    }
});

done.gallery.popup.img = new Class({
    Implements: [Events, Options],
    initialize: function(sid, thumbSrc, src, title, descr){


        this.dom = new Element('div', {
            'class': 'item'
        });

        this.isLoad = false;
        this.thumb = thumb;
        this.src = src;

        var _self = this;
        this.dom.addEvent('click', function(e){
            new Event(e).stop();
            if(_self.isLoad){;
               done.events.fireEvent('gallery.popup.show', [sid]);
            }
        });
        var thumb = new Image();
        thumb.onload = function(){
            _self.loadThumbEv(this);
        }
        thumb.src = thumbSrc;

        this.tween = new Fx.Morph(this.dom, {
            duration: 500
        });
        var _self = this;
        this.move = new Fx.Tween(this.dom, {
            duration: 500,
            onComplete: function(){
                _self.isAnim = false;
                if (_self.isMax) {
                    _self.descr.show();
                }
            }
        });

        this.mask = new Element('div', {
            'class': 'mask',
            'opacity': 0.6
        });
        this.dom.appendChild(this.mask);

        this.descr = new done.gallery.popup.descr(this, title, descr);

    },
    loadThumbEv:function(img){
         this.thumb = img;
         this.twidth = img.width;
         this.theight = img.height;
         this.dom.appendChild(img);
         this.setMinSize();
         this.setPos(this.x,this.y);
         this.isLoadThumb = true;
    },
    reset: function(left){
        this.setMinSize();
        this.onLoad();
        this.setPos(left, 10);
        this.dom.setOpacity(0);
        this.toTop();
        this.descr.hide();
    },
    toMax: function(x){
        if (!this.isAnim) {
            this.isAnim = true;
            this.isMax = true;
            this.toBottom();
            x -= parseInt(this.iwidth / 2);
            this.move.start('left', this.x, x);
            this.x = x;
            this.width = this.iwidth;

            this.tween.start({
                'width': [this.twidth, this.iwidth],
                'height': [this.theight, this.iheight]
            });
        }
    },
    toMin: function(x){
        if (!this.isAnim) {
            this.isAnim = true;
            this.isMax = false;
            this.descr.hide();
            this.toTop();
            x -= parseInt(this.twidth / 2);
            this.move.start('left', this.x, x);
            this.x = x;
            this.width = this.twidth;
            this.tween.start({
                'width': [this.iwidth, this.twidth],
                'height': [this.iheight, this.theight]
            });
        }
    },
    setSize: function(w, h){
        this.width = w;
        this.height = h;
        this.dom.setStyles({
            'width': w,
            'height': h
        });
        return this;
    },
    setMaxSize: function(){
        this.descr.show();
        this.setSize(this.iwidth, this.iheight);
    },
    setMinSize: function(){
        this.setSize(this.twidth, this.theight);
    },
    setPos: function(x, y){
        this.x = x - parseInt(this.width / 2);
        this.y = y;
        this.dom.setStyles({
            'left': this.x,
            'top': this.y
        });
        return this;
    },
    onLoad: function(fn, bind){
        bind = bind || this;
        if (!this.isLoad) {
            var img = new Image();
            var _self = this;
            img.onerror = function(){
                _self.onLoadEv(this, fn, bind);
            };
            img.onload = function(){
                _self.onLoadEv(this, fn, bind);
            };
            img.src = this.src;
        }
        else {
            if (fn)
                fn.apply(bind);
        }
    },
    onLoadEv: function(img, fn, bind){
        this.isLoad = true;
        this.iwidth = img.width;
        this.iheight = img.height;
        this.img = img;
        if (fn) {
            fn.apply(bind, []);
        }
         if(this.thumb)
            this.dom.replaceChild(img, this.thumb);
         else
            this.dom.appendChild(img);

        this.mask.fade(0);
    },
    hide: function(){
        this.dom.setOpacity(0);
    },
    show: function(anim){
        if (anim) {
            var _self = this;
            setTimeout(function(){
                _self.dom.fade(1);
            }, 300);
        }
        else {
            this.dom.fade(1);
        }

    },
    remove: function(){
        this.dom.fade(0);
        var _self = this;
        setTimeout(function(){
            _self.dom.parentNode.removeChild(_self.dom);
        }, 300);
        this.dom.setOpacity(1);
    },
    toBottom: function(){
        this.dom.style.zIndex = 1;
    },
    toTop: function(){
        this.dom.style.zIndex = 10;
    }
});

done.gallery.popup.descr = new Class({
    initialize: function(parent, title, descr){
        this.parent = parent;
        this.dom = new Element('div', {
            'class': 'descr'
        });

        this.cont = new Element('div');
        this.cont.style.display = 'none';

        this.txt = new Element('p');

        if (this.setText(title, descr)) {
            this.isActive = true;
            parent.dom.appendChild(this.dom);
            parent.dom.addEvent('mouseenter', this.over.bind(this));
            parent.dom.addEvent('mouseleave', this.out.bind(this));

            this.cont.setOpacity(0.8);
            this.dom.appendChild(this.cont);


            this.cont.appendChild(this.txt);


            var _s = this;

            this.tween = new Fx.Tween(this.cont, {
                duration: 200,
                //transition: Fx.Transitions.Quad.easeOut,
                onComplete: function(a){

                },
                onCancel: function(a){

                }
            });
        }
    },
    over: function(){
        if (this.isActive) {
            this.tween.cancel();
            this.cont.style.display = 'block';
            this.height = this.cont.offsetHeight;
            this.checkScroll();
            this.cont.style.bottom = '-' + this.height + 'px';
            this.tween.start('bottom', -this.height, 0);
        }
    },
    out: function(){
        if (this.isActive) {
            this.tween.cancel();
            this.tween.start('bottom', 0, -this.height);
        }
    },
    checkScroll: function(){
        if (!this.isCheck) {
            this.isCheck = true;
            if (this.height > this.dom.offsetHeight / 3) {
                this.height
            }
        }
    },
    setText: function(title, txt){
        title = title ? '<em>' + title + '</em>' : '';
        txt = txt ? txt : '';
        var descr = title + txt;
        if (descr.length > 0) {
            this.txt.innerHTML = descr;
            return true;
        }
        return false;
    },
    show: function(){
        this.dom.style.display = 'block';
        this.isActive = true;
    },
    hide: function(){
        this.dom.style.display = 'none';
        this.isActive = false;
    }
});

done.gallery.scroll = new Class({

    Implements: [Events, Options],

    options: {
        /*
         onStart: $empty,
         onCancel: $empty,
         onComplete: $empty,
         */
        width: 10000,
        height: 100,
        padding: 20,
        isScroll: true
    },

    initialize: function(parent, options){
        this.setOptions(options);
        this.pos = 0;
        this.length = 0;
        this.sWidth = 0;
        this.width = 0;
        this.imgs = {};

        this.dom = new Element('div', {
            'class': 'scroll'
        });
        this.container = new Element('div', {
            'class': 'container'
        });
        this.mask = new Element('div', {
            'class': 'mask'
        });
        this.wrapper = new Element('div', {
            'class': 'wrapper'
        });
        done.events.addEvent('gallery.scroll.close', this.onClose.bind(this));
        done.events.addEvent('gallery.scroll.clickload', this.onClickLoad.bind(this));

        this.dom.appendChild(this.wrapper);
        this.dom.appendChild(this.mask);
        this.wrapper.appendChild(this.container);
        parent.appendChild(this.dom);
    },
    add: function(sid, src, href){

        this.length++;
        var _self = this;
        var img = new Image();
         this.imgs[sid] = {
            'img': img,
            'dom': null
        };
        img.onload = function(){
            _self.onload(this, sid, href);
        };
        img.onerror = function(){
            _self.onerror();
        };
        img.src = src;
    },
    onload: function(img, sid, href){
        var dom = new Element('a')
        dom.set('href', href);
        dom.setStyles({
            'height': this.options.height,
            'width': img.width,
            'margin-right': 5
        });
        this.sWidth += img.width + 5;
        dom.appendChild(img);
        //this.scroll.appendChild(dom);
        this.imgs[sid]['dom'] = dom;
        //this.container.appendChild(dom);
        dom.addEvent('click', this.onClick.bindWithEvent(this, [sid, img]));
        this.length--;
        this.checkSize();
        //done.events.fireEvent('gallery.scroll.loading', [sid, img]);
    },
    onerror: function(){
        this.length--;
    },
    render: function(){

        return true;
    },
    checkSize: function(){
        if (this.length == 0) {
        for(var i in this.imgs){
            if(this.imgs[i]['dom'])
               this.container.appendChild(this.imgs[i]['dom']);
        }


        this.width = this.sWidth - this.wrapper.getSize().x -5; //TODO check it
        this.container.setStyle('width', this.sWidth);
        if (this.width > 0) {
            if (!this.isShow) {
                var _self = this;
                this.isShow = true;
                this.wrapper.setStyles({
                    'margin': '0 ' + this.options.padding + 'px'
                });
                this.width += this.options.padding * 2;
                this.createButtons(parent);
                if (this.options.isScroll) {
                    this.dom.addEvent('mousewheel', function(e){
                        e = new Event(e);
                        e.stop();
                        _self.move(e.wheel * 5);
                    });
                }
            }
        }
         this.hideMask();
        }
        return true;
    },
    hideMask: function(){
        var tween = new Fx.Tween(this.mask, {
            duration: 300,
            transition: Fx.Transitions.Quad.easeIn,
            onComplete: function(el){
                el.style.display = 'none';
            }
        });
        tween.start('opacity', 1, 0);
    },
    onClick: function(e, sid, img){
        new Event(e).stop();
        if (this.imgs[sid]) {
            this.actItem = this.imgs[sid];
            this.actItem.dom.addClass('loader');
            var tween = new Fx.Tween(this.imgs[sid].img, {
                duration: 300
            });
            tween.start('top', 0, -this.imgs[sid].img.getSize().y);
            this.fireEvent('onClick', sid)
            done.events.fireEvent('gallery.scroll.click', [sid, img]);
        }
    },
    onClickLoad: function(){
        if (this.actItem) {
            this.actItem.dom.removeClass('loader');
        }
    },
    onClose: function(){
        if (this.actItem) {
            var tween = new Fx.Tween(this.actItem.img, {
                duration: 300
            });
            tween.start('top', -this.actItem.img.getSize().y, 0);
        }
    },
    startMove: function(side){
        if (this.isClick)
            return false;
        this.isClick = true;
        var _self = this;
        this.stopMove();
        this.timer = setInterval(function(){
            _self.move(side);
        }, 50);
        return true;
    },
    stopMove: function(){
        if (this.timer)
            clearInterval(this.timer);
        this.isClick = false;
    },
    move: function(side){
        var p = this.pos = this.pos + side * 20;
        if (p <= 0) {
            this.pos = 0;
            this.stopMove();
        }
        if (p >= this.width) {
            this.pos = this.width;
            this.stopMove();
        }
        this.container.style.left = -this.pos + 'px';
    },
    createButtons: function(parent){
        var _self = this;

        this.dleft = new Element('div', {
            'class': 'left'
        });
        this.dleft.addEvents({
            'mousedown': function(){
                _self.startMove(-1);
            },
            'mouseup': function(){
                _self.stopMove();
            }
        });
        this.dright = new Element('div', {
            'class': 'right'
        });
        this.dright.addEvents({
            'mousedown': function(){
                _self.startMove(1);
            },
            'mouseup': function(){
                _self.stopMove();
            }
        });
        this.dom.appendChild(this.dleft);
        this.dom.appendChild(this.dright);
    }
});

var Popup = {
    isOpen: false,
    isCreate: false,
    isAnim: false,
    create: function(){
        if (!this.isCreate) {
            this.isCreate = true;
            this.dom = new Element('div', {
                'id': 'popup'
            });
            document.body.appendChild(this.dom);
            this.dom.onclick = function(){
                _s.close();
            };

            this.cont = new Element('div');
            this.dom.appendChild(this.cont);

            this.txt = new Popup.Descr(this.dom);

            this.wrapper = new Element('div', {
                'id': 'popup_click'
            });
            this.dom.appendChild(this.wrapper);

            this.wrapper.setOpacity(0);
            this.wrapper.addEvent('mouseover', function(e){
                new Event(e).stop();
                _s.txt.over();
            });
            this.wrapper.addEvent('mouseout', function(e){
                new Event(e).stop();
                _s.txt.out();
            });

            var _s = this;
            this.tween = new Fx.Tween(this.dom, {
                duration: 300,
                //transition: Fx.Transitions.Quad.easeOut,
                onComplete: function(){
                    _s.isAnim = false;
                    if (!_s.isOpen) {
                        _s.dom.setStyle('display', 'none');
                        Tool.showFlash();
                    }
                }
            });
        }
    },
    open: function(src, title, txt, callback){
        var img = new Image();
        var _self = this;
        img.onload = function(){
            _self.openImg(this, title, txt);
        }
        img.src = src;
        this.callback = callback;
    },
    openImg: function(img, title, txt){
        if (!this.isOpen) {
            this.create();
            Tool.hideFlash();
            this.width = img.width;
            this.height = img.height;

            this.cont.innerHTML = '';
            this.cont.appendChild(img);

            img.style.cursor = 'pointer';
            var _s = this;


            this.isOpen = true;
            Popup.Mask.show();
            this.dom.setStyles({
                'width': this.width,
                'height': this.height,
                'top': -this.height,
                'margin-top': -this.height / 2,
                'margin-left': -this.width / 2
            });
            this.txt.dom.setStyles({
                'width': this.width,
                'height': this.height
            });
            this.txt.cont.style.width = this.width - 20 + 'px';

            this.wrapper.setStyles({
                'width': this.width,
                'height': this.height
            });

            this.dom.setStyle('display', 'block');
            this.isAnim = true;
            this.openPos = window.getSize().y / 2 + window.getScroll().y;

            this.txt.setText(title, txt);
            this.tween.start('top', -this.height, this.openPos);

        }
    },
    close: function(){
        if (this.isOpen && !this.isAnim) {
            this.isOpen = false;
            this.isAnim = true;
            Popup.Mask.hide();

            if (this.callback)
                this.callback();
            this.tween.start('top', window.getSize().y / 2 + window.getScroll().y, -this.height);
        }
    }

};

Popup.Descr = function(dom){

    this.dom = new Element('div', {
        'class': 'descr'
    });
    dom.appendChild(this.dom);

    this.cont = new Element('div');
    this.cont.setOpacity(0.7);
    this.dom.appendChild(this.cont);
    this.cont.style.width = '100px';


    this.setText('');

    var _s = this;

    this.tween = new Fx.Tween(this.cont, {
        duration: 200,
        //transition: Fx.Transitions.Quad.easeOut,
        onComplete: function(a){

        },
        onCancel: function(a){

        }
    });
};
Popup.Descr.prototype = {};

var Mask = {
    isOpen: false,
    isCreate: false,
    create: function(){
        if (!this.isCreate) {
            this.isCreate = true;
            this.dom = new Element('div', {
                'id': 'pageMask'
            });
            document.body.appendChild(this.dom);
        }
    },
    show: function(){
        if (!this.isOpen) {
            this.isOpen = true;
            this.create();
            var wHeight = window.getSize().y;
            var wWidth = window.getSize().x;

            this.dom.setStyles({
                'height': window.getScrollSize().y,
                'opacity': 0
            });
            this.dom.setStyle('display', 'block');
            this.dom.fade(0.70);

        }
    },
    hide: function(){
        if (this.isOpen) {
            this.isOpen = false;
            this.dom.fade(0);
        }
    }
}

function insertBaner(){
    var so = new SWFObject(URL + "/themes/default/flash/baner.swf?page=" + (URL || '/') + "", "mymovie", "1002", "157", "8");
    so.addParam("quality", "hight");
    //so.addParam("wmode", "transparent");
    so.write("baner");

    so = new SWFObject(URL + "/themes/default/flash/sol-baner.swf", "mymovie", "107", "256", "8");
    so.addParam("quality", "hight");
    //so.addParam("wmode", "transparent");
    so.write("sol-baner");
}



/*
 GEvent.addListener(gmap, 'click',
 function(overlay, point){
 if (point) {
 // hide existing points
 gmap.clearOverlays();
 // add the new point
 gmap.addOverlay(new GMarker(point));
 // center to the new point
 gmap.panTo(point);
 // using the jquery val function set the input elements with names lat and long
 //$('input[name=lat]').val(point.lat());
 //$('input[name=lng]').val(point.lng());
 console.debug(point.lat(),point.lng());
 }
 });
 */
var CGMaps = new Class({
    initialize: function(cont, lat, lng){
        this.lat = lat;
        this.lng = lng;

        var txt = $('contact_descr');
        if (txt) {
            this.txt = txt.innerHTML;
        }

        var map = $(cont);
        if (map) {// && google && GBrowserIsCompatible()) {
            var mapG = new Element('div', {
                'id': 'cmaps_gmaps'
            });
            map.appendChild(mapG)
            var button = new Element('a', {
                'class': 'button',
                'href': '#zoom'
            });
            button.set('title', 'Kliknij aby powi\u0119kszyć.');
            button.innerHTML = 'powi\u0119ksz';

            map.appendChild(button);


            /*
             var button = new Element('a',{
             'class':'button',
             'href':'#map',
             'opacity':0.1
             });
             button.set('title','Kliknij aby powiększyć.');
             map.appendChild(button);
             */
            button.addListener('click', this.show.bind(this), true);

            this.gmaps(mapG, 14);

            this.dom = map;

            this.popup = new Element('div', {
                'id': 'cmaps_popup'
            });
            document.body.appendChild(this.popup);
            var _self = this;
            this.tween = new Fx.Morph(this.popup, {
                duration: 400,
                transition: Fx.Transitions.Sine.easeIn,
                onComplete: function(){
                    if (!_self.isShow) {
                        _self.isShow = true;
                        _self.showMap();
                    }
                    else {
                        _self.isShow = false;
                        _self.popup.style.display = 'none';
                        Tool.showFlash();
                    }
                }
            });

        }
    },
    gmaps: function(cont, zoom, big){



        var icon = new GIcon();
        icon.image = URL + "/themes/default/img/mapicon.png";
        icon.iconSize = new GSize(75, 26);
        icon.iconAnchor = new GPoint(0, 22);
        icon.infoWindowAnchor = new GPoint(0, 26);

        var gmap = new GMap2(cont);
        gmap.clearOverlays();
        var point = new GLatLng(this.lat, this.lng);
        gmap.setCenter(point, zoom);
        var marker = new GMarker(point, icon);
        gmap.addOverlay(marker);
        if (big) {
            gmap.addControl(new GLargeMapControl());
            if (this.txt) {
                var txt = this.txt;
                GEvent.addListener(marker, "click", function(){
                    marker.openInfoWindowHtml(txt);
                });
            }
        }
        var _self = this;
        var isMove = false;
        this.maps = this.maps || [];
        this.maps.push(gmap);
    },
    show: function(){
        if (this.isShow) {
            return false;
        }
        Mask.show();
        Tool.hideFlash();

        this.initPopup();
        var pos = this.dom.getPosition();
        var size = this.dom.getSize();

        var w = 800;
        var h = 600;
        var ws = window.getSize();
        if (h > ws.y + 50) {
            h = ws.y - 50;
        }
        if (w > ws.x + 40) {
            w = ws.x - 40;
        }
        var y = ws.y / 2 + window.getScroll().y - h / 2;
        var x = ws.x / 2 + window.getScroll().x - w / 2;

        this.tween.start({
            'height': [size.y, h],
            'width': [size.x, w],
            'top': [pos.y, y],
            'left': [pos.x, x]
        });
        this.popup.style.display = 'block';
        this.h = h;
        this.w = w;
        this.x = x;
        this.y = y;
        return true;
    },
    showMap: function(){
        if (this.pgmap) {
            this.pgmap.style.display = 'block';
            this.pclose.style.display = 'block';
            return false;
        }

        var d = new Element('div', {
            'class': 'body'
        });
        this.popup.appendChild(d);
        d.setStyles({
            'width': this.w,
            'height': this.h
        });
        this.gmaps(d, 15, true);
        this.pgmap = d;
        d = new Element('div', {
            'class': 'close'
        });
        d.innerHTML = 'Zamknij';
        this.popup.appendChild(d);
        d.addListener('click', this.close.bind(this));
        this.pclose = d;
        return true;
    },
    close: function(){
        Mask.hide();
        if (!this.isShow) {
            return false;
        }
        this.pgmap.style.display = 'none';
        this.pclose.style.display = 'none';

        var pos = this.dom.getPosition();
        var size = this.dom.getSize();

        this.tween.start({
            'height': [this.h, size.y],
            'width': [this.w = size.x],
            'top': [this.y, pos.y],
            'left': [this.x, pos.x]
        });
        return true;
    },
    initPopup: function(){
        var pos = this.dom.getPosition();
        var size = this.dom.getSize();
        this.popup.setStyles({
            'left': pos.x,
            'top': pos.y,
            'width': size.x,
            'height': size.y
        });

    }
});

var Tool = {
    hideFlash: function(){
        $$('object, embed').each(function(el){
            el.style.display = 'none';
        });
    },
    showFlash: function(){
        $$('object, embed').each(function(el){
            el.style.display = 'block';
        });
    }
};

window.addEvent('domready', function(){

    Mask.create();
    new done.gallery('gallery');
    if (typeof URL == 'undefined')
        var URL = '';

    new CGMaps('cmaps', 51.85394408729539, 19.399731159210205);
    insertBaner();
});

