function write_comment(){
	if( ! is_user_logged ){
		alert("You must be logged in to comment.");
//		window.location.hash = "#main";
		return false;
	}
	if( !jQuery.data($("#comment_form").get(0), "h") )
		jQuery.data( $("#comment_form").get(0), "h", $("#comment_form").show().height() );
	var height = jQuery.data($("#comment_form").get(0), "h");
	height = height;
	
	$("#comment_form_wrap")
		.animate({opacity:0},0,"linear",function(){$(this).css("visibility","hidden")})
		.height( 0 )
		.animate({height:height},600,"linear",function(){$(this).css("visibility","")})
		.animate({opacity:1},600);
	$('#comment_write_link').html('<a href="javascript:void(0)" onclick="return cancel_write()">&raquo; never mind</a>');
}
function cancel_write(){
	$('#comment_write_link').html('<a href="javascript:void(0)" onclick="return write_comment()">&raquo; write your comment</a>');

	var height = jQuery.data($("#comment_form").get(0), "h");
	$("#comment_form_wrap")
		.animate({opacity:0},600,'linear',function(){
			$(this)
				.css("visibility","hidden")
				.animate({height:0},600,'linear',function(){ $(this).css("display","none"); });
		});
	
	$("#comment").val("").blur();
	$("#comment_summary").val("").blur();
	$("#comment_errors")
		.animate({opacity:0},400)
		.animate({height:0},400,'linear',function(){
			$(this)
				.empty()
				.remove();
		});
}
function submit_comment(form){
	if( ! is_user_logged && comment_strict_user ){
		alert('You need to be logged in before you can submit your comment.');
		return false;
	}
	if( form.agree.checked && form.comment.value && form.comment_summary.value ){
		if( new_comment && new_comment(form) )
			return false;

		return false;
	}else{
		if( ! form.comment.value ){
			alert('You can\'t submit without your comment.');
			form.comment.focus();
		}else if( ! form.comment_summary.value ){
			alert('You don\'t have a summary, title or the like?');
			form.comment_summery.focus();
		}else if( ! form.agree.checked ){
			alert('Have you read the guidelines for posting comments?');
			form.agree.focus();
		}
		return false;
	}
}
function change_comment_page(page){
	comment_page(page,{
		callback:'jc_morecomment_game_get',
		relation:'game',
		rel_id:game_primkey,
		cpp: comments_per_page,
		url: comment_url
	},'comment_container');
	
	return false;
}

var flagged_comments = [];
function flag_this_comment( comment_id, flag ){
	if( ! is_user_logged && comment_strict_user_flag ){
		alert('You need to log in to flag comments.');
		return false;
	}
	for( var i in flagged_comments )
		if( flagged_comments[i] == comment_id ) return false;

	flagged_comments.push(comment_id);
	if( flag_comment(comment_id, flag) ){
		if( flag == 1 ){
			$("#comment-flagup-"+comment_id).addClass("flagged").attr("title","You have given this comment a star.");
			$("#comment-flag-"+comment_id).empty().remove();
		}else if( flag == -1 ){
			$("#comment-flagup-"+comment_id).empty().remove();
			$("#comment-flag-"+comment_id).addClass("flagged").attr("title","You have already flagged this comment,\n it is awaiting admin moderation.");
		}
	}
	
	return true;
}

var hs_reload_url = null;
var hs_reload_highscores_hash = null
var hs_gameid = null;
var hs_reload_hash = null;
function reload_highscores(){
	if( ! hs_reload_url || ! hs_gameid || ! hs_reload_hash ){ alert(); return false; }
	
	var ajax_data = {
		url: hs_reload_url +'?nocache='+ Math.random(),
		type: "POST",
		data: { gameid: hs_gameid, hash: hs_reload_hash },
		dataType: 'xml',
		timeout: 30000,
		complete:function(){},
		success: function(data, status){
			var xml = $(data);
			var prompt_msg = xml.find('prompt').text();
			var error_no = parseInt( xml.find("error").text() );
			var status_no = parseInt( xml.find("status").text() );
			if( typeof(error_no) == 'undefined' ) return
		
			if( error_no ){
				if( prompt_msg )
					alert( prompt_msg );
			}
			xml.find("replacehtmlid").children("*").each(function(){
				if( this.tagName == 'script' ){
					$(this).children("*").each(function(){
						eval( $(this).text() );
					});
				}else
					$("#"+ this.tagName).html( $(this).text() );//.empty().remove();
			});
		},
		error: function(data, status, e){
			if( status == 'timeout' )
				alert( "Server was taking too long to respond.\nThe request may have been submitted but a response wasn't recieved.\nPlease try again later or refresh the page." );
			else if( status )
				alert( "["+ e.number +"] "+ e.message +"\n"+ status +"..");
		}
	}
	if( jQuery.active < 3 ){
		$.ajax( ajax_data );
	}else
		alert("Another request is being sent, please try again later.");
	
}

chalngr_prompt = function(){
//	var h = $("#chalngr_prompt_content").height() + 34;
	var p = $("#chalngr_prompt").show();
	var h = p[0].offsetHeight;
	p.hide().height(0).show()
		.animate({height:0},2000)
		.animate({height:h},400);
}

chalngr_prompt_out = function(){
	$("#chalngr_prompt")
		.animate({height:0},400,"linear", function(){
			$(this).hide();
		})
}



