/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://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 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:'mahaleyat',
        text: 'محليات سياسية'
    }, false, true);

    feeds.addFeed({
        url:'international',
        text: 'عربيا ودوليا'
    }, true);

    feeds.addFeed({
        url:'sport',
        text: 'رياضة'
    }, true);
	
	feeds.addFeed({
        url:'moutafarrikat',
        text: '&#1605;&#1578;&#1601;&#1585;&#1602;&#1575;&#1578;'
    }, true);
	
	feeds.addFeed({
        url:'phono',
        text: '&#1575;&#1578;&#1589;&#1575;&#1604; &#1593;&#1604;&#1609; &#1575;&#1604;&#1587;&#1585;&#1610;&#1593;'
    }, true);
	
	feeds.addFeed({
        url:'khas',
        text: '&#1582;&#1575;&#1589; &#1605;&#1608;&#1602;&#1593; &#1575;&#1604;&#1602;&#1608;&#1575;&#1578;'
    }, true);
	
	feeds.addFeed({
        url:'solta4',
        text: '&#1575;&#1604;&#1587;&#1604;&#1591;&#1577; &#1575;&#1604;&#1585;&#1575;&#1576;&#1593;&#1577;'
    }, true);
	
	feeds.addFeed({
        url:'pres-secret',
        text: '&#1605;&#1606; &#1571;&#1587;&#1585;&#1575;&#1585; &#1575;&#1604;&#1589;&#1581;&#1601;'
    }, true);
	
	
	feeds.addFeed({
        url:'fi-siyasa',
        text: '&#1601;&#1610; &#1575;&#1604;&#1587;&#1610;&#1575;&#1587;&#1577;'
    }, true);
	
	feeds.addFeed({
        url:'hakim-pressandint',
        text: '&#1578;&#1589;&#1585;&#1610;&#1581;&#1575;&#1578; &#1583;.&#1580;&#1593;&#1580;&#1593;'
    }, true);
	
	feeds.addFeed({
        url:'economy',
        text: '&#1575;&#1602;&#1578;&#1589;&#1575;&#1583;'
    }, true);
	
	feeds.addFeed({
        url:'upcoming',
        text: '&#1593;&#1604;&#1609; &#1575;&#1604;&#1591;&#1585;&#1610;&#1602;'
    }, true);
	
	feeds.addFeed({
        url:'tahkikat',
        text: '&#1578;&#1581;&#1602;&#1610;&#1602;&#1575;&#1578;'
    }, true);
	
	feeds.addFeed({
        url:'interviews',
        text: '&#1605;&#1602;&#1575;&#1576;&#1604;&#1575;&#1578;'
    }, true);
	
	feeds.addFeed({
        url:'articles',
        text: '&#1605;&#1602;&#1575;&#1604;&#1575;&#1578; &#1605;&#1606; &#1575;&#1604;&#1602;&#1585;&#1575;&#1569;'
    }, true);
});

// 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'
        });
    }
};
