var js_len = document.getElementsByTagName('script').length;
for (var i = 0, got_url = -1; i <= js_len && got_url == -1; i++){
	var wapi_jsurl = document.getElementsByTagName('script')[i].src,
			got_url = wapi_jsurl.indexOf('/ajax-comments.js');
}

var wapi_php_url = wapi_jsurl.replace('/ajax-comments.js','/ajax-comments.php');
var wapi_img_url = wapi_jsurl.replace('/ajax-comments.js','/loading.gif');

function showAjaxComments(id) {
     var postid= String(id);
	$("div#ajax-comments-"+postid).data('alreadyshown',false);
     jQuery(document).ready(function($) {
     if ($("div#ajax-comments-"+postid).data('alreadyshown')==false){
	$("div#ajax-comments-"+postid).data('alreadyshown',true);
     jQuery.ajax({
  	type: 'POST',
  	url: wapi_php_url,
	beforeSend: function(XMLHttpRequest) {$("div#ajax-comments-"+postid).html("<img src='"+wapi_img_url+"' alt='Comments loading,Please wait...' title='Comments loading,Please wait...'>");},
  	data: {id:postid},
  	success: function(data){
		$("#ajax-comments-"+postid).html(data);
		//check if we got any comments and if not, display the comment form
		if($("#ajax-comments-"+postid).has('div.ajax-comment-text').length==0){
			quickCommentform(postid);
		}
	},
	error: function(XMLHttpRequest, textStatus, errorThrown){$("#ajax-comments-"+postid).replaceWith("Failed to get comments:" + textStatus);}
     });		
         }else{
		$("#ajax-comments-"+postid).delay(700).slideDown();
         }
		$("#ajax-comments-"+postid).delay(700).slideDown();
     	$("#show-ajax-comments-"+postid).hide();
		$('#contact-thankyou-'+postid).hide();
		$("#contact-form-container-"+postid).slideUp();
		$("#enquiry-link-"+postid).show(); 
		$("#hide-ajax-comments-"+postid).show();
    });
}


function hideAjaxComments(id) {
     var postid= String(id);
     jQuery(document).ready(function($) {
     	$("#hide-ajax-comments-"+postid).hide();  $("#show-ajax-comments-"+postid).show();  $("#ajax-comments-"+postid).slideUp(); 
		$("#waci-comment-form-"+postid).hide();
     });
}


function quickCommentform(id) {
     var postid= String(id);
     jQuery(document).ready(function($) {
	$("#waci-comment-form-"+postid).slideDown(); $("#show-ajax-comments-form-"+postid).hide();  	
	//$("#hide-ajax-comments-form-"+postid).slideDown();
	$('.slideout-form input, .slideout-form textarea').bind('focus', function() {
		if($(this).val()==$(this).attr('rel')){
			$(this).val('');
		}			
	});
	$('.slideout-form input, .slideout-form textarea').bind('blur', function() {
		if($(this).val()==''){
			$(this).val($(this).attr('rel'));
		}
	});
     });
}

function hideCommentform(id) {
     var postid= String(id);
     jQuery(document).ready(function($) {
	$("#waci-comment-form-"+postid).slideUp(); $("#hide-ajax-comments-form-"+postid).hide();  $("#show-ajax-comments-form-"+postid).slideDown(); 
     });
}
