function delete_click(e){
	var li = $(this).parent();
	if(!li.parent().hasClass('required') || li.siblings().length)
		li.hide('normal').queue(function(){ $(this).remove()});
	e.preventDefault();
	e.stopPropagation();
}

/**
 * Convert form to use ajax
 * mode: "replace", "append"
 * target: "#mydiv"
 */
(function($){
	$.fn.ajaxify = function(options){
		
		var options = jQuery.extend({mode: 'replace', success: function(data, status){
			if(options.target)
				var target = options.target;
			else
				var target = form;
			if(options.mode == 'replace')
				$(target).html(data);
			else
				$(target).append(data);
		}}, options);
		
		var form;
		$(this).each(function(){
			var submit;
			if(this.tagName.toUpperCase() == "FORM")
			{
				$(this).find("[type=submit]").live("click", function(e){
					submit = this;
				});
				$(this).bind("submit", function(e){
					form = $(this);
					var url = form.attr("action") || document.location.href;
					var m = form.attr("method") || "GET";
					var data = form.serializeArray();
					if(submit)
						data.push({name: submit.name, value: submit.value});
					if(m == "GET")
						$.get(url, data, options.success);
					else
						$.post(url, data, options.success);
					return false;
				});
			}
		});
		
		
		return this;
	}
})(jQuery);
$(window).resize(function(){
	$('#scroller').height($(window).height()-$('#top_bar').outerHeight()+parseInt($('#scroller').css('padding-top')));
});
$(window).load(function(){
	$('#scroller').height($(window).height()-$('#top_bar').outerHeight()+parseInt($('#scroller').css('padding-top')));
	if($('#scroller').length)
		$('html').css('overflow','hidden');
});
$(document).ready(function(){
	$('ul.tree li .toggler').live("click", function(e){
			$(this).parent().toggleClass('opened').toggleClass('closed');
			e.stopPropagation();
	});
	$('.module a[href*=ParseText]').live('click', function(e){
		var ajax_module = $(this).parents(".module").eq(0);
		jQuery.get(this.href, null, function(data){
			ajax_module.replaceWith(data);
		});
		e.preventDefault();
	});
	$('.accordion > h3').click(function(e){
		$(this).parent().toggleClass('closed');
	});
	$('.reply_to').click(function(e)
		{
			var href = $(this).attr('href').slice(1).split('|');
			$('[name=in_reply_to]').val(href[0]);
			$('#comment_form').show();
			$('[name=title]').val('Re: '+ href[1]).focus();
		});
	$("#main .check_all").live("click",function(e){
		e.preventDefault();
		$(this).parents('form').eq(0).find("input[type=checkbox]").attr("checked","checked");
	});
});
