jQuery.noConflict();

ind = new Image(16,16); 
ind.src='/images/indicator_circle_ball2.gif';

//jQuery.noConflict();

function ajaxEffect(content){
	jQuery(content).css({visibility:"hidden"}).fadeIn(1000).css({visibility:"visible"});
}

jQuery(document).ready(function() {

	var result;
	
	jQuery("script").each(function()
	{
		var scriptSrc = jQuery(this).attr("src");
		if(scriptSrc)
		{
			result = scriptSrc.match(/^(.*)jquery-comments.js/);
			if ( result ) {
				return false;
			}
		}
	});
	
	ajaxURL = result[0].replace(/jquery-comments.js/, "jquery-ajax.php");

	jQuery("#commentform").submit(function(){
		//if ( jQuery.find("#commentlist").length == 0 )	jQuery(this).parent().before('<ol id="commentlist"></ol>');
		jQuery("#postCommentForm").prev().after('<div id="loading"><p><img src="/images/indicator_circle_ball2.gif" height="16" width="16" border="0" /> Loading...</p></div>');
		jQuery('#commentFormContainer').slideUp('normal');
		ajaxEffect("#loading");
		if (jQuery("#ajaxerror")) jQuery("#ajaxerror").remove();
		var atype;
		var theData;
		jQuery.ajax({
			type: "POST",
			url: ajaxURL,
			data: jQuery("#commentform input, #commentform textarea").serialize(),
			dataType: "html",
			error: function(request){
				atype = "error";
			},
			success: function(data){
				atype = "success";
				theData = data;
			},
			
			complete: function(request){
				if(atype == "error")
				{
					var theRequestText = request.responseText;
					jQuery("#loading").fadeOut(1000, function(){
						jQuery("#loading").remove();
						jQuery('#commentFormContainer').slideDown('normal');
						if (theRequestText.search(/<title>WordPress &rsaquo; Error<\/title>/) != -1) {
							var data = theRequestText.match(/<p>(.*)<\/p>/);
							data = '<div id="ajaxerror"><span><p>' + data[1] + '</p></span></div>';
						} else {
							var data = theRequestText;
						}
						jQuery("#postCommentForm").prev().after(data);
						ajaxEffect("#ajaxerror");
					});
				} else {
					var data = theData;
					
					if (jQuery("#ajaxerror")) jQuery("#ajaxerror").remove();
					jQuery("#loading").fadeOut(1000, function(){
						jQuery("#loading").remove();
						jQuery("#postCommentForm").prev().after(data);
						//ajaxEffect(jQury('#postCommentForm').prev());
						jQuery("#commentform textarea").val("");
						jQuery('#commentFormContainer').slideDown('normal');
					});
				}
			}
		});
		return false;
	});
	
});

