Ext.Lightbox = function(){
    return {
        showText: function(elementId, title) {
          var content = Ext.get(elementId).dom.innerHTML;
          content = '<div style="padding: 15px 30px 15px 30px;">'+content+'</div>';
          var winId = 'lightbox'+new Date().getTime();
           
          var win = new Ext.Window({
            id: winId,
            title: title,
            html: content,
            autoScroll: true,
            modal: true,
            width: 800,
            height: 500,
            reziable: false,
            listeners: {
              afterrender: function() {
//                (function() {
//                  if(Ext.getCmp(winId).getWidth() > Ext.getBody().getWidth() - 40)
//                    Ext.getCmp(winId).setWidth(Ext.getBody().getWidth() - 40);
//                    
//                  if(Ext.getCmp(winId).getHeight() > Ext.getBody().getHeight() - 40)
//                    Ext.getCmp(winId).setHeight(Ext.getBody().getHeight() - 40);
//                    
//                  Ext.getCmp(winId).center();
//                }).defer(200);
              }
            }
          });
          win.show();
        },
        show: function(filetype, url, title) {
          var content = this.prepareContent(filetype, url);
          var winId = 'lightbox'+new Date().getTime();
           
          var win = new Ext.Window({
            id: winId,
            title: title,
            html: content,
            modal: true,
            reziable: false,
            listeners: {
              afterrender: function() {
                (function() {
                  Ext.getCmp(winId).center();
                }).defer(200);
              }
            }
          });
          win.show();
          
        },
        prepareContent: function(filetype, url) {
          switch(filetype)
          {
            case 'jpg':
            case 'gif':
            case 'bmp':
              content = '<div style="padding: 15px;"><img src="'+url+'" /></div>';
              break;
            case 'pdf':
              content = '<div style="padding: 15px;"><iframe height="'+(Ext.getBody().getHeight()-100)+'" width="'+(Ext.getBody().getWidth()-100)+'" src="'+url+'" scrolling="yes" /></div>';
              break;
            default:
              content = '<div style="padding: 15px;">'+content+'</div>';
              break;
          }
          return content;
        },
        init: function() {}
    };
}();

Ext.onReady(Ext.Lightbox.init, Ext.Lightbox);
