Ext.ns('ieee');
Ext.Ajax.request({
	url: '/ieee/util/ajax-fun.php'
	,method: 'POST'
	,params: {'action': 'get_session_data'}
	,success: function(response) {
		var obj = Ext.decode(response.responseText);
		ieee.uid = obj.results.uid;
	}
});
ieee.tpl = new Ext.XTemplate(
	'<tpl for="results">',
	'<a href="/ieee/news_detail.php?id={id}" style="text-decoration:none;"><h5> {[ieee.util.stripSlashes(values.headline)]}</h5></a>',
	'<div class="blog-entry-container">',
	'<p class="blog-entry">',
	'{[ieee.util.stripSlashes(values.content)]}',
	'</p>',
	'<div><a style="padding-left: 1em;" href="/ieee/news_detail.php?id={id}">Read more... ' +
	'(<a href="/ieee/news_detail.php?id={id}#comments">{comment_cnt} comment<tpl if="comment_cnt != 1">s</tpl></a>)</a></div>',
	'<div class="posted-by">Posted by <a href="/ieee/user-profile.php?uid={posterId}">{posterName}</a> on {date_of_event}<tpl if="posterId == ieee.uid"><span class="deleter" id="{id}">(Delete this item)</span></tpl></div>',
	'</div>',
	'</tpl>',
	{
		//XTemplate configuration:
		compiled: true
		,plural: function(str) {
			return (str.length > 1);
		}
	}
);

ieee.newsStore = new Ext.data.JsonStore({
	url: '/ieee/index-data.php'
	,id: 'newsStore'
	,root: 'results'
	,fields: ['headline', 'content', 'id', 'date_of_event', 'posterId', 'posterName', 'comment_cnt']
});


Ext.onReady(function () {
	Ext.BLANK_IMAGE_URL = '/ieee/resources/javascript/ext-3.0-rc1.1/resources/images/default/s.gif';
	Ext.QuickTips.init();
	ieee.util.stripSlashesOf('body'); //strip all slashes out of body...
	ieee.tpl.compile();
	ieee.newsStore.on('load', function () {
			ieee.tpl.overwrite('news-container', ieee.newsStore.reader.jsonData);
	});
	ieee.newsStore.load();
});
