(function(){
	var PIPES_URL = 'http://pipes.yahoo.com/pipes/pipe.run?_id=DEW4G3UP3BGY40Y2dbq02Q&_render=json&_run=1&_callback=document.updatedBanner&s=';
	
	// http://www.koikikukan.com/archives/2007/05/02-003535.php
	function updatedBanner(json)
	{
		if (json.value.items.length < 1 || !isUpdated(json.value.items[0].pubDate)) return;
		
		var updated = document.createElement('div');
		updated.style.zIndex = 99;
		updated.style.position = 'absolute';
		updated.style.top = 0;
		updated.style.left = 0;
		updated.style.display = 'block';
		updated.style.height = '120px';
		updated.style.width = '120px';
		
		var img = document.createElement('img');
		img.setAttribute('src', bitz_sticker_src);
		img.setAttribute('alt', 'updated now');
		img.setAttribute('title', 'updated now');
		img.style.border = 'none';
		img.style.height = '120px';
		img.style.width = '120px';
		
		var anchor = document.createElement('a');
		anchor.setAttribute('href', json.value.items[0].link);
		anchor.appendChild(img);
		updated.appendChild(anchor);
		document.getElementsByTagName('body').item(0).appendChild(updated);
		
		pngFix(img);
	}
	
	function getRssLocation()
	{
		var links = document.getElementsByTagName('link');
		for (var i = 0; i < links.length; i++) {
			var link = links[i];
			if (
				link.rel == 'alternate' &&
				(link.type == 'application/rss+xml' || link.type == 'text/xml')
			) {
				return link.href;
			}
		}
		
		return false;
	}
	
	function isUpdated(pubDate)
	{
		if (!pubDate.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/i)) return false;
		var date = new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6);
		return new Date().getTime() - date.getTime() < 86400 * 1000;
	}
	
	// http://homepage.ntlworld.com/bobosola
	function pngFix(img)
	{
		if (!/MSIE/.test(navigator.userAgent)) return;
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		
		if (version >= 5.5 && version < 7 && document.body.filters)  {
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<span " + imgID + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			img.parentNode.innerHTML = strNewHTML;
		}
	}
	
	function init()
	{
		var rss = getRssLocation();
		if (!rss) return;
		
		document.updatedBanner = updatedBanner;
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src  = PIPES_URL + encodeURIComponent(rss);
		document.getElementsByTagName('head')[0].appendChild(script);
	}
	
	init();
})();