
jQuery.noConflict(); 

function ajaxEffect(content){
	jQuery(content).css({visibility:"hidden"}).fadeIn(1000).css({visibility:"visible"}).animate({opacity: 1.0}, 3000).fadeOut(1000);
}

function ajaxEffectIn(content){
	jQuery(content).css({visibility:"hidden"}).fadeIn(1000).css({visibility:"visible"});
}

jQuery(document).ready(function() {

  jQuery('#menu li').hover(function() {
    jQuery(this).addClass('sfhover');
  }, function() {
    jQuery(this).removeClass('sfhover'); 
  });

  jQuery('#menu a').removeAttr("title");
  
  jQuery('#comment').one('focus',function() { //Live Comments
    jQuery('.formcontainer').prepend('<div id="comment-live-preview"></div>');
  });
  
  var $comment = ''; // that's two single quotation-marks at the end
  jQuery('#comment').keyup(function() {
    $comment = jQuery(this).val();
    $comment = $comment.replace(/\n/g, "<br />").replace(/\n\n+/g, '<br /><br />').replace(/(<\/?)script/g,"$1noscript").replace(/\[quote[^>]*?]/, "<blockquote>").replace(/\[\/quote\]/, "</blockquote>");
    jQuery('#comment-live-preview').html( $comment );
  });

  
	ajaxURL = 'http://blog.agent-sportif.fr/wp-content/themes/dkret3/ajax/jquery-comments.php?ver=3.0';

	jQuery("#commentform").submit(function(){
		if ( jQuery.find("#comments-list") == "" )	jQuery("#comments").prepend('<div id="comments-list"><ol id="comments-list-ordered"></ol></div>');
		jQuery("#comments-list h3").remove();
		jQuery(".write-comment-link").remove();
		jQuery(".commentnumber").remove();
		jQuery("#trackbacks-list").remove();
		jQuery(".formcontainer").prepend('<p id="comment-loading">&nbsp;</p>');
		ajaxEffectIn("#comment-loading");
		jQuery.ajax({
			type: "POST",
			url: ajaxURL,
			data: jQuery("#commentform input, #commentform textarea").serialize(),
			dataType: "html",
			error: function(request){
				if (jQuery("#ajaxerror")) jQuery("#ajaxerror").remove();
				jQuery("#comment-loading").fadeOut(1000, function(){
					jQuery("#comment-loading").remove();
					if (request.responseText.search(/<title>WordPress &rsaquo; Error<\/title>/) != -1) {
						var data = request.responseText.match(/<p>(.*)<\/p>/);
						data = '<p id="ajaxerror">Error: ' + data[1] + '</p>';
					} else {
						var data = request.responseText;
					}
					jQuery(".formcontainer").prepend(data);
					ajaxEffect("#ajaxerror");
				});
			},
			success: function(data){
				if (jQuery("#ajaxerror")) jQuery("#ajaxerror").remove();
				jQuery("#comment-loading").fadeOut(1000, function(){
					jQuery("#comment-loading").remove();
					jQuery("#comment-live-preview").fadeOut(1000).remove();
					jQuery("#comments-list-ordered").append(data);
					ajaxEffectIn("#newcomment");
					jQuery("#respond").animate({opacity: 1.0}, 1500).fadeOut(2000);
					if (window.AjaxEditComments) {
					 AjaxEditComments.init();
					}
				});
			}
		});
		return false;
	});
	
});
