$(document).ready(function() {
	var btn_prev = $(".prev"),
		btn_next = $(".next"),
		portfolio_list = $("div.portfolio-slider-container ul.portfolio"),
		li_count = $("div.portfolio-slider-container ul.portfolio").children("li").length,
		li_showed_count = 2,
		li_width = 218,
		li_now = 0;
	
	smooth_out();
		
	btn_prev.click(function() {
		slide("left");
		return false;
	})
	
	btn_next.click(function() {
		slide("right");
		return false;
	})
	
	function slide(direction) {
		if (direction == "right") {
			var slide_width = "-=" + li_width;
			li_now++;
		} 
		else {
			var slide_width = "+=" + li_width;
			li_now--;
		}
		portfolio_list.animate({ marginLeft: slide_width }, 300);
		
		smooth_out();
		
		return false;
	}
	
	function smooth_out() {
		if (li_now <= 0) {
			btn_prev.hide();
		}
		else {
			btn_prev.show();
			
			if (li_count - li_now < li_showed_count + 1)
				btn_next.hide();
			else
				btn_next.show();
		}
	}
})
