//this is the main editor window
VideoDownloadWindow = Ext.extend(VideoDownloadWindowUi, {
    initComponent: function() {
        VideoDownloadWindow.superclass.initComponent.call(this);
        
        this.initButtons();
    },
    initButtons:function(){
        this.buttons[0].on('click',this.saveForm,this);
        this.buttons[1].on('click',this.closeWindow,this);
    },
    saveForm:function(b,e){
        var form = this.getComponent('video-form');
        
        var win = this;
        
        form.getForm().submit({
            success:function(f,o){
                Ext.Msg.alert('Success','Thank you.',function(b,e){
                    if(b == "ok"){
                        win.close();
                        
                        for(var x=0;Ext.get('player'+x) != null;x++)
                        {
				        	var id = 'player'+x;

							var v = "";

				            switch(id){
				            	case "player0":
				            		v = 'http://econtext.s3.amazonaws.com/2011/ArcticGas2011/BERGER%20VIDEO.mp4';
				            	break;
				            	case "player1":
				            		v = 'http://econtext.s3.amazonaws.com/2011/ArcticGas2011/MACGUIRE%20VIDEO.mp4';
				            	break;
				            	case "player2":
				            		v = 'http://econtext.s3.amazonaws.com/2011/ArcticGas2011/SPEEDMAN%20VIDEO.mp4';
				            	break;
				            	
				            }

	                        var player = Ext.get(id);
	                        player.replaceWith({
	                            id:id,
	                            tag:'div',
	                            style:'margin-left:'+
	                                player.getMargins('l')+
	                                'px;display:block;width:'+
	                                player.getWidth()+
	                                'px;height:'+
	                                player.getHeight()+'px'
	                        });
	                        
	                        flowplayer(id, { src:"http://www.alaskaoilandgascongress.com/files/swf/flowplayer.commercial-3.2.5.swf",wmode:'transparent'}, {
	                            // commercial version requires product key
	                            key: '#@d20b55d53d109726e0a',
	                            // change the default controlbar to modern
	                            plugins:{
	                                controls:{
	                                    url: 'http://www.alaskaoilandgascongress.com/files/swf/flowplayer.controls-3.2.3.swf',
	                                    
	                                    borderRadius: '0px',
	                                    timeColor: '#ffffff',
	                                    bufferGradient: 'none',
	                                    slowForward: true,
	                                    backgroundColor: 'rgba(46, 84, 133, 0.55)',
	                                    volumeSliderGradient: 'none',
	                                    slowBackward: false,
	                                    timeBorderRadius: 20,
	                                    progressGradient: 'none',
	                                    time: true,
	                                    height: 26,
	                                    volumeColor: '#4599ff',
	                                    
	                                    tooltips:{
	                                        marginBottom: 5,
	                                        volume: true,
	                                        scrubber: true,
	                                        buttons: false
	                                    },
	                                    
	                                    fastBackward: false,
	                                    opacity: 1,
	                                    timeFontSize: 12,
	                                    bufferColor: '#a3a3a3',
	                                    border: '0px',
	                                    volumeSliderColor: '#ffffff',
	                                    buttonColor: '#ffffff',
	                                    mute: true,
	                                    
	                                    autoHide:{
	                                        enabled: true,
	                                        hideDelay: 500,
	                                        hideStyle: 'fade',
	                                        mouseOutDelay: 500,
	                                        hideDuration: 400,
	                                        fullscreenOnly: false
	                                    },
	                                    
	                                    backgroundGradient: [0,0.2,0.4],
	                                    width: '100pct',
	                                    display: 'block',
	                                    sliderBorder: '1px solid rgba(128, 128, 128, 0.7)',
	                                    buttonOverColor: '#ffffff',
	                                    fullscreen: true,
	                                    timeBgColor: 'rgb(0, 0, 0, 0)',
	                                    scrubberBarHeightRatio: 0.1,
	                                    bottom: 0,
	                                    stop: false,
	                                    zIndex: 1,
	                                    sliderColor: '#000000',
	                                    scrubberHeightRatio: 0.6,
	                                    tooltipTextColor: '#ffffff',
	                                    sliderGradient: 'none',
	                                    timeBgHeightRatio: 0.8,
	                                    volumeSliderHeightRatio: 0.4,
	                                    name: 'controls',
	                                    timeSeparator: ' ',
	                                    volumeBarHeightRatio: 0.1,
	                                    left: '50pct',
	                                    tooltipColor: 'rgba(0, 0, 0, 0)',
	                                    playlist: false,
	                                    durationColor: '#b8d9ff',
	                                    play: true,
	                                    fastForward: true,
	                                    timeBorder: '0px solid rgba(0, 0, 0, 0.3)',
	                                    progressColor: '#4599ff',
	                                    volume: true,
	                                    scrubber: true,
	                                    builtIn: false,
	                                    volumeBorder: '1px solid rgba(128, 128, 128, 0.7)'
	                                }
	                            },
	                            
	                            // setting for movie clip
	                            clip:  {
	                                url: v,
	                                autoPlay: false,
	                                autoBuffering: true
	                            }
	                        });
                        }
                    }
                });
            },
            failure:function(f,o){
                if(o.failureType =="client") Ext.Msg.alert('Failure','Please fill out the form in full.');
                else Ext.Msg.alert('Failure','<div style="width:200px;">An error occured with your request. '+o.result.error+'</div>')
            }
        });
    },
    closeWindow:function(b,e){
        this.close();
    }
});
