var popupStatus = 0;
function konkurs() {
	
		$('#comments .comment .answer').click(function(){
		var id = $(this).attr('id');
		var matches = id.match(/^comm-([0-9]+)$/);
		$('#commentid').val(matches[1]);
		$('#commentform').appendTo($(this).parent().parent());
		$('#commentform textarea:first').focus();
		return false;
	});
	
	$('#addcomm').click(function(){
		$('#commentid').val(rootcomm);
		$('#commentform').appendTo('#comment_form_default');
		$('#commentform textarea:first').focus();
		return false;
	});
	
	
	
		$('#comment_text').keypress(function(e){
				if((e.ctrlKey) && ((e.keyCode == 0xA)||(e.keyCode == 0xD)))    {
					$('#comment_submit').click();
										
				}
		});
				
	$('a.editcomment').click(function(){
		var id = $(this).attr('id')+'';
		var matches = id.match(/edit([0-9]+)$/);
		id = matches[1];
		show_message(id);

		return false;
	});
	$('#messageClose').click(function() {
		hide_message();
		return false;
	});
	$("#backgroundPopup").click(function(){
		hide_message();
		return false;
	});
}

function show_message(id){
	if(popupStatus==0){
		center();
		//loading data
		$('#replytext').val($('#ctext'+id).text()); /* for FF3 */
		$('#replytext').text($('#ctext'+id).text());
		$('#cid').val(id);
		//showing message
		$("#backgroundPopup").css({
		"opacity": "0.7",
		"filter": "alpha(opacity=70)"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#message").fadeIn("slow");
		popupStatus = 1;
		$('#message').css('top', ($(window).scrollTop()+200)+'px');
		$(document).keypress(function(e){
			if(e.keyCode==27){
				hide_message();
			}
		});
	}
}



function hide_message() {
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#message").fadeOut("slow");
		popupStatus = 0;
		$(document).unbind('keypress');
	}
}

function center(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#message").height();
	var popupWidth = $("#message").width();
	$("#message").css({
	"position": "absolute",
	"top": windowHeight/2-popupHeight/2,
	"left": windowWidth/2-popupWidth
	});

	$("#backgroundPopup").css({
	"height": windowHeight
	});
}

