Ext.namespace('cmv.gallery');

cmv.gallery.Panel=Ext.extend(Ext.Panel, {
  constructor: function(config) {
    config=Ext.apply({
      frame:true,
      autoScroll: true,
      title:' ',
      id:'cmvgallery-panel',
      items:new Ext.DataView({
        style:'overflow:auto',
        store: new Ext.data.JsonStore({
          url: 'json/get-images.php',
          autoLoad: false,
          baseParams:{
            year:2003,
            gallery: 'Enkeltstart'
          },
          root: 'images',
          id:'name',
          fields:[
          'name', 'url','url2',
          {
            name: 'shortName',
            mapping: 'name'
          }
          ],
          listeners:{
            load: {
              fn: function(store, record, operation){
                var pnl = operation.scope;
                pnl.setTitle(pnl.title+", "+store.getCount()+" billeder");
                Ext.ux.Lightbox.register('a.cmv-gallery', true);
                //collapse opslagstavlen
                cmv.opslag.Panel.collapse();
              }
            }
          }
        }),
        tpl: new Ext.XTemplate(
          '<tpl for=".">',
          '<div class="thumb-wrap" id="{name}">',
          '<a href="{url2}" class="cmv-gallery"><img src="{url}" class="thumb-img"></a>',
          '</div>',
          '</tpl>'
          )
      })
    },config);
    cmv.gallery.Panel.superclass.constructor.call(this, config);
  },
  update: function(item)
  {
    var store = this.get(0).getStore();
    store.setBaseParam('year', Math.floor((eval(item.id)+39000)/21));
    store.setBaseParam('gallery', item.text);
    cmv.gallery.Panel.superclass.setTitle.call(this,"Billedgalleri > "+Math.floor((eval(item.id)+39000)/21)+" > "+item.text);
    store.load({
      scope:this
    });
  }
});

Ext.reg('cmvgallerypanel', cmv.gallery.Panel);

