var LLFlash = {

        init: function(options){
                this.options = Object.extend({
                        flashWidth: 720,
                        flashHeight: 370,
                        containerWidth: 720,
                        containerHeight: 395
                }, options || {});
                //this.overlay = new Element('div');
                this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(document.body);
                this.container = new Element('div').setProperty('id', 'lbFlashContainer').setStyles({width: this.options.containerWidth+'px', height: this.options.containerHeight+'px', display: 'none'}).injectInside(document.body);
                this.flash = new Element('div').setProperty('id', 'lbFlash').setStyles({width: this.options.flashWidth+'px', height: this.options.flashHeight+'px'}).injectInside(this.container);
                new Element('a').setProperties({id: 'lbCloseLink', href: '#'}).injectInside(this.container).onclick = this.overlay.onclick = this.close.bind(this);
                this.fx = {
                        overlay: this.overlay.effect('opacity', {duration: 500}).hide()
                };

                this.eventPosition = this.position.bind(this);
        },

        show: function(){
                this.position();
                this.setup(true);
                this.top = window.getScrollTop() + ((window.getHeight() - this.options.containerHeight) / 2) - 1;
                this.left = ((window.getWidth() - this.options.containerWidth) / 2) - 1;
                this.container.setStyles({top: this.top+'px', left: this.left+'px', display: ''});
                this.fx.overlay.start(0.8);

                return false;
        },

        setup: function(open){
                var elements = $A(document.getElementsByTagName('object'));
                if (window.ie) elements.extend(document.getElementsByTagName('select'));
                elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
                var fn = open ? 'addEvent' : 'removeEvent';
                window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);

                if (open)
                  this.flash.innerHTML = '<!--[if !IE]> -->' +
                    '<!--[if !IE]> -->' +
                    '<object type="application/x-shockwave-flash"' +
                    '  data="/Portals/3/personal_stylist.swf" width="720" height="370">' +
                    '<!-- <![endif]-->' +
                    '<!--[if IE]>' +
                    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
                    '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
                    '  width="720" height="370">' +
                    '  <param name="movie" value="/Portals/3/personal_stylist.swf" />' +
                    '<!--><!---->' +
                    '  <param name="loop" value="true" />' +
                    '  <param name="menu" value="false" />' +
                    '<p>The <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW">Macromedia Flash</a> plug-in is required to view this animation.</p>' +
                    '</object>' +
                    '<!-- <![endif]-->';
		else
                  this.flash.innerHTML = '';

                //document[fn]('keydown', this.eventKeyDown);
                //this.step = 0;
        },


        position: function(){
                this.overlay.setStyles({top: window.getScrollTop()+'px', height: window.getHeight()+'px'});
        },

        close: function(){
                for (var f in this.fx) this.fx[f].stop();
                //this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
                this.setup(false);
                this.container.style.display = 'none';
                this.fx.overlay.start(0);
                return false;
        }

};

window.addEvent('domready', LLFlash.init.bind(LLFlash));

