$ml(document).ready(function(){
	// Blog Login Drop Down
	$ml(".blog-login-a").click(function(ev){
		ev.preventDefault();
		if($ml(this).next(".blog-login").length == 1) {
			$ml(this).next(".blog-login").slideToggle();
		} else {
			$ml(".blog-login").slideToggle();
		}
	});
	
	// Comment Reply Form Scroll
	$ml(".reply").click(function(ev){
		ev.preventDefault();
		setLegend('Reply to '+$ml(this).parent().parent().find(".comment_name").html(), $ml("#blog_comment_form").find('legend'));
		setFormId('/'+$ml(this).attr("href").match(/reply=([a-zA-Z0-9\-_\/]+)/)[1]);
		$ml.scrollTo('#blog_comment_form', 600);
	});
	
	// Add Comment Scroll
	$ml("p.post_addcomment-link").children("a").each(function(){
		$ml(this).bind('click', function(ev){
			ev.preventDefault();
			if($ml("#blog_comment_form").find("#blog_comment_orig_legend").length != 0) {
				setLegend($ml("#blog_comment_form").find("#blog_comment_orig_legend").html(), $ml("#blog_comment_form").find("legend"));
			}
			setFormId('');
			$ml.scrollTo('#blog_comment_form', 600);
		});
	});
	
	// Captcha Error
	if(blogCommentFormCaptchaError == 'true') {
		$ml.scrollTo('#blog_comment_form', 0);
	}

	// DEBUG PROFILE Close
	$ml(".DEBUG_PROFILE").each(function(){
		var prof = $ml(this);
		$ml(this).find('.close').each(function(){
			$ml(this).click(function(ev){
				ev.preventDefault();
				prof.fadeToggle();
			});
		});
		$ml(this).find('td').each(function(){
			$ml(this).click(function(){
				$ml(this).css('color', 'red');
			});
		});
	});
});

function setLegend(newLegend, legendObj)
{
	if($ml("#blog_comment_form").find("#blog_comment_orig_legend").length == 0) {
		legendObj.after('<div id="blog_comment_orig_legend" style="display:none;">'+legendObj.html()+'</div>');
	}
	legendObj.html(newLegend);
}

function setFormId(id)
{
	$ml("#blog_comment_form").find("#form_id").attr('value', $ml("#blog_comment_form").find("#post_id").attr('value')+id);
}
