$(function(r){
	$("input[name='years']").click(function(c){
		var str = $("input[name=years]:checked").val();
		str += (str == 1) ? ' year' : ' years';
		$("#term").html(str);
	});
	
	$("#scope_information legend, #special_block legend, .oops").click(function(c){
		var all_items = $("#all_products");
		var vis = all_items.val();
		if(vis == "0"){
			$("#scope_information").hide();
			$("#special_block").show();
			all_items.val("1");
		} else {
			$("#scope_information").show();
			$("#special_block").hide();
			all_items.val("0");
		}
		return false;
	});
	
	$("#category").change(category_change);
	
	$("a.bookmark").click(function(e){
		e.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = $(this).attr('href');
		if(url.substring(0,1) == '#' || url == ''){
			if(window.location){
				url = window.location;
			} else if(window.location.href){
				url = window.location.href;
			} else if(location.href){
				url = location.href;
			}
			if($.browser.opera){
				$(this).attr('href', url);
			}
		}
		
		var title = $(this).attr('title');
		if(title == ''){
			title = $(document).find('title').html();
			if($.browser.opera){
				$(this).attr('title', title);
			}
		}
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url, '');
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite(url, title);
		} else if($.browser.opera) { // Opera 7+
			if ($("a.bookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
				$("a.bookmark").attr("rel","sidebar");
			}
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			alert("Unfortunately, this browser does not support the requested action.\n" +
				  "Please bookmark this page manually (hint: try pressing CTRL+D).");
		}
		
	});
	
	
	category_change();
});

function category_change(){
	var val = $("#category").find(':selected').html();
	val = $.trim(val.toLowerCase());
	val = val.replace('&nbsp;','');
	val = val.replace("\n", '');
	$(".togglable").hide();
	$(".togglable select").attr('disabled','disabled');
	$("#"+val).show();
	$("#"+val+" select").removeAttr('disabled');
}