$(document).ready(function(){
	$(".delicious").hide();
	$("a.enlarge").fancybox({ 'titleShow':false });
	$("a.caljax").click(function(){
		$.fancybox({
			'href':'/cal-event.php?id=' + this.href.replace(/^.*#e([0-9]+)$/,"$1"),
			'hideOnContentClick':false,
			'scrolling':'no'
		});
		$.fancybox.resize();
		return false;
	});
	$(".grid tr").mouseover(function(){
		$(this).addClass("over");
	 });
	$(".grid tr").mouseout(function(){
		$(this).removeClass("over");
	 });
	$(".grid tr:even").addClass("alt");
	$("form").submit(function() {
		//var e = $(this).children("input[name=token]").val();
		// $(this).children("input[name=token]").val(parseInt(e).toString(16));
		//var tok = '<input type="hidden" name="token" value="' + parseInt(e).toString(16) + '" />';
		//$(this).append(tok);
		// $(this).children("input[name=token]").val("test");
		$(this).attr("action",$(this).attr("action").replace(/^\/honey/i,""));
		// $("input[type=submit]", this).attr("value","Please Wait...");
		$("input[type=submit]", this).attr("disabled","disabled");
		return true;
	});
	$("#addphoto a").click(function(){
		$("#photoinput").show();
		$("#addphoto").hide();
		return false;
	});
	$("a.report").click(function(){
		var self = this;
		jPrompt("Why are you reporting this post?","","Reason", function(r) {
			if (r && r != 'undefined') {
				$.post($(self).attr('href'), { p: $(self).parents(".thread").attr("id"), s: "report", reason: r }); 
				$(self).replaceWith("<b>Reported!</b>");
				return false;
			}	
		});
		return false;
	});
	$("a.moderator").click(function(){
		var self = this;
		if ($(this).text() == 'Approve') {
			$.post($(this).attr('href'), { p: $(this).parents(".thread").attr("id"), s: "" } ); 
			$(this).parents(".thread").removeClass("mod");
			$(this).replaceWith("<b>Saved</b>");
		} else if ($(this).text() == 'Ignore') {
			$.post($(this).attr('href'), { p: $(this).parents(".thread").attr("id"), s: "" } ); 
			$(this).parents(".thread").removeClass("report");
			$(this).replaceWith("<b>Saved</b>");
		} else if ($(this).text() == 'Sticky') {
			$.post($(this).attr('href'), { p: $(this).parents(".thread").attr("id"), s: "sticky" }); 
			$(this).replaceWith("<b>Saved</b>");
			return false;
		} else if ($(this).text() == 'UnSticky') {
			$.post($(this).attr('href'), { p: $(this).parents(".thread").attr("id"), s: "" }); 
			$(this).replaceWith("<b>Saved</b>");
			return false;
		} else if ($(this).text() == 'Disable') {
			jPrompt("Why was this post deleted?","","Moderation", function(r) {
				if (r && r != 'undefined') {
					$(self).parents(".thread").find(".modNote").html(r);
					$.post($(self).attr('href'), { p: $(self).parents(".thread").attr("id"), s: "disable", reason: r }); 
					$(self).parents(".thread").addClass("disable");
					$(self).replaceWith("<b>Saved</b>");
					return false;
				}	
		   });
		} else if ($(this).text() == 'Lock') {
			jPrompt("Why was this post locked?","","Moderation", function(r) {
				if (r && r != 'undefined') {
					$(self).parents(".thread").find(".modNote").html(r);
					$.post($(self).attr('href'), { p: $(self).parents(".thread").attr("id"), s: "lock", reason: r }); 
					$(self).replaceWith("<b>Saved</b>");
					return false;
				}	
		   });
		}
		return false;
  	});
	$("#modreadmore").click(function(){
		if($('#modinfo').css('display') == "none")
			$("#modinfo").show('slow');
		else
			$("#modinfo").hide('slow');
		return false;
  	});
	/*
	if($("#message").val() == ""){
		$("#message").val("Write a comment...");
		$("#message").css("color","#999");
	}
	$("#message").focus(function(){
		if(this.value == 'Write a comment...'){
			$(this).val("");
			$(this).css("color","#000");
		}
	});
	$("#message").blur(function(){
		if(this.value == ''){
			$(this).val("Write a comment...");
			$(this).css("color","#999");
		}
	});
	*/
	// countdown = setInterval('countdownclock()', 100)
});

function countdownclock(){
	var cur = parseFloat($("#countdown").html()) - 0.1;
	if(cur >= 0){
		$("#countdown").html(cur.toFixed(1));
	}else{
		clearInterval(countdown);
	}
}
