// Origami Carousel jQuery
/*

1) Set the width of the slides on the CSS (class .slide) and the #slides_wrappe
2) Add as many divs with the class slide as needed
3) DONE

*/
var cur_slide = 1;
var show = 4;
var pos = 0;
$(document).ready(function() {

	slides = $(".slide").size();
	width = $(".slide").width();
	
	total_width = width * slides;
/*	if (slides < show) {
		$("#slides_wrapper").css("width",total_width + 50 + "px");
		$("#slider").css("width",total_width + "px");
	}
	else {
		$("#slides_wrapper").css("width",(width * show) + 50 + "px");
		$("#slider").css("width",(width * show) + "px");
	}*/
	
	$("#slides_wrapper").css("width",(width * show) + "px");
	$("#slider").css("width",total_width + "px");
	
// Next
	function MoveNext() {
		if ((cur_slide + show) <= slides)
			{
			$("#slider").animate({"left" : "-=" + width + "px"}, "slow" );
			cur_slide = cur_slide + 1;
			}		
		else
			{
			left_pos = $("#slider").css("left");
			left_pos = parseFloat(left_pos);
			left_pos = left_pos * -1;
			$("#slider").animate({"left" : "+=" + left_pos + "px"}, "slow" );
			cur_slide = 1;
			}	
	}
	
	//Previous
	function MovePrev() {
		if (slides > show)
		{
		if (cur_slide != 1)
			{
			$("#slider").animate({"left" : "+=" + width + "px"}, "slow" );
			cur_slide = cur_slide - 1;
			}		
		else
			{
			$("#slider").animate({"left" : "-=" + width * (slides - show) + "px"}, "slow" );
			cur_slide = slides - (show - 1);
			}
		}
	}
	

	$("#next").click(function(event) {
		event.preventDefault();	
		MoveNext();
		
	});
	
	$("#prev").click(function(event) {
    	event.preventDefault();	
		MovePrev();	
	});
	
	
	
});



