function photoEdit(initOptions){
    if(!canEdit){
    userLogin();
    photoWin.close();
    }
    var windowHeight = 250;

    var _self = this;
    var _settings = {};
    _settings.photoID = 0;
    _settings.action = 'gallery';
    _settings.gcdID = 0;    
    _settings.albumID = 0;  
    
    Ext.apply(_settings, initOptions);
    
    if(_settings.photoID != 0)
        windowHeight = 350;
    
    function saveImage(){
      PhotoInfoPanel.getForm().submit({
        clientValidation: true, 
        standardSubmit:false, 
        fileUpload:true,
        url:'/ajax/gallery/uploadPhoto.cfm', 
        waitMsg:'Uploading thumbnail and Saving...',
        params: {
          ID: _settings.photoID,
          uimg: 1,
          max: 1,
          action:_settings.action,
          gcdID: _settings.gcdID,
          catID: _settings.albumID
        },
        errorReader : new Ext.data.JsonReader({
            root:'extra',
            successProperty:'success'
          }, ['ImageID','title','desc','newItem']),
        success: function(form, action) {
            photoWin.close();
            if(_settings.action == 'gallery') {
            addGalItem(action.result.imageID,action.result.title,action.result.desc,action.result.imageName,action.result.newItem,_settings.gcdID,_settings.albumID,action.result.imageFFID);
            } else if (_settings.action == 'category') {
              window.location.reload(true);
            } else if (_settings.action == 'slideshow') {
              imageStore.reload();
            }
        },
        failure: function(form, action) {
          switch (action.failureType) {
              case Ext.form.Action.CLIENT_INVALID:
                  Ext.Msg.alert('Failure', 'Please verify fields are correct.');
                  break;
              case Ext.form.Action.CONNECT_FAILURE:
                  Ext.Msg.alert('Failure', 'Ajax communication failed');
                  break;
              case Ext.form.Action.SERVER_INVALID:
              default:
                  Ext.Msg.alert('Failure', action.result.msg);
          }
        }
      });
    }
    
    function addGalItem(id,title,desc,ImageName,newImage,gcdID,albumID,ffID) {
      var tmpImage = new Image();
      var rHeight = 105;
      var rWidth = 120;
        tmpImage.src = '/files/gallery/' + id + '/' + ImageName;
        OrigWidth = parseInt(tmpImage.width);
        OrigHeight = parseInt(tmpImage.height);
        if(tmpImage.width > tmpImage.height) {
          rWidth = 120;
          rHeight = Math.round((OrigHeight/OrigWidth) * rWidth);
        } else {
          rHeight = 105;
          rWidth = Math.round((OrigWidth/OrigHeight) * rHeight);
        }
      if(newImage){
        imageLinkItem = '<a href="/files/gallery/' + id + '/' + ImageName + '" class="lightview PhotoGrid_PhotoLink clearfix" rel="gallery[sets]" title=""><img title="" class="PhotoGrid_Image" alt="' + title + '::' + desc + '" src="/files/gallery/' + id + '/' + ImageName + '" width="' + rWidth + '" height="' + rHeight + '"/></a><div class="editContainer"><a class="editBtn" href="##" title="Edit"><img src="/common/images/gallery/picture_edit.png"></a><a class="editBtn" href="##" title="Delete"><img src="/common/images/gallery/picture_delete.png"></a><br class="clear"/></div>';
        var checkLast = false;
        lastID = $$('#galleryTable tbody > tr > td:last-child').each(
            function(s){ 
              checkLast = (s).hasClassName('lastItem');
            }
          );
        if (checkLast) {
          $('galleryTable tbody').insert({
            bottom: '<tr><td class="PhotoGrid_TableCell">'+imageLinkItem+'</td></tr>'
          });
        } else {
          lastRowItemCheck = $$('#galleryTable tbody > tr:last-child').size();
          var SetClassName = '';
          if(lastRowItemCheck == 0){
            $$('#galleryTable tbody').each(function(s){(s).insert({
              bottom: '<tr><td class="PhotoGrid_TableCell' + SetClassName + '">'+imageLinkItem+'</td></tr>'
            });});
          } else {
            if(lastRowItemCheck == 3){SetClassName = ' lastItem';}
            $$('#galleryTable tbody > tr:last-child').each(function(s){(s).insert({
              bottom: '<td class="PhotoGrid_TableCell' + SetClassName + '">'+imageLinkItem+'</td>'
            });});
          }
        }
      } else {
        $$('.photoLink_' + id).each(function(s){(s).writeAttribute('href','/files/gallery/' + id + '/' + ImageName)});
        $$('.photoLink_' + id).each(function(s){(s).writeAttribute('alt',title + '::' + desc)});
        $$('.photoImage_' + id).each(function(s){(s).writeAttribute('src','/files/gallery/' + id + '/' + ImageName)});
        $$('.photoImage_' + id).each(function(s){(s).writeAttribute('width',rWidth)});
        $$('.photoImage_' + id).each(function(s){(s).writeAttribute('height',rHeight)});
      }
    }
    
    /*var catStore = new Ext.data.Store({
      autoLoad: true,
      url: '/ajax/editor/getCategories.cfm?type=gallery&groupID=0',
      reader : new Ext.data.JsonReader({
          root : 'categories'                           
        },[
          {name: 'id', mapping: 'id'},
          {name: 'title', mapping: 'title'},
          {name: 'desc', mapping: 'desc'}
        ]
      )
    });*/
    
    var formItems = [];
        if(_settings.action != 'category'){
          if(_settings.photoID != 0)
            formItems.push({xtype:'box',anchor:'100%',fieldLabel:'Current',autoEl:{tag:'div',style:'text-align:center',children:[{tag:'img',qtip:'Current Uploaded Image',src:'/thumber.cfm?id='+_settings.imageID+'&w=150&h=112&fill=1'}]}});
          formItems.push({xtype: 'fileuploadfield', anchor:'100%', emptyText: 'Select a image', fieldLabel: 'Image', name: 'photoFile_1', allowBlank: true, buttonText: '', buttonCfg: {iconCls: 'file-upload-icon'}});
        }
        formItems.push({fieldLabel: 'Title', anchor:'100%',name: 'title', maxLength:50, maxLengthText: 'Your Title Exceeds 50 Characters'});
        formItems.push({fieldLabel: 'Description', anchor:'100% -30', name: 'desc', xtype: 'textarea', maxLength:250, maxLengthText: 'Your Title Exceeds 250 Characters', flex:1});
        
        /*formItems.push(new Ext.form.ComboBox({
                        store: catStore,
                        triggerAction: 'all',
                        allowBlank:false, 
                        editable: false,
                        mode: 'local',
                        fieldLabel: 'Category',
                        hiddenName: 'editor_category',
                        hiddenValue: _settings.albumID,
                        //name: 'editor_category',
                        id: 'gallery_category',
                        valueField: 'id',
                        displayField: 'title',
                        //setvalue:'School Events'
                      }));*/
                                                        
    
    
    
    
    var xmlCols = [];
        xmlCols.push({name: 'title', mapping: 'title'});
        xmlCols.push({name: 'desc', mapping: 'content'});
  
  
  var PhotoInfoPanel = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 390,
        reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
        defaults: {width: 230},
        fileUpload:true,
        defaultType: 'textfield',
        items: [
        formItems
        ],
        listeners:{
          render:function(el){
           el.getForm().load({url:'/ajax/gallery/getData.cfm?id='+_settings.photoID+'&action='+_settings.action, waitMsg:'Loading Data....'});
           }
        },
        buttons: [{
            text: 'Save',
            handler: function(){ saveImage();}
        },{
            text: 'Cancel',
            handler: function(){ photoWin.close() }
        }]
    });
    
 var photoWin = new Ext.Window({
          id: 'photoPanel_win_' + _settings.photoID,
          plain: true,
          title: 'Photo Upload',
          width:390,
          minWidth: 390,
          height:windowHeight,
          minheight:windowHeight,
          maxHeight: windowHeight,
          border: false,
          layout:'fit',
          closable: true,
          closeAction:'close',
          maximizable: true,
          modal: false,
          items: PhotoInfoPanel
      });
      photoWin.show(this);
      if (journeyHelper.isRunning){
        journeyHelper.setHelpTopic('gallery_upload');
        journeyHelper.showHelpTopic();
      }
};



