

var open_comment = null;
var old_text = null;

function loaderON(blogID){
	$('ajax_loader_'+blogID).set('html','<img src="/ajax/ajax-loader.gif" border="0" style="border:none;"/>');
	
}

function loaderOFF(blogID){
	$('ajax_loader_'+blogID).set('html','');
}


function closeComment(blogID){
		$('ajax_comments_'+blogID).open=false;
		var mySlide = new Fx.Slide('ajax_comments_'+blogID);
		mySlide.toggle();
}



function loadComments(blogID,bypass){

	var isOpen = $('ajax_comments_'+blogID).open;
	
	
		
	if((isOpen==true) && (bypass==false)){
		
		$('comment_linker_'+blogID).set('text',$('comment_linker_'+blogID).old);
		closeComment(blogID);
	
		open_comment=null;
		
	}else{
			if(open_comment!=blogID && open_comment!=null){
				closeComment(open_comment);
			}
			
			//alert('loading');
			open_comment = blogID;
			$('ajax_comments_'+blogID).open=true;
			old_text = $('comment_linker_'+blogID).get('text');
			$('comment_linker_'+blogID).old = old_text;
			
			loaderON(blogID);
			
		    var getHTML = new Request.HTML({update:$('ajax_comments_'+blogID),evalScripts:true,onComplete:function(){
		
				
				$('comment_linker_'+blogID).set('text','Hide Comments');
				
				
				
				var mySlider = new Fx.Slide('ajax_comments_'+blogID,{onComplete:function(){
					var myScroll= new Fx.Scroll(window).toElement('ajax_comments_'+blogID);
				}});
				
				loaderOFF(blogID);
				
				//refreshSIFR();
				
				mySlider.slideIn();
			//---------
			}}).get('ajax/comments_ajax.php?id='+blogID);
	}
}



function pingComment(postID){
	//alert('pingging '+postID);
	//var pingMe = new Request({url:'http://practiceworkplay.com/ajax/pingcomment.php?comment_post_ID='+postID, method:'get' }).send();

}


function submitComment(postID){
	
	//http://practiceworkplay.com/wp-comments-post.php
	//commentform


	var a = $('author_'+postID).get('value');
	var b = $('email_'+postID).get('value');
	var c = $('url_'+postID).get('value');
	var d = $('comment_'+postID).get('value');

	
	var checkers = new Array(a,b,d);
	var valid = true;
	checkers.each(function(x){
		if(x=="") valid =false;
	});

	if(valid==false){
		
		$('comment_phrase_'+postID).setProperty('html','Please Complete Required Fields');
	}else{
		//$('comment_loader_'+postID).set('html','<img src="/ajax/ajax-loader.gif" border="0" style="border:none;"/>');
		 var dataObj = {author:a,email:b,url:c,comment_post_ID:postID,comment:d,submit:'Submit Comment'};
		 	
		var send = new Request({url:'http://practiceworkplay.com/wp-comments-post2.php',method:'post',data:dataObj,onSuccess:function(t){
				//this pings it
				 
					pingComment(postID);
					
				$('comment_phrase_'+postID).setProperty('html','Success!');
				//$('comment_loader_'+postID).set('html','');
				loadComments(postID,true);
				
		 }}).send();
	}
	
	
	
	//comment_post_ID
	
}
















