$(document).ready(function() {

	var currImg = 0;
	var imgArray = $(".post:first .images .image");
	$(imgArray[currImg]).show();
	
	$("#post_list").accordion({autoHeight: false}).bind('accordionchangestart',function(e, ui){
		imgArray = ui.newContent.find(".image");
		if(imgArray.length > 0) {
			ui.newContent.find(".control.left").hide();
			ui.newContent.find(".control.right").show();
			currImg = 0;
			$(imgArray).hide();
			$(imgArray[currImg]).show();
		}
	});
	
	$(".addComment").click(function(){
		$(this).hide();
		$("#comment_form").fadeIn("fast");
	});
	
	$(".control:not(.inactive)").mouseenter(function(){

		$(this).children(".arrow").css('filter','alpha(opacity=100)');
		$(this).children(".arrow").css('-moz-opacity','1');
		$(this).children(".arrow").css('-khtml-opacity','1');
		$(this).children(".arrow").css('opacity','1');

	}).mouseleave(function(){

		$(this).children(".arrow").css('filter','alpha(opacity=46)');
		$(this).children(".arrow").css('-moz-opacity','0.46');
		$(this).children(".arrow").css('-khtml-opacity','0.46');
		$(this).children(".arrow").css('opacity','0.46');

	}).click(function(){
		if($(this).hasClass("left")) {
			$(".control.right:hidden").show();
			if(currImg == 1) {
				$(this).hide();
			} else {
				
			}
			currImg --;
		} else {
			$(".control.left:hidden").show();
			if(currImg == ($(imgArray).length)-2) {
				$(this).hide();
			} else {
				
			}
			currImg ++;
		}
		$(this).siblings(".image").hide();
		$(imgArray[currImg]).show();
	});
	
});

function charConv(str){
	var strOut = "";
	for(i=0;i<str.length;i++) {
		strOut += String.fromCharCode(str.charCodeAt(i));
	};
	return strOut;
}