/* 
 * ClickableLayer
 */

var ClickableLayer = new Class({
    Implements: [Options],
    options: {
        cookieOptions: {
            duration: 0
        }
    },
    initialize: function(item, options) {
        this.setOptions(options);
        this.item = $(item);        
        this.closer = this.item.getElement('div.closer');

        // check, if already set
        this.visible = Cookie.read('clickableLayer',
                                   this.options.cookieOptions);
        if (null == this.visible) {
            this.visible = true;
            Cookie.write('clickableLayer',
                         this.visible,
                         this.options.cookieOptions);
        }

        this.initCloser();
        this.displayLayer();
    },

    initCloser: function() {
        this.closer.addEvent('click', function() {
            this.visible=false;
            this.displayLayer();
            Cookie.write('clickableLayer',
                         this.visible,
                         this.options.cookieOptions);
        }.bind(this));
    },

    displayLayer: function() {
        if (this.visible == 'true') {
            new Fx.Reveal(this.item).reveal();
        } else {
            new Fx.Reveal(this.item).dissolve();
        }
    }
});

