/* encoding: utf-8

  ****  linkify plugin for jQuery - automatically finds and changes URLs in text content into proper hyperlinks  ****

  Version: 1.0

  Copyright (c) 2009
    Már Örlygsson  (http://mar.anomy.net/) &
    Hugsmiðjan ehf. (http://www.hugsmidjan.is)

  Dual licensed under a MIT licence (http://en.wikipedia.org/wiki/MIT_License)
  and GPL 2.0 or above (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).

*/

(function($){

  var url1 = /(^|"|&lt;|\s)(www\..+?\..+?)(\s|&gt;|"|$)/g,
      url2 = /(^|"|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|"|$)/g;

  $.fn.linkify = function () {
    return this.each(function () {
      var childNodes = this.childNodes,
          i = childNodes.length;
      while(i--)
      {
        var n = childNodes[i];
        if (n.nodeType == 3) {
          var html = n.nodeValue;
          if (/\S/.test(html))
          {
            html = html.replace(/&/g, '&amp;')
                       .replace(/</g, '&lt;')
                       .replace(/>/g, '&gt;')
                       .replace(url1, '$1<a href="<``>://$2" target="_blank">$2</a>$3' )
                       .replace(url2, '$1<a href="$2" target="_blank">$2</a>$5')
                       .replace(/"<``>/g, '"http');
            $(n).after(html).remove();
          }
        }
        else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) {
          arguments.callee.call(n);
        }
      };
    });
  };

})(jQuery);
 $(function(){
      jQuery('#Social div').linkify().find('a').text('... View link');
    });

google.load("feeds", "1") //Load Google Ajax Feed API (version 1)

function rssdisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}

rssdisplayer.prototype.formatdate=function(datestr){
var itemdate=new Date(datestr)
return "<span class='Date'>"+itemdate.toLocaleString()+"</span>"
}

rssdisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput=""
for (var i=0; i<thefeeds.length; i++){ //loop through entries


//var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""
//var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""

var itemtitle = thefeeds[i].content 





var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""

//var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""


rssoutput+="<div>" + itemtitle +  " <br /> " + itemdate  + " </div>"

}
rssoutput+="</ul>"



//console.log(rssoutput);
this.feedcontainer.innerHTML=rssoutput


$('#Social div').find('a').text('... View link');

}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}
function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}



//what beautiful weather! If you're planning to head out for a picnic, why not make some delicious gluten free flatbread? http://www.glutafin.co.uk/Recipes/default.aspx?keywords=&timeToMake=&recipeType=&mealType=&occasion=&product=&recipeID=0c09fadf-c0ab-426a-b120-7096065d71f0
