var GE_FeedDropDown = Class.create( GE_DropDown, {
	directory:null,
	initialize:function($super, el) {
		$super(el);
		this.titleEl.update('<a href="#">XML</a>');
		this.titleEl.firstDescendant().observe("focus", function() { this.toggleSelect(); }.bind(this));
		this.directory = $$('.directory,.newsfeed_list')[0];
		this.filter('xml');
		this.items.each(
			function(el) {
				var a = el.down('a');
				a.observe('click',function(e){
					e.stop();
					this.o.titleEl.update("<a href=\"#\">" + this.a.innerHTML + "</a>");
					this.o.titleEl.firstDescendant().observe("focus", function() { this.s.toggleSelect(); }.bind({s:this.o}));
					this.o.filter(this.a.title);
					this.o.toggleSelect();
				}.bind({o:this,a:a}));
			}.bind(this)
		);
	},
	filter:function(c) {
		this.directory.descendants().each(function(el){
			if (el.tagName=='A')
				{
					el.show();
					if (el.getStyle('margin-left')!='0px') {
						if (el.hasClassName('google')) el.setStyle({marginLeft: '315px'});
						if (el.hasClassName('my_yahoo')) el.setStyle({marginLeft: '390px'});
						if (el.hasClassName('bloglines') || el.hasClassName('itunes')) el.setStyle({marginLeft: '478px'});
					}
				}
		});
		this.directory.descendants().each(function(el){
			if (el.tagName=='A')
				{
				if (!(el.hasClassName(c) || c=='All')) {
					el.hide();
					}
				else
					{
						if (c!='All'){
						if (el.getStyle('margin-left')!='0px') el.setStyle({marginLeft: '223px'});
						}
					}
				}
		});
	}
});

var GE_getNewsFeedsList = function() {
	var list = new Element('ul').addClassName('dropdown_list');
	list.insert( new Element('li').addClassName('dropdown_item').insert( new Element('a',{href:'#', title:'xml'}).addClassName('rss_link xml').insert('XML') ) );
	if ($$('.google').length>0) list.insert( new Element('li').addClassName('dropdown_item').insert( new Element('a',{href:'#', title:'google'}).addClassName('rss_link google').insert('Google') ) );
	if ($$('.my_yahoo').length>0) list.insert( new Element('li').addClassName('dropdown_item').insert( new Element('a',{href:'#', title:'my_yahoo'}).addClassName('rss_link my_yahoo').insert('MyYahoo!') ) );
	if ($$('.bloglines').length>0) list.insert( new Element('li').addClassName('dropdown_item').insert( new Element('a',{href:'#', title:'bloglines'}).addClassName('rss_link bloglines').insert('Bloglines') ) );
	if ($$('.itunes').length>0) list.insert( new Element('li').addClassName('dropdown_item').insert( new Element('a',{href:'#', title:'itunes'}).addClassName('rss_link itunes').insert('Itunes') ) );
	
	var el = new Element('div').addClassName('abstract_list')
		.insert( new Element('div').addClassName('abstract_item')
			.insert( new Element('h3').addClassName('item_title').insert('Select a subscription service:') )
			.insert( list ));
	return el;
}

GE_Main.mapCSSToFn('directory',function(el){
	var list = GE_getNewsFeedsList();
	$(el).insert({before:list});
	new GE_FeedDropDown(list.down('.dropdown_list'));
});
GE_Main.mapCSSToFn('investor_newsfeeds',function(el){
	var list = GE_getNewsFeedsList();
	$(el).down('.newsfeed_list').insert({before:list});
	new GE_FeedDropDown(list.down('.dropdown_list'));
});
