/**
	jLayer plugin
	2009-2010(c) http://attentionplatform.com
**/


function Layer(base, id, options) {
    this.base = base;
    this.layerId = id;
    this.layer = null;
    this.backLayer = null;
    this.already = false;
    this.options = { height: 200, width: 500, autoheight: false };
    $.extend(this.options, options);
}

Layer.prototype = {

    extend: function(src) {
        var temp = {};
        for(var x in src) {
            if((typeof temp[x] === "undefined") || (temp[x] != src[x])){
                this[x] = src[x];
            }
        }
        return this;
    },

    show: function() {
        if (this.already) return false; else this.already = true;
        
        this.backLayer = $("<div />", {
            id: "backlayer-" + this.layerId,
            css: { opacity: 0 }
        }).appendTo(this.base);
        this.backLayer.attr("class", "backlayer-class").animate({opacity: 0.5}, 1500);
        var f = $.proxy(function(){ this.backLayer.remove(); this.layer.remove(); this.already = false; }, this);
        //this.backLayer.click(f);
        this.layer = $("<div id = '"+this.layerId+"'></div>").css(
            {
                width: this.options.width,
                top: (((($.browser.msie ? screen.height : window.innerHeight) - this.options.height) / 2)),
                left: (((screen.width - this.options.width) / 2)),
                opacity: 0
            }
        ).attr("class", "layer-class").appendTo(this.base);
        this.options.autoheight ? this.layer.css("min-height", this.options.height) : this.layer.css("height", this.options.height);
        if (this.options.autoheight) this.layer.css("top", parseInt(this.layer.css("top"), 10)-this.options.height/2.2);
        this.layer.delay(1500).animate({opacity: 1}, 750);
        var close = $("<img src = '/js/close.png' class = 'layer-close' title = 'close' />");
        close.click(f);
        this.layer.append(close);
        
    }

};


