var AppCreator = new Class({

    Implements: [Options, Events],
    
    options: {uri:'', height:'', width:''},

    initialize: function(options){
        this.setOptions(options);

        if(screen.height <= 1024 && options.height > 650){
            this.options.height = (options.height.toInt() * .8).round();
            this.options.width = (options.width.toInt() * .8).round();
        }

        this.handleScrolling();

        this.size = $(document.body).getSize();
	this.scroll = $(document.body).getScrollSize();

        $('app').setStyle('min-height', this.scroll.y - 5);
        
        this.create();
        this.slideIn(); 
    },

    create: function(){
        
        this.frame = new IFrame({
            src: this.options.uri,
            scrolling: 'no',
            frameborder: '0',
            allowTransparency: true,
            styles: {
                width: this.options.width.toInt(),
                height: this.options.height.toInt()
            }
        });
        
        this.app_container = new Element('div', {
            styles: {
                position:'relative',
                margin: '20px auto',
                background:'transparent',
                width: this.options.width.toInt(),
                height: this.options.height.toInt(),
                border: '2px solid #0b6497'
            }
        });

        this.close_button = new Element('div', {
            html:'<a href="#" class="close">schließen</a>',
            styles: {
                position: 'absolute',
                top:'-10px',
                right:'-40px'
            }
        });

        this.close_button.addEvent('click', this.remove.bind(this));

        $('app').adopt(this.app_container);
    },

    remove: function(){

        this.size = $(document.body).getSize();

        this.app_container.set('morph', {duration: 200});
        this.app_container.morph({opacity: 0});

        new Fx.Morph($('app'), {duration: 1000, onComplete: function(){
            this.app_container.dispose();
            $('app').setStyle('min-height', '');
            $(document.body).setStyle('overflow', 'auto');
        }.bind(this)}).start({top: this.size.y - 5});

        this.handleScrolling();

        return false;
    },

    slideIn : function(){
        new Fx.Morph($('app'), {duration: 1000, onComplete: function(){
            this.app_container.adopt(this.frame);
            this.app_container.adopt(this.close_button);
            $(document.body).setStyle('overflow', 'auto');
        }.bind(this)}).start({top: '0'});
    },
    
    handleScrolling: function(){
        if(window.getSize().y >= window.getScrollSize().y)
        $(document.body).setStyle('overflow', 'hidden');
    }
    

});


