(function($){$.fn.feedreader=function(options){var defaults={targeturl:'',artCurrent:null};if(!options.targeturl) return false;var opts=$.extend(defaults, options);var scrollpage=function(box_height){var elem=$("#anchorUpNext");var offset=elem.offset();var top_ban=Math.round(offset.top);$('#btnUpNext').click(function(){$('#upNext').remove();});$(window).bind("scroll",{box_height:box_height, top_ban:top_ban}, _scroll);};var _is_iPad=(navigator.userAgent.indexOf("iPad") > -1);var _scroll=function(e){var cssval={};var top_scroll=$(window).scrollTop();if(_is_iPad){hwin=$(window).height();var delta=(2*e.data.box_height)+112;toppos=top_scroll+hwin-delta;cssval={"top":toppos + "px", "position":"absolute"};} else cssval={"bottom":"0px"};if(top_scroll>(e.data.top_ban/2)){$('#upNext').css({'right':'0px'});if(!_is_iPad) $('#upNext').css("min-height", "0").slideDown('slow');$('#upNext').css(cssval);if(_is_iPad) $('#upNext').height(e.data.box_height);}else if(!_is_iPad) $('#upNext').slideUp('slow').css(cssval);};$(this).each(function(){var container=this;$.get(opts.targeturl,function(xml){var count=1;var found=false;num_item=$(xml).find("item").length;channel_title=$("channel > title:first-child", xml).text();$("item", xml).each(function(i,item){str=jQuery.trim($(item).find("link").text());str=str.split('/');var newStr="";for(var c=3; c<str.length; c++){newStr += "/";newStr += str[c];}if (newStr==opts.artCurrent){position_item=i + 1;position_item_next=i + 2;if (i==num_item -1){title_item=$(xml).find("item:first title").text();link_item=$(xml).find("item:first link").text();position_item_next=1;}else{var next=i + 1;title_item=$(xml).find("item:eq("+ next +") title").text();link_item=$(xml).find("item:eq("+ next +") link").text();}found=true;return false;}});if (!found ){title_item=$(xml).find("item:first title").text();link_item=$(xml).find("item:first link").text();position_item_next=1;}format(container);var box_height=$("#upNext").outerHeight();scrollpage(box_height);});});};function format(container)   {$(container).empty();var html='<h6>' + channel_title + '<span> (' + position_item_next + ' di ' +  num_item +  ' articoli)</span></h6>';html += '<h3><a href="' + link_item + '">' + title_item + '</a><br /></h3>';html += '<h6><a href="' + link_item + '">Continua a leggere »</a></<h6>';$(container).html(html);}})(jQuery);
