$(function(){
	$('.ProductAttributesSelect').change(function(){
		$el = $(this).find('option:selected');
		rel = $el.attr('rel');
		if (rel == 'hasOptions')
			$(this).next().slideDown();
		else
			$(this).next().slideUp();
	});
	
	$('input[type="image"]').click(function(){
		$(this).submit();
		$(this).unbind('click');
	});

	$('select[name="oa_attributes[44]"], select[name="oa_attributes[67]"], select[name="oa_attributes[21]"], select[name="oa_attributes[68]"]').change(function(){
		$selected = $(this).find('option:selected');
		var index = $(this).children().index($selected);
		if ($(this).attr('name') == "oa_attributes[44]" || $(this).attr('name') == "oa_attributes[21]")
		{
			var val = $(this).children().eq(index).val();
			var pat = new RegExp("Gauge");
			if ($(this).attr('name') == "oa_attributes[44]")
				$select = $('select[name="oa_attributes[67]"]');
			else
				$select = $('select[name="oa_attributes[68]"]');
			if (pat.test(val))
			{
				$select.val('None');
				$select.attr('disabled', true);
				$select.parent().next().next().next().fadeOut();
			}
			else
			{
				$select.attr('disabled', false);
				$select.children().eq(0).select();
				$select.parent().next().next().next().fadeIn();
			}
		}
		$images = $(this).parent().next().next().next();
		if ($(this).attr('name') == "oa_attributes[67]" || $(this).attr('name') == "oa_attributes[68]")
		{
			if ($images.children().filter(':visible').size() == 0)
				$images.children().eq(0).show();
		}
		$images.children().filter(':visible').fadeOut(function(){
			$images.children().eq(index).fadeIn();
		});
	});
});