/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
FeedViewer = {};

Ext.onReady(function(){
    Ext.QuickTips.init();

    //Ext.state.Manager.setProvider(new Ext.state.SessionProvider({state: Ext.appState}));
	Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    var tpl = Ext.Template.from('preview-tpl', {
        compiled:true,
        getBody : function(v, all){
            return Ext.util.Format.stripScripts(v || all.description);
        }
    });
    FeedViewer.getTemplate = function(){
        return tpl;
    }

    var feeds = new FeedPanel();
    var mainPanel = new MainPanel();

    feeds.on('feedselect', function(feed){
        mainPanel.loadFeed(feed);
    });
    
    var viewport = new Ext.Viewport({
        layout:'border',
        items:[
            new Ext.BoxComponent({ // raw element
                region:'north',
                el: 'header',
                height:32
            }),
            feeds,
            mainPanel
         ]
    });

    // add some default feeds
	feeds.addFeed({
		url:'http://moriwaki.net/cms/?feed=rss2',
		text: 'MORIWAKI.NETのメモ帳'
	}, false, true);

	feeds.addFeed({
		url:'http://hanshin-now.com/blog/rss/train-bus.xml',
		text: '阪神電車とバスで神出鬼没'
	}, true);

	feeds.addFeed({
		url:'http://mt22.cocolog-nifty.com/mt/index.rdf',
		text: 'くまなブログ'
	}, true);

	feeds.addFeed({
		url:'http://rilakkuma.jpn.org/?feed=rss2',
		text: 'Rilakkuma.JPN'
	}, true);

	feeds.addFeed({
		url:'http://blog.livedoor.jp/dqnplus/index.rdf',
		text: '痛いニュース(ﾉ∀`)'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/news4vip.livedoor.biz/index.rdf',
		text: '【2ch】ニュー速クオリティ'
	}, true);

	feeds.addFeed({
		url:'http://alfalfalfa.com/index.rdf',
		text: 'アルファルファモザイク'
	}, true);

	feeds.addFeed({
		url:'http://api.bing.com/rss.aspx?Source=News&Market=ja-JP&Version=2.0&Query=java',
		text: 'Bing News - Java'
	}, true);

	feeds.addFeed({
		url:'http://api.bing.com/rss.aspx?Source=News&Market=ja-JP&Version=2.0&Query=ajax',
		text: 'Bing News - Ajax'
	}, true);

	feeds.addFeed({
		url:'http://api.bing.com/rss.aspx?Source=News&Market=ja-JP&Version=2.0&Query=android',
		text: 'Bing News - Android'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.com/ajaxian',
		text: 'Ajaxian'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.com/EclipseMarketplace',
		text: 'Eclipse Marketplace'
	}, true);

	feeds.addFeed({
		url:'http://techblog.yahoo.co.jp/index.xml',
		text: 'Yahoo! JAPAN Tech Blog'
	}, true);

	feeds.addFeed({
		url:'http://blogs.technet.com/jpieblog/rss.xml',
		text: 'Japan IE Support Team Blog'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/rss.rssad.jp/rss/impresswatch/pcwatch.rdf',
		text: 'PC Watch'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/rss.rssad.jp/rss/k-taiwatch/k-tai.rdf',
		text: 'ケータイ Watch'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/rss.rssad.jp/rss/internetwatch/internet.rdf',
		text: 'INTERNET Watch'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/rss.rssad.jp/rss/forest/rss.xml',
		text: '窓の杜'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/minkei/kobe.xml',
		text: '神戸経済新聞'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/minkei/umeda.xml',
		text: '梅田経済新聞'
	}, true);

	feeds.addFeed({
		url:'http://akiba.keizai.biz/rss.xml',
		text: 'アキバ経済新聞'
	}, true);

	feeds.addFeed({
		url:'http://journal.mycom.co.jp/haishin/rss/index.rdf',
		text: 'マイコミジャーナル'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/feed.rssad.jp/rss/jcast/mono/index.xml',
		text: 'J-CASTモノウォッチ'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/feed.rssad.jp/rss/gigazine/rss_2.0',
		text: 'GIGAZINE'
	}, true);

	feeds.addFeed({
		url:'http://feeds.lifehacker.jp/rss/lifehacker/index.xml',
		text: 'ライフハッカー［日本版］'
	}, true);

	feeds.addFeed({
		url:'http://itlifehack.jp/index.rdf',
		text: 'ITライフハック'
	}, true);

	feeds.addFeed({
		url:'http://feeds.gizmodo.jp/rss/gizmodo/index.xml',
		text: 'ギズモード・ジャパン'
	}, true);

	feeds.addFeed({
		url:'http://20kaido.com/index.rdf',
		text: '二十歳街道まっしぐら'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/codezine/new/20/index.xml',
		text: 'CodeZine：新着記事'
	}, true);

	feeds.addFeed({
		url:'http://itpro.nikkeibp.co.jp/rss/ITpro.rdf',
		text: 'ITpro総合'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/itmtop/2.0/itmedia_all.xml',
		text: 'ITmedia TOP STORIES'
	}, true);

	feeds.addFeed({
		url:'http://www.ibm.com/developerworks/jp/rss/dw_dwjp.xml',
		text: 'IBM developerWorks Japan'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/rss.rssad.jp/rss/itmatmarkit/rss.xml',
		text: '＠IT'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/gihyo/feed/rss1',
		text: 'gihyo.jp：総合'
	}, true);

	feeds.addFeed({
		url:'http://image.gihyo.co.jp/assets/f/orange_rss2.rss',
		text: '濃縮還元オレンジニュース'
	}, true);

	feeds.addFeed({
		url:'http://feeds.japan.cnet.com/cnet/rss',
		text: 'CNET Japan'
	}, true);

	feeds.addFeed({
		url:'http://feeds.reuters.com/reuters/JPTopNews',
		text: 'Reuters: トップニュース'
	}, true);

	feeds.addFeed({
		url:'http://rss.rssad.jp/rss/sankeibiz/flash',
		text: '経済ニュース速報 - SankeiBiz'
	}, true);

	feeds.addFeed({
		url:'http://money.jp.msn.com/rss/stock.aspx',
		text: 'MSN 株式市場ニュース'
	}, true);

	feeds.addFeed({
		url:'http://www.tdb.co.jp/rss/jouhou.rdf',
		text: '帝国データバンク 大型倒産速報'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.com/tb-hotentry',
		text: 'TweetBuzz - 注目エントリー'
	}, true);

	feeds.addFeed({
		url:'http://blog.twitter.jp/feeds/posts/default?alt=rss',
		text: 'Twitterブログ'
	}, true);

	feeds.addFeed({
		url:'http://twinavi.jp/posts.rss',
		text: 'twinavi 新着情報'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.jp/hitokuchi_6200',
		text: '大阪府の天気予報'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.jp/hitokuchi_6310',
		text: '兵庫県南部の天気予報'
	}, true);

	feeds.addFeed({
		url:'http://weather.jp.msn.com/RSS.aspx?wealocations=wc:JAXX0003&weadegreetype=C&culture=ja-JP',
		text: '兵庫県 尼崎市 - MSN 天気予報'
	}, true);

	feeds.addFeed({
		url:'http://rss.weather.com/weather/rss/local/JAXX0003?cm_ven=LWO&cm_cat=rss&par=LWO_rss',
		text: 'LWO--Amagasaki'
	}, true);

	feeds.addFeed({
		url:'http://feeds.feedburner.com/extblog',
		text: 'Ext JS Blog'
	}, true);

	feeds.addFeed({
		url:'http://d.hatena.ne.jp/higayasuo/rss2',
		text: 'ひがやすを blog'
	}, true);

	feeds.addFeed({
		url:'http://d.hatena.ne.jp/cypher256/rss2',
		text: 'C/pHeR Memo - Java とか。Eclipse とか。'
	}, true);

	feeds.addFeed({
		url:'http://d.hatena.ne.jp/wyukawa/rss2',
		text: 'watawata日記'
	}, true);

	feeds.addFeed({
		url:'http://d.hatena.ne.jp/takezoe/rss2',
		text: '新・たけぞう瀕死の日記'
	}, true);

	feeds.addFeed({
		url:'http://www.ideaxidea.com/feed',
		text: 'IDEA*IDEA'
	}, true);

	feeds.addFeed({
		url:'http://mrss.dokoda.jp/a/http/feeds.feedburner.jp/coliss',
		text: 'コリス'
	}, true);

	feeds.addFeed({
		url:'http://blog.san-x.co.jp/rilakkuma/index.xml',
		text: 'リラックマごゆるりブログ'
	}, true);

	feeds.addFeed({
		url:'http://blog.san-x.co.jp/rilakkuma-store/index.xml',
		text: 'リラックマストア'
	}, true);

	feeds.addFeed({
		url:'http://blog.san-x.co.jp/toretate/index.xml',
		text: 'とれたて！情報局　ハイパー'
	}, true);

	feeds.addFeed({
		url:'http://www.san-x.co.jp/index.rdf',
		text: 'サンエックスネット'
	}, true);

	feeds.addFeed({
		url:'http://api.bing.com/rss.aspx?Source=News&Market=ja-JP&Version=2.0&Query=%E3%83%AA%E3%83%A9%E3%83%83%E3%82%AF%E3%83%9E',
		text: 'Bing News - リラックマ'
	}, true);

    Ext.get('header').on('click', function() {
        viewport.focus();
    });
    
    feeds.focus();
});

// This is a custom event handler passed to preview panels so link open in a new windw
FeedViewer.LinkInterceptor = {
    render: function(p){
        p.body.on({
            'mousedown': function(e, t){ // try to intercept the easy way
                t.target = '_blank';
            },
            'click': function(e, t){ // if they tab + enter a link, need to do it old fashioned way
                if(String(t.target).toLowerCase() != '_blank'){
                    e.stopEvent();
                    window.open(t.href);
                }
            },
            delegate:'a'
        });
    }
};
