hohoho = function (id)
{
	this.id = id;
	this.storage = null;
	this.timer = null;
	this.counter = 10;

	this.snake = '/images/hoh/snake.gif';
	this.link = '/images/hoh/hoh.gif';

	this.random = function (max)
	{
		return Math.round(Math.random() * max);
	}

	this.start = function ()
	{
		this.counter--;
		if (this.counter <= 0)
		{
			clearInterval(this.timer);
			this.end();
			return true;
		}
		if (this.pixel)
		{
			this.pixel.onmouseover = function () {};
		}

		var pix = document.createElement('div')
		pix.className = 'pix';

		clearTimeout(this.timer);
		this.pixel = document.createElement('div');
		this.pixel.appendChild(pix);

		this.changeColor();

		var x = this.random(100);
		var y = this.random(100);

		if (this.random(1))
		{
			this.pixel.style.left = x + 'px';
		}
		else
		{
			this.pixel.style.right = x + 'px';
		}
		if (this.random(1))
		{
			this.pixel.style.top = y + 'px';
		}
		else
		{
			this.pixel.style.bottom = y + 'px';
		}

		this.storage.appendChild(this.pixel);

		this.pixel.onmouseover = function (elem) 
		{
			return function ()
			{
				elem.start();
			}
		}(this);

		this.handler = this.changeColor;
		this.timer = setInterval(this.closing(this), 100);
	}

	this.end = function ()
	{
		document.getElementById('hohsnake').style.display = '';
		document.getElementById('hohsnake').style.backgroundImage = 'url(' + this.snake + ')';
		this.storage.style.zIndex = 100;
		this.handler = this.showLink;
		this.timer = setTimeout(this.closing(this), 7000);
	}

	this.showLink = function ()
	{
		clearTimeout(this.timer);
		document.getElementById('hohbg').style.display = '';
		document.getElementById('hohbg').style.backgroundImage = 'url(' + this.link + ')';
		var a = document.createElement('a');
		a.className = 'hohlink';
		a.href = 'http://hoh.dominion.ru/';
		a.onclick = function()
		{
			var a = pageTracker._trackEvent('hoh', 'click');
		}
		this.storage.appendChild(a);
	}

	this.changeColor = function ()
	{
		var colorId = this.random(8);
		this.pixel.className = 'pixel color' + colorId;
	}

	this.closing = function (param)
	{
		return function ()
		{
			param.handler();
		}
	}

	this.init = function ()
	{
		this.storage = document.getElementById(this.id);
		if (this.storage)
		{
			var timeout = this.random(100);
			this.handler = this.start;
			this.timer = setTimeout(this.closing(this), timeout);
		}
	}
	this.init();
}

var func = function ()
{
	var bugaga = new hohoho('hoh');
}
setTimeout('func()', 5000);
