/*
	Windy City Help Desk JavaScript
*/

var Forms = 
{
	/*
		Disables all submit buttons onclick to prevent double-submits
	*/
	safeSubmit: function(event)
	{
		//	Grab all submit buttons
		var submitButtons = $$('input[type=submit]');
		
		//	Loop through and disable all submit buttons
		submitButtons.each(function(element)
		{
			element.disabled = true;
		});
	}
}
Event.observe(document,'dom:loaded',function()
{
	//	Grab all froms
	var forms = $$('form');
	
	//	Loop through and listen for all submit clicks
	forms.each(function(element)
	{
		Element.observe(element,'submit',Forms.safeSubmit);
	});
});

/*
	Provide smooth scrolling for anchored links
*/
var SmoothAnchors = 
{
	load: function()
	{
		//	Grab all anchored links except those with only #
		//	Loop through, listen for event, scrolling effect, then stop default event behavior
		$$('a[href^=#]:not([href=#])').each(function(element)
		{
			element.observe('click',function(event)
			{
				new Effect.ScrollTo(this.hash.substr(1),{ duration: 0.375 });
				Event.stop(event);
			}.bindAsEventListener(element))
		})
	}
}
Event.observe(document,'dom:loaded',SmoothAnchors.load);

var Tables = 
{
	/*
		Provide alternating row striping for tables with "striped" CSS class
	*/
	stripeRows: function()
	{
		//	Grab every other table row
		var rows = $$('table.striped tr:nth-child(even)');
		
		//	Add "alt" CSS class
		rows.each(function(element)
		{
			Element.addClassName(element,'alt');
		});
	}
}
Event.observe(document,'dom:loaded',Tables.stripeRows);