/*!
 * Ext JS Library 3.0.0
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
FeedViewer = {};

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

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

    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 menu_felso = new Ext.Panel({

									html			:'<div style="background-color: #C7CCE2;" align="center"><div ><img src="http://www.npk.hu/rss/reader/images/banner.jpg" width="932" height="91" /></div>',
									margins			:'10 15 10 10'
							});


    var viewport = new Ext.Viewport({
        layout:'border',
        items:[
            {
													  region		: 'north'
													  ,height		: 91
													  ,items		: [menu_felso]

												},
            feeds,
            mainPanel
         ]
    });

    // add some default feeds
        feeds.addFeed({
        url:'http://www.npk.hu/rss',
        text: 'Euroguidance Hungary'
    }, false, true);



    feeds.addFeed({
        url:'http://www.edupress.hu/admin/ep_rss20.xml',
        text: 'EDUPRESS'
    }, true);

    feeds.addFeed({
        url:'http://www.tpf.hu/rss.php',
        text: 'TEMPUS Közalapítvány'
    }, true);

    feeds.addFeed({
        url:'http://www.okm.gov.hu/main.php?folderID=1297',
        text: 'OKM'
    }, true);

    feeds.addFeed({
        url:'http://www.mobilitas.hu/rss/',
        text: 'Mobilitas'
    }, true);

    feeds.addFeed({
        url:'http://www.tpf.hu/rss.php',
        text: 'Tempus Közalapítvány'
    }, true);

    feeds.addFeed({
        url:'http://feeds2.feedburner.com/Pszichologia_com-Minden-Cikke',
        text: 'Pszichologia.com'
    }, true);

    feeds.addFeed({
        url:'http://www.u-szeged.hu/hirek-aktualitasok?rss=1',
        text: 'Szegedi Tudományegyetem'
    }, true);

    feeds.addFeed({
        url:'http://www.pte.hu/rss/hirek',
        text: 'Pécsi Tudományegyetem'
    }, true);

    feeds.addFeed({
        url:'http://www.cedefop.europa.eu/etv/news/feed_all.asp',
        text: 'Cedefop News'
    }, true);

    feeds.addFeed({
        url:'http://www.europa-nu.nl/9353000/1/j9vvh6nf08temv0/vhdubxdwqrzw?ctx=vg9pjpilytz0',
        text: 'Educationa and youth policy'
    }, true);

    feeds.addFeed({
        url:'http://www.admin.cam.ac.uk/news/newsfeeds/all.xml',
        text: 'University of Cambridge '
    }, true);

    feeds.addFeed({
        url:'http://www.hrdc.bg/plugins/rss_menu/rss.php?news.2',
        text: 'Euroguidance Bulgaria '
    }, true);

    feeds.addFeed({
        url:'http://www.naep.cz/rss-documents.php',
        text: 'Euroguidance Czech - documents '
    }, true);

    feeds.addFeed({
        url:'http://www.naep.cz/rss-news.php',
        text: 'Euroguidance Czech - news '
    }, true);

    feeds.addFeed({
        url:'http://www.innove.ee/refernet_rss',
        text: 'Euroguidance Estonia '
    }, true);

    feeds.addFeed({
        url:'http://www.innove.ee/refernet_rss',
        text: 'Euroguidance Estonia '
    }, true);

    feeds.addFeed({
        url:'http://ec.europa.eu/eures/RSSFeed?rssType=public&language=de',
        text: 'Eures Deutschland '
    }, true);


    feeds.addFeed({
        url:'http://www.orientation-formation.fr/spip.php?page=backendxiti&xts=257696&xtor=RSS-2',
        text: 'Orientation et formation'
    }, true);

    feeds.addFeed({
        url:'http://www.etudiant.gouv.fr/rid16/toutes-les-actualites.rss',
        text: 'Portail Etudiant'
    }, true);

    feeds.addFeed({
        url:'http://www.cmepius.si/en/rss/rss.aspx',
        text: 'CMEPIUS'
    }, true);

    feeds.addFeed({
        url:'http://eacea.ec.europa.eu/rss/work_eacea_en.xml',
        text: 'EACEA'
    }, true);

    feeds.addFeed({
        url:'http://eit.europa.eu/metanavigation/rss.xml',
        text: 'European Institute of Innovation and Technology'
    }, true);


    feeds.addFeed({
        url:'http://www.eurodesk.eu/edesk/RSS.do',
        text: 'EURODESK'
    }, true);


    feeds.addFeed({
        url:'http://www.eu-student.eu/feed/rss/',
        text: 'EU STUDENT'
    }, 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'
        });
    }
};
