/*
 * vdvdg.js SolidFlux Dec 2008
 *
 */
 
/*jfeed*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3.X=a(h){h=3.J({v:D,C:D,u:D},h);k(h.v){$.W({t:\'V\',v:h.v,C:h.C,U:\'4\',u:a(4){d f=j B(4);k(3.T(h.u))h.u(f)}})}};a B(4){k(4)2.K(4)};B.r={t:\'\',l:\'\',c:\'\',b:\'\',g:\'\',K:a(4){k(3(\'8\',4).y==1){2.t=\'x\';d s=j z(4)}H k(3(\'f\',4).y==1){2.t=\'S\';d s=j A(4)}k(s)3.J(2,s)}};a o(){};o.r={c:\'\',b:\'\',g:\'\',i:\'\',n:\'\'};a A(4){2.q(4)};A.r={q:a(4){d 8=3(\'f\',4).9(0);2.l=\'1.0\';2.c=3(8).5(\'c:e\').6();2.b=3(8).5(\'b:e\').p(\'I\');2.g=3(8).5(\'R:e\').6();2.w=3(8).p(\'4:Q\');2.i=3(8).5(\'i:e\').6();2.m=j G();d f=2;3(\'P\',4).F(a(){d 7=j o();7.c=3(2).5(\'c\').9(0).6();7.b=3(2).5(\'b\').9(0).p(\'I\');7.g=3(2).5(\'O\').9(0).6();7.i=3(2).5(\'i\').9(0).6();7.n=3(2).5(\'n\').9(0).6();f.m.E(7)})}};a z(4){2.q(4)};z.r={q:a(4){k(3(\'x\',4).y==0)2.l=\'1.0\';H 2.l=3(\'x\',4).9(0).p(\'l\');d 8=3(\'8\',4).9(0);2.c=3(8).5(\'c:e\').6();2.b=3(8).5(\'b:e\').6();2.g=3(8).5(\'g:e\').6();2.w=3(8).5(\'w:e\').6();2.i=3(8).5(\'N:e\').6();2.m=j G();d f=2;3(\'7\',4).F(a(){d 7=j o();7.c=3(2).5(\'c\').9(0).6();7.b=3(2).5(\'b\').9(0).6();7.g=3(2).5(\'g\').9(0).6();7.i=3(2).5(\'M\').9(0).6();7.n=3(2).5(\'L\').9(0).6();f.m.E(7)})}};',60,60,'||this|jQuery|xml|find|text|item|channel|eq|function|link|title|var|first|feed|description|options|updated|new|if|version|items|id|JFeedItem|attr|_parse|prototype|feedClass|type|success|url|language|rss|length|JRss|JAtom|JFeed|data|null|push|each|Array|else|href|extend|parse|guid|pubDate|lastBuildDate|content|entry|lang|subtitle|atom|isFunction|dataType|GET|ajax|getFeed'.split('|')))

$(document).ready(function(){ 
	$('#latest-news').getRssFeed();
	setTimeout("$('#loading').fadeOut('fast');", 1500);
});


(function($) {
    $.fn.getRssFeed = function() {
        return this.each(function() {   
            $.getRssFeed(this);
        });
    };

    $.getRssFeed = function(container) {
		var loadertje = new Image(16, 16);
		loadertje.src = '/inc/img/loading.gif';
		loadertje.setAttribute('id', 'loading');
		$(container).find('h2').append(loadertje);
		//console.log(container);
		
		setTimeout("$.checkNew($('#latest-news'));", 60000); //60 s
    };
	
	$.checkNew = function(container) {
		$('#loading').fadeIn('fast');
		//console.log('checking new news...');
		$.getFeed({url: 'fd-news-proxy.php',
        success: function(feed) {
            var html = '';
			var newItemArray = [];
			var curItemArray = [];
			$(container).find('a.fin-news-title').each(function (i) {
				curItemArray.push(this.href);
			});
			
			var i = 0;
			var curItem = feed.items[i];
			var firstCurElement = $('#latest-news li:first');
			
			var newElement;
			//alert(curItem.title);
			while($.inArray(curItem.link, curItemArray)==-1&&i<curItemArray.length){
				var updateDate = new Date(curItem.updated);
				var minutes = updateDate.getMinutes();
				if (minutes<10){
					minutes = "0"+minutes;
				}
				var time = updateDate.getHours()+':'+minutes;
				$(container).find('li:last').fadeOut("fast");
				firstCurElement.before('<li style="display: none;"><a href="'+curItem.link+'" class="fin-news-time">'+time+'</a>&nbsp;&nbsp;<a href="'+curItem.link+'" class="fin-news-title">'+curItem.title+'</a></li>');
				$(container).find('li:first').fadeIn();
				//setTimeout("alert($('#latest-news li:last')).length", 1000);
				setTimeout("$('#latest-news li:last').remove()", 2000);
				i++;
				curItem = feed.items[i];
			}
			$('#loading').fadeOut('fast');
			setTimeout("$.checkNew($('#latest-news'));", 60000);
        }    
   		});
	};

})(jQuery);
