// --------------------------------------------------
//
// --------------------------------------------------
$(document).ready(
	function ()
	{
		initExpandLinks();
		
		expandInitialSite();
	}
);

// --------------------------------------------------
//
// --------------------------------------------------
function initExpandLinks ()
{
    $("#site-accessibility-details tr.no-header").show();

    $("#site-accessibility-details tr.header td.url a").click(handleSiteExpandCollapse);

	$("#site-accessibility-details tr.header td.url a").focus(function () { this.blur(); });
};

// --------------------------------------------------
//
// --------------------------------------------------
function handleSiteExpandCollapse ()
{
	if ($(this).is(".expanded"))
	{
		toggleSite($(this).parent().parent(), "collapse");
	}
	else
	{
		toggleSite($(this).parent().parent(), "expand");
	};
	
	return false;
};

// --------------------------------------------------
//
// --------------------------------------------------
function toggleSite (row, direction)
{
	var l = $("td.url a", row);
	
	(direction == "collapse") ? l.removeClass("expanded") : l.addClass("expanded");

	row.nextAll("tr").each(
		function ()
		{
			if ($(this).is(".header")) return false;
			
			(direction == "collapse") ? $(this).hide() : $(this).show();
		}
	);
};

// --------------------------------------------------
//
// --------------------------------------------------
function expandInitialSite ()
{
	toggleSite($("#site-accessibility-details tr.header").eq(0), "expand");

};
