/*
 * rssnews.js
 *
 * Copyright (c) 2007 UiD Team
 * All Rights Reserved
 *
 */
(function($){$.fn.rssNews=function(options){if(typeof options=='object'){var containers=this;var options=$.extend($.fn.rssNews.defaults,options);var items=[];$.get(options.feed,function(xml){$('item',xml).each(function(){var data=$(this);var item={link:$('link',data).text(),title:$('title',data).text(),description:$('description',data).text()};if(options.filters.url.pattern!=null){item.link=item.link.replace(options.filters.url.pattern,options.filters.url.replacement);}if(options.filters.content.pattern!=null){item.title=item.title.replace(options.filters.content.pattern,options.filters.content.replacement);item.description=item.description.replace(options.filters.content.pattern,options.filters.content.replacement);}items.push(item);});if(options.title.selector!=null){$(options.title.selector).text($.fn.rssNews.abbreviate(options.title.prefix+' '+$('channel > title',xml).text(),20)).attr('title',$('channel > description',xml).text());}containers.each(function(i,e){var that=this;if(typeof that.timer=='undefined'){that.timer=null;that.container=$(e);that.nextIndex=0;that.paused=false;that.next=function(){if(items.length>0){that.entries.dequeue().hide();var template=$.fn.rssNews.templates[options.template];var content='';var offset=that.nextIndex;var limit=Math.min(items.length,that.nextIndex+template.items);for(var i=offset;i<limit;++i){var temp=template.html;for(var key in items[i]){var value=items[i][key];if(key=='title'&&template.lengths.title>-1){value=$.fn.rssNews.abbreviate(value,template.lengths.title);}if(key=='description'&&template.lengths.description>-1){value=$.fn.rssNews.abbreviate(value,template.lengths.description);}temp=temp.replace('$'+key,value);}content+=temp;that.nextIndex=(i+1)%items.length;}that.entries.html(content).dequeue().show();if(!that.paused){that.timer=setTimeout(that.next,options.delay);}}};that.container.html('<div id="rssnews_entries"></div><div id="rssnews_stop">- Leállítva -</div>').hover(function(){if(typeof that.timer!='undefined'){that.paused=true;clearTimeout(that.timer);}$('#rssnews_stop').show();},function(){$('#rssnews_stop').hide();that.paused=false;that.next();});that.entries=$('#rssnews_entries',that.container);that.next();}});});return this;}else if(typeof options=='string'&&options=='destroy'){return this.each(function(){var that=this;if(typeof that.timer!='undefined'){that.paused=true;clearTimeout(that.timer);that.container.unbind();delete that.timer;delete that.container;delete that.entries;$('#rssnews_entries, #rssnews_stop',that).remove();}});}};$.fn.rssNews.defaults={template:'article',delay:20000,feed:'rssnews.xml',filters:{url:{pattern:null,replacement:null},content:{pattern:null,replacement:null}},title:{selector:null,prefix:'RSS: '}};$.fn.rssNews.templates={'list':{items:5,lengths:{title:55,description:-1},html:'<div class="rssnews_title list"><a href="$link" target="_blank">$title</a></div>'},'article':{items:1,lengths:{title:-1,description:250},html:'<div class="rssnews_title article"><a href="$link" target="_blank">$title</a></div><div class="rssnews_description article">$description</div>'}};$.fn.rssNews.abbreviate=function(string,limit,postfix,wordAware){var pf=typeof postfix=='string'?postfix:'...';var wa=typeof wordAware=='boolean'?wordAware:true;if(string.length<=limit){return string;}else{var abbreviated=string.substr(0,limit+1);if(wa){abbreviated=abbreviated.substr(0,abbreviated.lastIndexOf(' '));}return abbreviated+pf;}};})(jQuery);