function home_mwl_detail(id)
{
	function async(response)
	{
		var h = document.getElementById("home_mwl_list").clientHeight;
		var review_h;
		var xml = response.responseXML;

		for (var i = 0; i < xml.childNodes.length; i++)
			if (xml.childNodes[i].nodeName == "data")
			{
				xml = xml.childNodes[i];
				break;
			}

		if (document.getElementById("home_mwl_content").style.paddingBottom)
			h -= parseInt(document.getElementById("home_mwl_content").style.paddingBottom);
		if (h < 380)
			h = 380;

		document.getElementById("home_mwl_list").style.display = "none";
		document.getElementById("home_mwl_content").style.display = "";

		document.getElementById("home_mwl_content").style.height = h + "px";

		review_h = h - 162;
		document.getElementById("home_mwl_review").style.height = review_h + "px";

		document.getElementById("home_mwl_mp3").style.display = 'none';

		for (var i = 0; i < xml.childNodes.length; i++)
		{
			if (xml.childNodes[i].nodeType != 1)
				continue;

			var k = xml.childNodes[i].nodeName;
			var v = xml_text_content(xml.childNodes[i]);

			if (k == "mp3")
			{
				if (v != '')
				{
					document.getElementById("home_mwl_" + k).href = '/admin' + v;
					document.getElementById("home_mwl_" + k).style.display = '';
				}

				continue;
			}
			else if (k == "reviewer")
				document.getElementById("home_mwl_reviewer_c").style.display = v == '' ? 'none' : '';

			if (k == "picture")
			{
				k = "image";
				v = '<img src="/blog/image.php?src=' +escape_html(v) + '&amp;fitType=crop&amp;width=150&amp;height=150&amp;maxS=1" alt="" />';
			}
			else if (k == "review")
				v = '<div style="height: ' + review_h + 'px; overflow: auto; width: 415px;">' + v + '</div>';
			else
				v = escape_html(v);

			document.getElementById("home_mwl_" + k).innerHTML = v;
		}
	}

	window.location.href = "#music-" + id;

	http_get("/data/home-mwl.php?item=" + id, async);
}

window.setTimeout(home_mwl_check_hash, 200);

var home_mwl_check_last = "";
function home_mwl_check_hash()
{
	if (home_mwl_check_last != window.location.hash)
	{
		if (window.location.hash == "" || window.location.hash == "#" || window.location.hash == "#home")
			home_mwl_close(true);

		if (window.location.hash.indexOf("#music-") == 0)
		{
			var id = window.location.hash.substr(7);
			if (id > 0)
				home_mwl_detail(id);
		}

		home_mwl_check_last = window.location.hash;
	}

	window.setTimeout(home_mwl_check_hash, 200);
}

function home_mwl_close(actual)
{
	window.location.href = "#home";

	if (actual)
	{
		document.getElementById("home_mwl_list").style.display = "";
		document.getElementById("home_mwl_content").style.display = "none";
	}
}

function home_mwl_play_mp3(mp3, link)
{
	hidden_play_mp3(mp3, link);
}

function home_mwl_addcart(item_id, type)
{
	function async(response)
	{
		var xml = xml_first_child(response.responseXML, "data");

		if (type != "bsh_track")
		{
			document.getElementById("buy-stuff-cart-error_" + item_id).innerHTML = xml_text_content(xml_first_child(xml, "message"));
			document.getElementById("buy-stuff-cart-error_" + item_id).style.display = "block";
		}

		if (xml.getAttribute("ok") == "1")
		{
			// Customize the message for this page.
			if (type != "bsh_track")
				document.getElementById("buy-stuff-cart-error_" + item_id).innerHTML = 'This item has been added to your <a href="/buy-stuff/cart.html">shopping cart</a>.';

			window.location.href = "/buy-stuff/cart.html";
		}
		else if (type == "bsh_track")
			alert(xml_text_content(xml_first_child(xml, "message")));
	}

	http_get("/buy-stuff/cart.html?xml=add&item=" + item_id + "&type=" + type, async);

	return false;
}

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 "";
}


var home_gallery_onload = window.onload;
window.onload = home_gallery_load;

var home_gallery_now = {};
var home_gallery_timeout = {};
var home_gallery_animDone = {};

function home_gallery_load()
{
	if (typeof(window.home_gallery_listing) != "undefined")
	{
		for (ident in window.home_gallery_listing)
		{
			home_gallery_now[ident] = -1;
			home_gallery_timeout[ident] = null;
			home_gallery_animDone[ident] = false;

			home_gallery_switch(ident, 0);
		}
	}

	window.onload = home_gallery_onload;
	home_gallery_onload = null;

	if (window.onload)
		return window.onload();
}

function home_gallery_schedule(ident)
{
	home_gallery_pause(ident);

	function finish()
	{
		home_gallery_switch(ident, home_gallery_now[ident] + 1);
	}

	home_gallery_timeout[ident] = window.setTimeout(finish, 5000);
}

function home_gallery_pause(ident)
{
	if (home_gallery_timeout[ident] != null)
		window.clearTimeout(home_gallery_timeout[ident]);
	home_gallery_timeout[ident] = null;
}

