$(document).ready(function() {
$("form .avatar").click(function(){
	$(".avatar").removeClass("avatar-selected");
	$(this).addClass("avatar-selected");
	var name = ($(this).attr("for"));
	$("input#"+name).attr("checked","checked");
});	
$(":radio").hide();

$("form .smileys img").click(function(){
var emo = $(this).attr("alt");							
$("form textarea").val($("form textarea").val() + emo); 		 
});

$(".spoiler p").hide();

$(".spoiler").click(function(){

$(this).children().slideDown("slow");	
$(this).children().addClass("visible");
	 return false;
});

function checkKey(e){
	     switch (e.keyCode) {
	        case 37:
	            navigate('previous');
	            break;
	        case 39:
	            navigate('next');
	            break;
	            }      
	};

	if ($.browser.mozilla) {$(document).keypress (checkKey);} 
	else {$(document).keydown (checkKey);}

	
	function navigate(direction)
	{
		var directionMap = {
				next: $("#nextLink").attr("href"),
				previous: $("#prevLink").attr("href")			
		}
		
		if (directionMap[direction] != undefined)
		{
			window.location.pathname = directionMap[direction];
		}
		
	};


});
