var FormNoticeElement = new Class({});

FormNoticeElement.hideElementNotice = function(){
    if( this.noticeElement == null )
    {
        return;
    }

    this.noticeElement.dispose();
    this.noticeElement = null;
};

FormNoticeElement.showElementNotice = function(element,notice){
    FormNoticeElement.hideElementNotice();

    this.noticeElement = new Element("div");
    this.noticeElement.element = element;
    this.noticeElement.addClass("FormNoticeElement");

        var container = new Element("div");
        container.addClass("container");
        container.inject(this.noticeElement);
        container.set("html",notice);

        var tl = new Element("div");
        tl.addClass("tl");
        tl.inject(this.noticeElement);

        var t = new Element("div");
        t.addClass("t");
        t.inject(this.noticeElement);

        var tr = new Element("div");
        tr.addClass("tr");
        tr.inject(this.noticeElement);

        var bl = new Element("div");
        bl.addClass("bl");
        bl.inject(this.noticeElement);

        var b = new Element("div");
        b.addClass("b");
        b.inject(this.noticeElement);

        var br = new Element("div");
        br.addClass("br");
        br.inject(this.noticeElement);

        var l = new Element("div");
        l.addClass("l");
        l.inject(this.noticeElement);

        var r = new Element("div");
        r.addClass("r");
        r.inject(this.noticeElement);

        var arrow = new Element("div");
        arrow.addClass("arrow");
        arrow.inject(this.noticeElement);

    this.noticeElement.addEvent("click",function(){
        this.fx.start("top",this.outOfScreenTop);
    });

    this.noticeElement.inject(document.body);
    this.noticeElement.fx = new Fx.Tween(this.noticeElement,{
        link: "cancel",
        duration: 600,
        transition: Fx.Transitions.Elastic.easeOut
    });

    var width = this.noticeElement.getWidth();
    var height = this.noticeElement.getHeight();

    t.setStyle("width",width-12);
    b.setStyle("width",width-12);
    l.setStyle("height",height-26);
    r.setStyle("height",height-26);
    arrow.setStyle("left",Math.round(width/2-15));

    FormNoticeElement.updateElementNoticePosition();

};

FormNoticeElement.updateElementNoticePosition = function(){
    if( this.noticeElement == null )
    {
        return;
    }
    var width = this.noticeElement.getWidth();
    var height = this.noticeElement.getHeight();
    var left = Math.round(this.noticeElement.element.getLeft() + (this.noticeElement.element.getWidth()/2) - (width/2));
    var top = this.noticeElement.element.getTop()-this.noticeElement.getHeight();
    this.noticeElement.setStyle("left",left);

    this.noticeElement.outOfScreenTop = -height*2;
    this.noticeElement.setStyle("top",this.noticeElement.outOfScreenTop);
    this.noticeElement.fx.start("top",top+11);
};