function home_gallery_switch(ident, n)
{
	if (n < 0)
		n = home_gallery_listing[ident].length + n;
	if (n >= home_gallery_listing[ident].length)
		n = 0;

	if (home_gallery_now[ident] != -1)
	{
		var now_image = document.getElementById(home_gallery_listing[ident][home_gallery_now[ident]].id);

		now_image.style.display = "block";

		function fade_out()
		{
			var o = parseFloat(get_opacity(now_image));
			if (o - 0.5 > 0)
			{
				set_opacity(now_image, o - 0.5);
				window.setTimeout(fade_out, 10);
			}
			else
			{
				set_opacity(now_image, 0);
				now_image.style.display = "none";

				home_gallery_now[ident] = -1;
				window.setTimeout(function ()
				{
					home_gallery_switch(ident, n);
				}, 100);
			}
		}

		window.setTimeout(fade_out, 10);
		return;
	}

	var new_image = document.getElementById(home_gallery_listing[ident][n].id);

	set_opacity(new_image, 0.01);
	new_image.style.display = "block";

	function fade_in()
	{
		var o = parseFloat(get_opacity(new_image));
		if (o + 0.1 < 1)
		{
			set_opacity(new_image, o + 0.1);
			window.setTimeout(fade_in, 10);
		}
		else
		{
			set_opacity(new_image, 0.99);

			if (home_gallery_animDone[ident])
				home_gallery_pause(ident);
			else
				home_gallery_schedule(ident)
		}
	}

	home_gallery_now[ident] = n;
	window.setTimeout(fade_in, 10);
}

var home_news_onload = window.onload;
window.onload = home_news_resize2;

function home_news_resize2()
{
	if (document.getElementById("home-news-content-scroller"))
	{
		home_news_resize();
		document.getElementById("home-news-content-scroller").style.overflow = "auto";
		document.getElementById("home-news-content-scroller").style.overflowX = "hidden";
	}

	if (home_news_onload)
	{
		window.onload = home_news_onload;
		home_news_onload = null;
		return window.onload();
	}
	else
		return true;
}

function home_news_resize()
{
	var box = document.getElementById("home-news-content-scroller");
	var divs = box.getElementsByTagName ? box.getElementsByTagName("div") : box.all.tags.div;

	var h = 0;
	for (var i = 0; i < divs.length; i++)
	{
		if (divs[i].className == "home-news-content-item")
			h += divs[i].offsetHeight;
	}

	if (h > 420)
		h = 420;
	box.style.height = h + "px";
}


var home_features_onload = window.onload;
window.onload = home_features_load;

var home_features_now = -1;
var home_features_timeout = null;
var home_features_animDone = false;
var home_features_halted = false;

function home_features_load()
{
	if (typeof(home_features_listing) != "undefined")
		home_features_switch(0);

	window.onload = home_features_onload;
	home_features_onload = null;
	return window.onload();
}

function home_features_schedule()
{
	home_features_pause();

	function finish()
	{
		home_features_switch(home_features_now + 1);
	}

	home_features_timeout = window.setTimeout(finish, 8000);
}

function home_features_pause()
{
	if (home_features_timeout != null)
		window.clearTimeout(home_features_timeout);
	home_features_timeout = null;
}

function home_features_nav(n)
{
	if (home_features_halted)
		home_features_animDone = false;
	else
		home_features_animDone = true;
	home_features_halted = false;

	home_features_switch(n);
}

function home_features_switch(n)
{
	if (home_features_listing.length <= 1 && home_features_now == 0)
		return;

	if (n < 0)
		n = home_features_listing.length + n;
	if (n >= home_features_listing.length)
		n = 0;

	if (home_features_now != -1)
	{
		var now_image = document.getElementById(home_features_listing[home_features_now].id);
		var now_nav = document.getElementById(home_features_listing[home_features_now].nav);

		now_image.style.display = "block";

		function fade_out()
		{
			var o = parseFloat(get_opacity(now_image));
			if (o - 0.5 > 0)
			{
				set_opacity(now_image, o - 0.5);
				window.setTimeout(fade_out, 10);
			}
			else
			{
				set_opacity(now_image, 0);
				now_image.style.display = "none";

				now_nav.src = "/images/home2/features-item_off.gif";

				home_features_now = -1;
				window.setTimeout(function ()
				{
					home_features_switch(n);
				}, 100);
			}
		}

		window.setTimeout(fade_out, 10);
		return;
	}

	var new_image = document.getElementById(home_features_listing[n].id);
	var new_nav = document.getElementById(home_features_listing[n].nav);

	new_nav.src = "/images/home2/features-item_on.gif";

	set_opacity(new_image, 0.01);
	new_image.style.display = "block";

	function fade_in()
	{
		var o = parseFloat(get_opacity(new_image));
		if (o + 0.1 < 1)
		{
			set_opacity(new_image, o + 0.1);
			window.setTimeout(fade_in, 10);
		}
		else
		{
			set_opacity(new_image, 0.99);

			if (home_features_listing[n].halt)
			{
				home_features_pause();
				home_features_halted = true;
			}
			else if (home_features_animDone)
				home_features_pause();
			else
				home_features_schedule()
		}
	}

	home_features_now = n;
	window.setTimeout(fade_in, 10);
}