$(document).ready(function(){

	//$("#sidebar").animate({right:100,top:30},1000)
	
	$(".post_block img").wrap("<span class=\"off\"></span>");
	var block_show;
	var block_name;
	var picWidth = [];
	var j;
	var n;
	var moveX;
	$("#sidebar a").click(function(){
								   //$("#sidebar").animate({right:100,top:30},1000)
								   $("#sidebar .menu_btn").css({visibility:"hidden"});
								   $("#"+ $(this).attr("class")).find("span").removeClass("off").addClass("on");	
								   block_show = "#" + $(this).attr("class");
								   $(this).css({ background:"#CCCCCC" })
								   //alert(block_show);
								   setTimeout(showpic,2000);
								   block_name = $(this).attr("class");
								   j = 0;
								   n = 0;
								   moveX = 0;
								   $("#" + block_name).animate({left: 0 },1000)
								   $("#" + block_name + " img").each(function(i){
															picWidth[i]= $(this).width();	
															//alert(picWidth[i]);
																			  })
								   n = $("#" + block_name + " img").size();
								   //alert(n);
								   $(this).next().css({visibility:"visible"});
								   })
	function showpic() {
		$(block_show + " img").each(function(i){
																						this.src = "images/" + $(this).parent().parent().parent().find("a").attr("class") + (i+1) + ".jpg"
																							 })
		}
	$(".next").click(function(){
							  //var moveX = $("#" + block_name).find("img").width();
							  //alert($("#" + block_name).css("left").substring(1,-2))
							  if (j<n) { $("#" + block_name).animate({left: moveX - picWidth[j] - 32 },1000, function(){ moveX = parseFloat($("#" + block_name).css("left"))});
							  //alert(moveX)
							 
							  j++;
							  } else j=n;
							  })
	$(".prev").click(function(){
							  //var moveX = $("#" + block_name).find("img").width();
							  //alert($("#" + block_name).css("left").substring(1,-2))
							 if (j>0) { $("#" + block_name).animate({left: moveX + picWidth[j-1] + 32 },1000, function(){ moveX = parseFloat($("#" + block_name).css("left"))});
							  //alert(moveX)
							  j--;
							  } else j=0;
							  })
	
});