// 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 = 7;
var pos = 0;
$(document).ready(function() {

	slides = $(".slide").size();
	width = $(".slide").width();
	total_width = width * slides;
	
	$("#slides_wrapper").css("width",( (width * show) - 20 ) + "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);
			}
		}
	}
	
	//Down
	function MoveDown() {
		hw = $("#slides_wrapper").css("height");
		hw = parseFloat(hw);
		hh = $(".slide:eq("+ (cur_slide - 1) +")").css("height");
		hh = parseFloat(hh);
		move = hh - hw;
		if ((hh > hw) && (pos == 0))
		{
			$("#slider").animate({ "top" : "-=" + move + "px" }, "slow");
			pos = pos + 1;
		}
	}

	//Up
	function MoveUp() {
		top_pos = $("#slider").css("top");
		top_pos = parseFloat(top_pos);
		top_pos = top_pos * (-1);
		if (pos == 1)
		{
			$("#slider").animate({ "top" : "+=" + top_pos + "px" }, "slow");
			pos = 0;
		}
		}
	
	
	$("#next").click(function(event) {
		event.preventDefault();	
		MoveUp();
		MoveNext();
		
	});
	
	$("#prev").click(function(event) {
    	event.preventDefault();	
		MoveUp();
		MovePrev();	
	});
	
	
	$("#down").click(function(event) {
		MoveDown();
	});
	
	$("#up").click(function(event) {
		MoveUp();
	});
	
	
});


/* Pop up  */

var last = '';

function OSPopUp(lyr) {
	if (last != '')
		{
			$(last).fadeOut("slow");
		}
	
	if ( ($(lyr).css("display") == 'block') ) {
			$(lyr).fadeOut("slow");
			last = '';
		}
	else {
		$(lyr).fadeIn("slow");
		last = lyr;
		}
	}
	

/* AJAX */

function LoadPage(filename){
	
	
	$.ajax({
  url: filename,
  cache: false,
  success: function(html){
    $("#results").html(html);
  }
});
	
	}
