/*
 * Add Halloween edition of Tux to left-bottom page
 * Image source: http://www.junauza.com/2008/10/15-scariest-tux-icons-for-halloween.html
 * Script author: Yu-Jie Lin ( http://livibetter.mp/ )
 */

function ChainEvent(evt, f) {
	if (window.addEventListener)
		window.addEventListener(evt, f, true);
	else
		window.attachEvent('on' + evt, f);
    }

ChainEvent('load', function() {
	var hallotux = document.createElement('img');
	var now_date = new Date()
	var img_name = (Math.floor(Math.random() * 15) + 1).toString() + '.png'
	hallotux.setAttribute('id', 'hallotux');
	hallotux.setAttribute('src', 'http://sites.google.com/site/livibetter/blog-files/hallotux/' + img_name + '?attredirects=0');
	hallotux.style.position = 'absolute';
	hallotux.style.left = 0;
	hallotux.style.top = ((window.pageYOffset ? window.pageYOffset : (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop)) + 
		(window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight: document.body.clientHeight)) - 256) + 'px';
	document.getElementsByTagName('body')[0].appendChild(hallotux);
	});

var HallotuxMove = function() {
		var hallotux = document.getElementById('hallotux');
		if (hallotux) {
		hallotux.style.top = ((window.pageYOffset ? window.pageYOffset : (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop)) + 
			(window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight: document.body.clientHeight)) - 256) + 'px';
			}
		};

ChainEvent('scroll', HallotuxMove);
ChainEvent('resize', HallotuxMove);
