if (!window.$)
{
	window.$ = function (id)
	{
		return document.getElementById(id);
	}
}

var thumb_preview_showing = null;
var thumb_preview_timeout = null;
function show_thumb_preview(id)
{
	if (!$(id).onmouseover)
		$(id).onmouseover = function ()
		{
			show_thumb_preview(this.id);
		}

	if (!$(id).onmouseout)
		$(id).onmouseout = function ()
		{
			hide_thumb_preview_soon(this.id);
		}

	if (thumb_preview_showing && thumb_preview_showing != id)
		$(thumb_preview_showing).style.display = "none";
	if (thumb_preview_timeout)
		window.clearTimeout(thumb_preview_timeout);

	if ($(id).style.display != "block")
	{
		$(id).style.display = "block";

		thumb_preview_showing = id;

		set_opacity($(id), 0.1);
		$(id).OpacityDest = 1.0;

		window.setTimeout(function () {animate_thumb_preview(id);}, 50);
	}
}

function hide_thumb_preview_soon(id)
{
	if (id != thumb_preview_showing)
	{
		$(id).style.display = "none";
		return;
	}

	thumb_preview_timeout = window.setTimeout(hide_thumb_preview, 100);
}

function hide_thumb_preview()
{
	var id = thumb_preview_showing;
	thumb_preview_showing = null;

	//$(thumb_preview_showing).style.display = "none";
	$(id).OpacityDest = 0;

	window.setTimeout(function () {animate_thumb_preview(id);}, 50);
}

function animate_thumb_preview(id)
{
	var curr = Number(get_opacity($(id)));
	var delta = Number($(id).OpacityDest - curr);
	if (delta < 0)
		delta = Math.max(-0.5, delta);
	else
		delta = Math.min(0.3, delta);

	set_opacity($(id), Number(curr + delta));

	if (Number(curr + delta) == 0)
		$(id).style.display = "none";
	if (delta != 0)
		window.setTimeout(function () {animate_thumb_preview(id);}, 50);
}

window.set_opacity = function (el, f)
{
	if (typeof(el.style.MozOpacity) != "undefined")
		return el.style.MozOpacity = f;
	else if (typeof(el.style.KhtmlOpacity) != "undefined")
		return el.style.KhtmlOpacity = f;
	else if (typeof(el.style.filter) != "undefined")
		return el.style.filter = "alpha(opacity=" + Math.round(f * 100) + ");"
	else
		return el.style.opacity = f;
}

window.get_opacity = function (el)
{
	if (typeof(el.style.MozOpacity) != "undefined")
		return el.style.MozOpacity;
	else if (typeof(el.style.KhtmlOpacity) != "undefined")
		return el.style.KhtmlOpacity;
	else if (typeof(el.filters) != "undefined" && typeof(el.filters.alpha) != "undefined")
		return el.filters.alpha.opacity / 100;
	else if (typeof(el.style.opacity) != "undefined")
		return el.style.opacity;
	else
		return "";
}
