function createImgLink(itm){
    var listitem = document.createElement('span');
    listitem.className = 'flickritem';

    var anchor = document.createElement('a');
    anchor.setAttribute('href', itm.link);
    anchor.className = 'flickra';

    var image = document.createElement('img');
    tmp=itm.media.m
    tmp=tmp.replace(/_m\.jpg/g,'_s.jpg');
    image.setAttribute('src', tmp);
    image.setAttribute('title', itm.title);
    image.setAttribute('alt', 'Photograph of ' + itm.title);
    image.setAttribute('width', 75);
    image.setAttribute('height', 75);
    image.className = 'flickrphoto';

    anchor.appendChild(image);
    listitem.appendChild(anchor);
    document.getElementById('FlickrPics').appendChild(listitem);
}

function jsonFlickrFeed(feed){
  count=8;
  if (feed.items.length < count) {
          count=feed.items.length
  }
  document.getElementById('FlickrPics').setAttribute('style','border: 10px solid black; width: 340px;');
  for (x=0; x<count; x++) {
    createImgLink(feed.items[x]);
  }
}

function fb(o) {
  if (!target) return;
  for (var i=0; i<o.feed.items.length && i<max_items; i++) {
    var item = o.feed.items[i];
    var li = document.createElement('li');
    var a = document.createElement('a');
    if (!item.title) item.title = item.date;
    if (filter) item.title = filter(item.title)
    a.appendChild(document.createTextNode(item.title));
    a.setAttribute('href', item.link);
    a.setAttribute('hdate', item.date);
    li.appendChild(a);
    //if (item.body) {
	//var p = document.createElement('p');
	//var truncated=item.body;
	//if (truncated.length > 50){
		//truncated = truncated.substring(0, max_del_desc_len);
		//truncated = truncated.replace(/\w+$/, '');
		//truncated = truncated + '...';
	//}
	//p.innerHTML=(truncated);
	//li.appendChild(p);
    //}
    target.appendChild(li);
  }
}
//These are commented out so I don't hammer Flickr while testing
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://api.flickr.com/services/feeds/photos_public.gne?id=56511085@N00&format=json';
headID.appendChild(newScript);

var max_items = 3;
var target = null;
var filter = null;
function showImage(img){ return (function(){ img.style.display='inline'; }) }

var max_del_desc_len=40;
var ul = document.createElement('ul')
for (var i=0, post; post = Delicious.posts[i]; i++) {
    var li = document.createElement('li')
    li.className="delicious_link"
    var a = document.createElement('a')
    //these are temporarily commented out
    //a.style.marginLeft = '20px'
    //var img = document.createElement('img')
    //img.style.position = 'absolute'
    //img.style.display = 'none'
    //img.height = img.width = 16
    //img.src = post.u.split('/').splice(0,3).join('/')+'/favicon.ico'
    //img.onload = showImage(img);
    a.setAttribute('href', post.u)
    
    var truncated=post.d
    if (truncated.length > max_del_desc_len){
    	truncated = truncated.substring(0, max_del_desc_len);
    	truncated = truncated.replace(/\w+$/, '');	
    	truncated = truncated + '...';
    }
    a.appendChild(document.createTextNode(truncated))
    //a.appendChild(document.createTextNode(post.d))
    //li.appendChild(img)
    li.appendChild(a)
    ul.appendChild(li)
}
document.getElementById('DeliciousLinks').appendChild(ul)

