RUN4IT=(typeof RUN4IT=='undefined'?{}:RUN4IT);
RUN4IT.classes=(typeof RUN4IT.classes=='undefined'?{}:RUN4IT.classes);
RUN4IT.classes.Clubs = function()
{
	var rows, i;
	
	if(!(this.root = document.getElementById('club-finder'))) return;

	rows = Shine.getElementsByClass(this.root, 'tr', 'club-row');
	for(i = 0; i < rows.length; i++)
	{
		this.hookEventRow(rows[i]);
	}
}
RUN4IT.classes.Clubs.prototype.hookEventRow = function(row)
{
	var details;
	
	for(details = row.nextSibling; details; details = details.nextSibling)
	{
		if(!details.tagName || details.tagName.toLowerCase() != 'tr') continue;
		if(!Shine.hasElementClass(details, 'club-details'))
		{
			return false;
		}
		break;
	}
	cells = Shine.getElementsByClass(row, 'td', 'name');
	if(!cells || !cells.length) return false;
	cells = cells[0];
	s = Shine.createHTMLElement('span');
	Shine.setAttribute(s, 'class', 'club-details-toggle');
	s.appendChild(document.createTextNode(Shine.getText(cells)));
	while(cells.firstChild) cells.removeChild(cells.firstChild);
	s.eventDetails = details;
	Shine.addEventHandler(s, 'click', { host: this, handler: this.onToggle });
	cells.appendChild(s);
	details.oldDisplay = details.style.display;
	details.style.display = 'none';
}
RUN4IT.classes.Clubs.prototype.onToggle = function(Shine, sender, ev, data)
{
	if(sender.eventDetails.oldDisplay == sender.eventDetails.style.display)
	{
		Shine.removeElementClass(sender.parentNode.parentNode, 'expanded');
		sender.eventDetails.style.display = 'none';
	}
	else
	{
		Shine.addElementClass(sender.parentNode.parentNode, 'expanded');
		sender.eventDetails.style.display = sender.eventDetails.oldDisplay;
	}
}
document.loadHooks=(typeof document.loadHooks=='undefined'?[]:document.loadHooks);
document.loadHooks.push(function(){new RUN4IT.classes.Clubs();});
