
var mostPopularWin = null;

var showMostPopular = function(){
	if(mostPopularWin){
		mostPopularWin.close();
		mostPopularWin.destroy();
	}

    var callback = function(records){
        var headerNC = new Ext.Panel({
            autoLoad:{url: 'statistics.spr', params: 'linkName=mostPopularHeader'},
            cls:'w-header-panel',
            border: false,
            header: false,
            height: 65
        });

        var gridNC = new Ext.ux.clv2.NewContentGrid({id:'gridNC', ds:this});
        var onRowClick = function(gridLO,rowIndex, event){
            var record = gridLO.getStore().getAt(rowIndex); // Get the Record
            var IframePanel = Ext.getCmp('snapshot-topLo-content').findById('content-preview-iframe');
            IframePanel.setSrc('content.spr?'+Ext.urlEncode({ "learningObjectId" : record.id}), false, Ext.emptyFn());
        }

        gridNC.addListener('rowClick', onRowClick);
        var titleLO = new Ext.Panel({
            id:'snapshot-topLo-title',
            cls:'snapshot-lo-title',
            border: false,
            header: false,
            height: 35,
            html: 'Preview: ' +  records[0].data.title
        });

           var contentLO = new Ext.Panel({
            id:'snapshot-topLo-content',
            cls:'snapshot-lo-content',
            border: false,
            header: false,
            height: !Ext.isIE6 ? 334 : 337,
            width:664,
            items: {
                       id:'content-preview-iframe',
                       xtype : 'iframepanel',
                       defaultSrc : 'content.spr?'+Ext.urlEncode({ "learningObjectId" : records[0].id}),
                       height: !Ext.isIE6 ? 334 : 337,
                       width:658
                    }           
        });

        //var IframePanel = contentLO.findById('content-preview-iframe');        
        
        mostPopularWin = new Ext.ux.clv2.NewContentWindow({
            id:'new-content-window',
            cls:'clv2-window',
            items: [headerNC, gridNC, titleLO, {
                cls:'snapshot-content-container',
                items: [contentLO]
            }],
            //resizable:false,
            height:637,
            width: 681
        });
        var relativePos = findPos(document.getElementById('loginPanel'));
        mostPopularWin.setPosition(relativePos[0]+316,relativePos[1]);
        mostPopularWin.setElements(headerNC, gridNC, titleLO, contentLO);
        mostPopularWin.setObjects({'header':headerNC, 'grid':gridNC, 'title':titleLO, 'content':contentLO});
        mostPopularWin.on("beforeshow", mostPopularWin.beforeShowWindow, mostPopularWin);
        mostPopularWin.on("show", mostPopularWin.afterShowWindow, mostPopularWin);
        if(Ext.isIE) mostPopularWin.show();
        else mostPopularWin.show(this);
        mostPopularWin.addTitleBarItems({title:'Most Popular',close:'close window'});
    }

    var dsNC =  new Ext.ux.clv2.NewContentStore({});
	dsNC.load({params: {id:'1',mode:3,folderName:'general.folder.topRatedLos',statistic:true}, callback:callback});

}