var theoptions = Array();
theoptions['mostrecentlink'] = '#postsbydate',
theoptions['mostpopularlink'] = '#postsbyvote',
theoptions['mostdiscussedlink'] = '#postsbycomment'

function swapMost(switchTo) {
	for (key in theoptions) {
		$("#"+key).removeClass('mostLinkOver');
		$("#"+key).addClass('mostLink');
		$(theoptions[key]).css('display','none');
	}
	$("#"+switchTo).addClass('mostLinkOver');
	$(theoptions[switchTo]).css('display','block');
}

function loadConfessions(data) {
	if (data == 1) {
		$("#confessionerror").html("Your confession doesn't seem to be <em>clean</em>. Please try again.");
	} else {
		$.ajax({
			url: "view-confessions.php",
			//cache: true,
			success: function(htmlresult){
				//$("#confessions").html(htmlresult);
				//alert(htmlresult);
				document.getElementById('confessions').innerHTML = htmlresult;
			}
		});
	}
}

$(document).ready(function($) {
	loadConfessions('');
	$('textarea#confession').maxlength({'feedback' : '.charsLeft'});
	$('INPUT#confessor').focus(function () {
		if (this.value == 'Enter Your Name') this.value = '';
    });
	$(document).pngFix(); 
});

function submitConfession() {
	$.post("add-confession.php", { confessor: $('INPUT#confessor').val(), confession: $('TEXTAREA#confession').val()},function(data){ 
		if (data != 1) {
			$('INPUT#confessor').val('');
			$('TEXTAREA#confession').val('');
		}
		loadConfessions(data);
	});
	return false;
}
