VideoEdit = function(){
      var dialog;
      var form;
      return {
          init : function(){
          },
      
      showDialog : function(videoid){
      	  this.createDialog();
      	  this.form = null;
      	  this.createForm(videoid);
      	  this.dialog.show();
      },
      
      createDialog : function(){
  	 
			
            this.dialog = new Ext.LayoutDialog("videoedit-dlg", { 
                    modal:true,
                    width:650,
                    height:325,
                    shadow:true,                       
                    minWidth:400,
                    minHeight:325	                   
            });
            this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);

            this.dialog.body.setStyle('padding','8pt');               
           
      },
      
           
      createForm : function(videoid) {     			
			Ext.QuickTips.init();
			
			Ext.form.Field.prototype.msgTarget = 'side';
		
		    this.form = new Ext.form.Form({
		        labelAlign: 'right',
		        labelWidth: 95,
		        method: 'GET',
				url: Application.baseUrl + 'videos/setDetails/',
				buttonAlign: 'right'
		    });
		
		
		    var video_title = new Ext.form.TextField({
		        fieldLabel: 'Title',
		        name: 'title',
		        width:190
		    });
		
		    var video_description = new Ext.form.TextArea({
		        fieldLabel: 'Description',
		        name: 'description',
		        grow: true,
		        width:190
		    });
		
		    var video_tags = new Ext.form.TextField({
		        fieldLabel: 'Tags',
		        name: 'tags',
		        width:190
		    });
	
		    var video_externaltags = new Ext.form.TextField({
		        fieldLabel: 'External Tags',
		        name: 'externaltags',
		        width:190
		    });
			
			 var video_excluded = new Ext.form.Checkbox({
		        fieldLabel: 'Excluded',
		        name: 'excluded',
		        width:190
		    });
		    
		     var video_suggested = new Ext.form.Checkbox({
		        fieldLabel: 'Suggested',
		        name: 'suggested',
		        width:190
		    });
		    
		    
			this.form.column({width: 350, labelWidth:95});
		    this.form.fieldset(
		        {legend:'Video Edit'},
				video_title,
				video_description,
				video_tags,
				video_externaltags,
				video_excluded,
				video_suggested
			)
			this.form.end();

			this.form.column(
			        {width:202, style:'margin-left:10px', clear:true}
			);
			
			this.form.fieldset(
			        {id:'detailsimage', legend:'Image'}
			);
			
			this.form.end();
		
			video_data = new Ext.data.Store({
				proxy: new Ext.data.HttpProxy({url: Application.baseUrl + 'videos/getDetails?id=' + videoid}),
				reader: new Ext.data.JsonReader({},[ 'id', 'title', 'description', 'tags', 'externaltags', 'thumbnailurl', 'excluded', 'suggested']),
				remoteSort: false
			});
			
			video_data.on('load', function() {
								
				video_title.setValue(video_data.getAt(0).data.title);
				video_description.setValue(video_data.getAt(0).data.description);
				video_tags.setValue(video_data.getAt(0).data.tags);
				video_externaltags.setValue(video_data.getAt(0).data.externaltags);
				video_excluded.setValue(Ext.util.Format.boolean(video_data.getAt(0).data.excluded));
				video_suggested.setValue(Ext.util.Format.boolean(video_data.getAt(0).data.suggested));
				
				VideoEdit.form.addButton('Exclude', function(){
						VideoEdit.dialog.hide();
						VideoManager.excludeVideo(videoid);		
				}, VideoEdit.form);
				
				VideoEdit.form.addButton('Save', function(){
					if (VideoEdit.form.isValid()) {
						VideoEdit.form.submit({
							params:{
								action:'submit',
								id:video_data.getAt(0).data.id
							}, 
							waitMsg:'Saving...',
							failure: function(form, action) {
                                                Ext.MessageBox.alert('Status', action.result.error, null);
                                            },
                            success: function(form, action) {
                                                VideoEdit.dialog.hide();
                                            }
						});	
					}else{
						Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
					}
				}, VideoEdit.form);
			
				VideoEdit.form.render(VideoEdit.dialog.body);
				// The form elements are standard HTML elements. By assigning an id (as we did above)
			    // we can manipulate them like any other element
			    var photo = Ext.get('detailsimage');
			    var c = photo.createChild({
			        tag:'center', 
			        cn: {
			            tag:'img',
			            src: video_data.getAt(0).data.thumbnailurl,
			            style:'margin-bottom:5px;',
			            width:180,
			            height:135
			        }
			    });
						
			});
									
		video_data.load();           
      }
    }    
}();

//Hide the loading stuff
			var loading = Ext.get('loading');
			var mask = Ext.get('loading-mask');
			mask.setOpacity(.8);
			mask.shift({
				xy:loading.getXY(),
				width:loading.getWidth(),
				height:loading.getHeight(), 
				remove:true,
				duration:1,
				opacity:.3,
				easing:'bounceOut',
				callback : function(){
					loading.fadeOut({duration:.2,remove:true});
				}
			});
