/**
 * Utility methods for the downloads section, including
 * DOM-based filtering for preview tiles 
 */

/**
 * Takes the current value of "this" and uses it to filter
 * elements with a className of "tilegroup" within the document.
 * - if the "tilegroup"
 * 
 * Assumes 'this' has the scope of the select object to which
 * this method will be assigned as an event listenter.
 * This is achieved using Prototype's Function.bindAsEventListener
 */
var selFilter_onchange = function() {
	var filter = $F(this);
	var nodes = $A(document.getElementsByClassName('tilegroup','listings'));
	nodes.each(function(node) {
		(Element.hasClassName(node,filter) || filter == '') ? Element.show(node) : Element.hide(node);
	})
}

// Attach event handlers by URL
document.observe('dom:loaded', function() {
	if ($('selFilter')) {
		$('selFilter').onchange = selFilter_onchange.bindAsEventListener($('selFilter'));
		$('selFilter').onchange();
	}
});