// Original code - Chris Boyle
// 10.06.2008
// Shamelessly borrowed with permission

jQuery.easing.def = "easeInOutCirc";

var current_page;

$(document).ready(function(){
	
	var total_width = 0;
	$('.ind_strip').each(function(){
		total_width += $(this).width();
	});
	
	var badges_total_width = 0;
	$('.badges_ind_strip').each(function(){
		badges_total_width += $(this).width();
	});
	
	current_page = 1;
	
	//get width of gallery	
	var distance = $('#featured_goals').width();	
	var badges_distance = $('#my_badges_divvy').width();
	

	$('a#prev_slide').click(function(){
		slide(distance, total_width);
		return false;
	});
	
	$('a#next_slide').click(function(){
		slide("-"+distance, total_width);
		return false;
	});	
	
	$('a#badges_prev_slide').click(function(){
		badges_slide(badges_distance, badges_total_width);
		return false;
	});
	
	$('a#badges_next_slide').click(function(){
		badges_slide("-"+badges_distance, badges_total_width);
		return false;
	});	
});

function slide(distance, total_width)
{
	//get total pages
	var total_pages = total_width / Math.abs(distance);
	
	//get current margin left
	var marginleft = $('#stripholder').css("margin-left");	
	
	if(current_page == 1 && distance > 0)
	{
	 	$('#stripholder').animate({"marginLeft": "-"+ (total_width - Math.abs(distance)) + "px" }, 500);
	 	current_page = total_pages;
	}
	else if(current_page == total_pages && distance < 0)
	{
		$('#stripholder').animate({"marginLeft": "0px"}, 500);
		current_page = 1;
	}
	else
	{
		$('#stripholder').animate({"marginLeft": "+="+distance}, 500);
		if(distance > 0)
		{
			current_page--;
		}	
		else
		{
			current_page++;
		}		
	}	
}

function badges_slide(distance, total_width)
{
	//get total pages
	var total_pages = total_width / Math.abs(distance);
	
	//get current margin left
	var marginleft = $('#badges_stripholder').css("margin-left");	
	
	if(current_page == 1 && distance > 0)
	{
	 	$('#badges_stripholder').animate({"marginLeft": "-"+ (total_width - Math.abs(distance)) + "px" }, 500);
	 	current_page = total_pages;
	}
	else if(current_page == total_pages && distance < 0)
	{
		$('#badges_stripholder').animate({"marginLeft": "0px"}, 500);
		current_page = 1;
	}
	else
	{
		$('#badges_stripholder').animate({"marginLeft": "+="+distance}, 500);
		if(distance > 0)
		{
			current_page--;
		}	
		else
		{
			current_page++;
		}		
	}	
}
