$(function() {

	if (parseInt($("#js_expires_in_field_data").html()) > 0)
		setInterval("update_expires_field()", 1000);

	update_expires_field();
});

function update_expires_field()
{
	var diff = parseInt( $("#js_expires_in_field_data").html() );

	if (diff <= 0  )
	{
		$("#js_expires_in_field").html("Expired");
		return;
	}

	if ( !$("#js_expires_in_field_data") || ! $("#js_expires_in_field_data").html() )
		return;


	$("#js_expires_in_field_data").html(parseInt($("#js_expires_in_field_data").html()) - 1);

	var html = "";

	if(diff>31536000) html = Math.floor(diff/31536000)+' year';
	else if(diff>2419200) html = Math.floor(diff/2419200)+' month';
	else if(diff>604800) html = Math.floor(diff/604800)+' week';
	else if(diff>86400) html = Math.floor(diff/86400)+' day';
	else if(diff>3600) html = Math.floor(diff/3600)+' hour';
	else if(diff>60) html = Math.floor(diff/60)+' minute';
	else html = diff+' second';

	if ( parseInt(html) > 1 ) html+="s";

	var html2 = "";


	if(diff>31536000) html2 = "";
	else if(diff>2419200) html2 = "";
	else if(diff>604800) html2 = Math.floor(diff/86400)%7+' day';
	else if(diff>86400) html2 = Math.floor(diff/3600)%24+' hour';
	else if(diff>3600) html2 = Math.floor(diff/60)%60+' minute';
	else if(diff>60) html2 = diff%60+' second';
	else htm2 = "";


	if ( parseInt(html2) > 1 ) html2+="s";

	$("#js_expires_in_field").html("Expires in: "+html+" "+html2);
}

function filter_comments()
{
	$(".isidea").hide();
	$(".post_comment_form").hide();
	$(".post_idea_form").hide();
	$(".iscomment").show();
}

function hide_anounce(id)
{
	$("#announce_div").hide();
	$.post("http://www.ideaoffer.com/ajax/mark_as_announced.php", {
		project_id: id
	});
}

function filter_ideas()
{
	$(".iscomment").hide();
	$(".post_comment_form").hide();
	$(".post_idea_form").hide();
	$(".isidea").show();
}

function filter_both()
{
	$(".post_idea_form").hide();
	$(".post_comment_form").hide();
	$(".iscomment").show();
	$(".isidea").show();
}

function show_idea_form()
{
	$("#comments *,#report,#answers").hide();
	$(".post_comment_form").hide();
	$(".post_idea_form").show();
}

function show_comment_form()
{
	$("#comments *,#report,#answers").hide();
	$(".post_idea_form").hide();
	$(".post_answer_form").hide();
	$(".post_comment_form").show();
}

function show_answer_form()
{
	$("#comments *,#report,#answers").hide();
	$(".post_comment_form").hide();
	$(".post_answer_form").show();
}

function show_report()
{
	$('#comments *,#answers').hide();
	$(".post_comment_form").hide();
	$(".post_answer_form").hide();
	$('#report').show();
}

function show_answers()
{
	$('#comments *').hide();
	$(".post_comment_form").hide();
	$(".post_answer_form").hide();
	$('#report').hide();
	$('#answers').show();
}

function select_as_winner(id)
{
	$("#winner"+id).submit();
}

function remove_from_winners(id)
{
	$("#dewinner"+id).submit();
}

function flag_idea(id)
{
	$("#flag"+id).submit();
}

function remove_flag(id)
{
	$("#deflag"+id).submit();
}
function flag_comment(id)
{
	$("#flagc"+id).submit();
}

function remove_flag_comment(id)
{
	$("#deflagc"+id).submit();
}
