var MiniVideoPlayer = new Class({
    Implements: [Options, Events],
    options:
    {
        container: null,
        video: '',
        bgColor: '#a59768',
        isShow: false,
        isInit: false,
        playerPath: '/flash/minivideoplayer.swf?' + Math.random(),
        delay: 700,
        imgPath: '/images/'
    },
    initialize: function(options)
    {
        this.setOptions(options);
        this.options.container = $(this.options.container);
        this._initIcon();
        this._initPlayer();
        this._initBG();
        this._initSlider();
    },
    _initPlayer: function()
    {
        this.options.playerContainer = new Element('div', {
            styles:
            {
                position: 'absolute',
                zIndex: 13,
                left: 7,
                top: 7,
                backgroundColor: this.options.bgColor,
                opacity: 0,
                width: 594,
                height: 405
            }
        }).inject(this.options.container);
    
        this.options.player = new Swiff(this.options.playerPath, {
            id: 'videoplayer',
            width: 594,
            height: 405,
            params: {
                wmode: 'opaque',
                bgcolor: this.options.bgColor,
                swLiveConnect: true,
                allowScriptAccess: 'always',
                allowFullScreen: true
            }

        }).inject(this.options.playerContainer);
        
    },
    _initBG: function()
    {
        this.options.bg = new Element('div', {
            styles:
            {
                position:'absolute',
                zIndex: 12,
                left: 7,
                top: 7,
                backgroundColor: this.options.bgColor,
                width: 0,
                height: this.options.container.getHeight() - 14
            }
        }).inject(this.options.container);
    
        this.options.bar = new Element('img', {
            src: this.options.imgPath + 'arrow.gif',
            styles:
            {
                width: 10,
                height: 405,
                position: 'absolute',
                right: 0,
                top: 0,
                zIndex: 14,
                cursor: 'pointer',
                display: 'none'
            },
            events:
            {
                click: function()
                {
                    this.togglePlayer();
                }.bind(this)
            }
        }).inject(this.options.bg);
        
        
        
    },
    _initSlider: function()
    {
        this.options.slider = new Fx.Morph(this.options.bg, {
            transition: Fx.Transitions.Circ.easeOut,
            onComplete: function()
            {
                if(!this.options.isShow)
                {
                    this.options.playerContainer.setStyle('opacity', 1);
                    this.options.bar.setStyle('display', 'inline');
                    this.options.isShow = true;
                    Browser.Engine.gecko ? (function(){this.getPlayer().playMovie()}).delay(this.options.delay, this) : (function(){Swiff.remote($('videoplayer'), 'playMovie');}).delay(this.options.delay);
                }    
                else
                {
                    //this.options.bar.setStyle('display', 'none');
                    this.options.isShow = false;
                }
            }.bind(this)
        })
    },
    _initIcon: function()
    {
        var div = new Element('div', {
            styles: 
            {
                position: 'absolute',
                zIndex: 12,
                left: 7,
                top: 340
            }
        }).inject(this.options.container);
        new Element('img', {
            src: this.options.imgPath + 'camera.png',
            width: 71,
            height: 72,
            styles: { cursor: 'pointer' },
            events:
            {
                click: function()
                {
                    this.togglePlayer();
                }.bind(this)
            }
        }).addClass('pngfix').inject(div);
    },
    togglePlayer: function()
    {
        //var callout = $('callout');
        
    
        this.options.slider.cancel();
        
        if(!this.options.isShow)
        {
            this.options.slider.start({'width': [this.options.bg.getWidth(), 604]});
            /*if(callout)
                callout.setStyle('display', 'none');*/
        }
        else
        {
            /*if(callout)
                callout.setStyle('display', 'block');*/
            this.options.playerContainer.setStyle('opacity', 0);
            Browser.Engine.gecko ? this.getPlayer().pauseMovie() : Swiff.remote($('videoplayer'), 'pauseMovie');
            this.options.slider.start({'width': [this.options.bg.getWidth(), 0]});
            this.options.bar.setStyle('display', 'none');
        }
        
        if(!this.options.isInit)
        {
            this.options.isInit = true;
            Browser.Engine.gecko ? (function(){this.getPlayer().playNext(this.options.video, true, '');}).delay(this.options.delay, this) : (function(){Swiff.remote($('videoplayer'), 'playNext', this.options.video, true, '');}).delay(this.options.delay, this);
        }
        
    },
    getPlayer: function()
    {
        var flashObj;
        if (navigator.appName.indexOf("Microsoft") != -1) {
            flashObj = window["videoplayer"];
        }
        else {
            flashObj = document["videoplayer"];
            if(flashObj && flashObj.length)
                flashObj = flashObj[1];
        }
        
        return flashObj
    }
});

