function SetActivePage()
{
	var id = null;
	var path = document.location.pathname;
	
	if (path == "/")									id = "ha_startpage";
	else if (path.substring(0, 10) == "/calendars")		id = "ha_calendars";
	else if (path.substring(0, 8) == "/deejays")		id = "ha_deejays";
	else if (path.substring(0, 6) == "/shows")			id = "ha_shows";
	else if (path.substring(0, 9) == "/mixtapes")		id = "ha_mixtapes";
//	else if (path.substring(0, 11) == "/statistics")	id = "ha_statistics";
	else if (path.substring(0, 7) == "/forums")			id = "ha_forums";
	else if (path.substring(0, 7) == "/search")			id = "ha_ismsearch";
	else if (path.substring(0, 6) == "/subscriptions")	id = "ha_subscriptions";

	try
	{
		var el = document.getElementById(id);
		if (el != null && typeof(el) != "undefined" && el.tagName.toLowerCase() == "a")
		{
			el.className = "activepage";
		}
	}
	catch (e) {}
}

var STAR_OFF = IMAGE_URL + "StarOff.png";
var STAR_ON = IMAGE_URL + "StarOn.png";

var ARROW_DOWN = IMAGE_URL + "ArrowDown.png";
var ARROW_UP = IMAGE_URL + "ArrowUp.png";

var supressMixtapeDescription = false;

function getMixtapeStars(id)
{
	var stars = [];
	for (var i = 1; i <= 5; i++)
	{
		stars[i] = document.getElementById("mt" + id + "star" + i);
	}
	return stars;
}

function toggleMixtapeDescription(id)
{
	if (!supressMixtapeDescription)
	{
		try
		{
			var elid = "mt_" + parseInt(id) + "_dscr";
			ToggleDisplay(elid);
			
			var img = document.getElementById("mt_" + parseInt(id) + "_hsimg");
			img.src = document.getElementById(elid).style.display == "none" ? ARROW_DOWN : ARROW_UP;
		}
		catch(e) {}
	}
	else
	{
		supressMixtapeDescription = false;
	}
}

function DeleteGearImage(gearID, imageID)
{
	if (typeof(gearID) != "number" || typeof(imageID) == "undefined")
		return;
	
	// Send update request to the server
	var url = BASE_URL + "ismusic/gear/manage/edit/" + gearID + "/delete-image/" + imageID + "/";
	jQuery.post(
		url,
		{ },
		DeleteGearImageCompleted,
		"json"
	);
}

function DeleteGearImageCompleted(json)
{
	if (json.error > 0)
	{
		alert("Got an error: " + json.error);
	}
	else
	{
		// Remove the comment
		var e = document.getElementById("gearimage_" + json.imageID);
		e.parentNode.removeChild(e);
	}
}

//var statsLoadingHTML = "<img src=\"" + IMAGE_URL + "Loading.gif\" alt=\"\" />";
function InitStats()
{
	GetStats("popular-deejays");
	GetStats("popular-mixtapes");
	GetStats("country-distribution");
}
function GetStats(which, all)
{
	try
	{
		var url = null;
		var element = document.getElementById("stats-"+which);
		//element.innerHTML = statsLoadingHTML;

		// Determine URL
		if (which == "popular-deejays")				url = "popular-deejays";
		else if (which == "popular-mixtapes")		url = "popular-mixtapes";
		else if (which == "country-distribution")	url = "country-distribution";

		if (url != null)
		{
			url = BASE_URL + "statistics/data/" + url + "/";

			if (all == true)
				url += "all/";

			// Get data
			jQuery.get(
				url,
				function (data)
				{
					element.innerHTML = data;
				}
				);
		}
	}
	catch (e) { alert("Something went wrong while retrieving statistics"); }
}