/**
 *	Options for product detail page
 */
initOptions = function() {
	$$('.product-options select').each(function(optionSelect) {
		//	Probably never used, as the select box is hidden
		optionSelect.observe('change', function(event) {
			updateOptions();
		});
	});

	//	Select first option of first choice
	var dropdown = $$('.product-options select')[0];
	var attribute_id = dropdown.id.replace('attribute', '');
	$('options_' + attribute_id).firstDescendant().onclick();
	//Element.fire($('options_' + attribute_id).firstDescendant(), 'click');
	//set_attribute_selected_value(attribute_id, value);
} 
updateOptions = function() {
	$$('.product-options select').each(function(optionSelect) {
		attribute_id = optionSelect.id.replace('attribute', '');

		//	Walk through all options, and set them inactive
		$$('#options_' + attribute_id + ' li').each(function(option) {
			option.addClassName('inactive');
			option.removeClassName('selected');
		});

		if (!optionSelect.disabled) {
			availableOptions = Selector.findChildElements(optionSelect, ['option']);
			availableOptions.each(function(availableOption) {
				if (availableOption.value > 0) {
					$('option_' + attribute_id + '_' + availableOption.value).removeClassName('inactive');
				}
			});
			if (optionSelect.value > 0) {
				$('option_' + attribute_id + '_' + optionSelect.value).addClassName('selected');
			};
		};
	});
};

document.observe("dom:loaded", function(){
	if ($$('.product-options select').length > 0) {
		// moved from media.phtml
		
		initOptions();
		updateOptions();
	}
});
