/**
 * @author Aaron Static
 */
Ext.namespace('AaronStatic');

AaronStatic.NewsFeed = Ext.extend(Ext.PanelView,{
	frame: true,	
	id: 'twitter',
	bodyCssClass: 'twitter-body',
	defaults: {
		baseCls: 'x-bubble',
		frame: true		
	},
	iconCls: 'icon-twitter-big',
	autoScroll: true,
	title: ' ',	
	initComponent: function(){
		var tpl = new Ext.XTemplate(
			'<tpl>',				
				'<div class="news-wrap tweet" style="background-image:url(\'{avatar}\')">',
					'<div class="title">{text}</div>',
					'<div class="time">{author} about {[AaronStatic.calcAgo(values.unixtime)]} from {source}</div>',
				'</div>',
			'</tpl>'				
		);
		
		var store = new Ext.data.JsonStore({		    
		    root: 'news',
			url: 'get-twitter.php',
			autoLoad: true,
		    fields: [
		        'text', 'author', 'url', 'source', 'unixtime', 'avatar'
		    ]
		});	
	
		Ext.apply(this,{
			store: store,
			tpl: tpl			
		});
		this.on('beforeaddpanel',function(panel,row){
			var url = row.get('url');			
			panel.on('render',function(){
				panel.el.on('mouseenter',function(){
					panel.el.addClass('tweet-over');
				});
				panel.el.on('mouseleave',function(){
					panel.el.removeClass('tweet-over');
				});
			});			
		});
		
		AaronStatic.NewsFeed.superclass.initComponent.call(this, arguments);		
	}
});

