google.load("feeds", "1");

function initialize() {
	var loading = document.getElementById("loading");
	var ran = Math.random()*100;
	var feed = new google.feeds.Feed("http://fotologue.jp/fantasista/rss.xml"+"?"+ran);
	feed.setNumEntries(12);
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	feed.load(function(result) {
		var container = document.getElementById("fotologue");
		var ulist = document.createElement("ul");
		container.appendChild(ulist);
		if (!result.error) {
    		var items = result.xmlDocument.getElementsByTagName("item");
			loading.style.display = "none";
			for (var i = 0; i < items.length; i++) {
				var entry = items[i];
				var li = document.createElement("li");
				var imgAnchor = document.createElement("a");
				var imgAnchorPath = entry.getElementsByTagName("link")[0].firstChild.nodeValue;
				var imgAnchorText = entry.getElementsByTagName("title")[0].firstChild.nodeValue;
				if(entry.getElementsByTagName("media:thumbnail")[0] == null) {
					var imgPath = entry.getElementsByTagName("thumbnail")[0].getAttribute("url");
				} else {
					var imgPath = entry.getElementsByTagName("media:thumbnail")[0].getAttribute("url");
				}
				var imgsrc = document.createElement("img");

				imgAnchor.setAttribute("title",imgAnchorText);
				imgAnchor.setAttribute("alt",imgAnchorText);
				imgAnchor.setAttribute("target","_blank");
				imgAnchor.setAttribute("href",imgAnchorPath);
				imgAnchor.className = "tips";
				
				imgsrc.setAttribute("src",imgPath);
				li.appendChild(imgAnchor);
				li.getElementsByTagName("a")[0].appendChild(imgsrc);
				ulist.appendChild(li);
			}
			$$(".tips").each( function(link) {
			new Tooltip(link, {backgroundColor: "#A9DDD9", borderColor: "#A9DDD9", textColor: "#333", textShadowColor: "#FFF", delay: 0, mouseFollow: true, maxWidth: 200, appearDuration: 0.5, hideDuration: 0.5});
			});
		} else {
			document.getElementById("fotoFeed").style.display = "none";
		}
	});
	feed.onLoadError
}
google.setOnLoadCallback(initialize);

