// store

// soluciona el problema de no cargarse si llamamos a ziving.con sin la www
var noticiasAtom = 'ziving.com/news/?feed=rss2';
if ( location.host == 'www.ziving.com'){
	noticiasAtom = 'www.ziving.com/news/?feed=rss2';
}

var proxyFeeds = new Ext.data.HttpProxy({
	//url		: 'http://www.sonrie.com/temp/my_feed.php?feed=http://www.ziving.com/news/?feed=rss2'
	//url		: 'http://www.ziving.com/news/?feed=rss2'
	url			: 'http://'+location.host+'/zfeeds/my_feed.php?intro=www.ziving.com/news/?feed=rss2'
});
//console.log(proxyFeeds);

var storeFeeds = new Ext.data.XmlStore({
	storeId		: 'storeFeeds',
	proxy		: proxyFeeds,
	// those are for rss readers:
	fields		: ['title','pubDate','description',{name: 'content', mapping:'content'},'link','imagen'],
	record		: 'item',
	//
	listeners	: {
		load	: function(store, records, options){
			//storeFeeds.each( function(record){
			//	var imagen = new String(record.data.content).match(/src=(.+?[\.jpg|\.gif]")/)[1];
			//	record.data.imagen = (imagen.replace("\"","")).replace("\"","");
			//	//console.log(record.data);
			//});
			//Ext.getCmp('viewp').render('myPanel');
		}
	}
});
//console.log(storeFeeds);


// fields
// in the reader

var formatDate = function(adate){
	//console.log(adate);
	return adate;
};

var tpl = new Ext.XTemplate(
	'<tpl for=".">',
		'<div class="noticia">',
			'<div class="imagen">',
				'<img src="{imagen}">',
			'</div>',
			'<span class="titulo">{shortName}</span>',
		'</div>',
	'</tpl>',
	'<div class="x-clear"></div>'
);


var gridfeeds = new Ext.DataView({
	id			: 'gridfeeds',
	store		: storeFeeds,
	tpl			: tpl,
	singleSelect: true,
	overClass 	:'imagen-over',
	itemSelector: 'div.noticia',
	autoHeight	:true,
	listeners: {
		click : function( dv, index, node, e ){
			//console.log(Ext.StoreMgr.get('storeFeeds').data.items[index].data.link);
			var url = Ext.StoreMgr.get('storeFeeds').data.items[index].data.link;
			var wname = 'Ziving, es ortodoncia';
			var wfeatures = 'menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=yes';
			newwin = window.open(url,wname,wfeatures);
		}
	},
	prepareData: function(data){
		data.shortName = Ext.util.Format.ellipsis(data.title, 25);
		var imagen = new String(data.content).match(/src=(.+?[\.jpg|\.gif]")/)[1];
		data.imagen = (imagen.replace("\"","")).replace("\"","");
		return data;
	},
	
});

/**
		 * Converts a Novell GMT date/time string to a local Date object
		 * @param zStr - GMT datetime as YYYYMMDDHHmmSSZ 
		 * @return local Date object
		 */
		function toLocalDate(zStr) {
		//2010-05-21T12:51:49Z
			var year = zStr.substring(0,4);
			var month = zStr.substring(5,7);
			var date = zStr.substring(8,10);
			//console.log(date);
			//var hour = zStr.substring(11,2);
			//var min = zStr.substring(14,2);
			//var sec = zStr.substring(17,18);
			// convert to date
			//var gmt = new Date(year, month-1, date, hour, min, sec);
			// get offset for local timezone in minutes
			//var offset = (new Date()).getTimezoneOffset();
			// get the local date
			//return new Date(gmt.getTime() + offset * 60000).toDateString();
			return date + "/" + month + "/" + year;
		}
