$(document).ready(function() {

	/* parameters */
	
		var tenthings_current_frame = 0;
	
	
	/* bind each thumbnail in grid to initiate overlay, jump to frame */
	
		$('.tenthings_list li').click(function() {
			jump_to_frame($(this).data('tenthings_frame_index'));
		});

	/* bind left/right arrows to shift frames */
	
		$('#tenthings-arrow-left').unbind('click').bind('click',function(){
			tenthings_current_frame -= 1;
			if(tenthings_current_frame < 0 ) tenthings_current_frame = 0;
			jump_to_frame(tenthings_current_frame);
		});
		
		$('#tenthings-arrow-right').unbind('click').bind('click',function(){
			tenthings_current_frame += 1;
			if(tenthings_current_frame > 9 ) {
				tenthings_current_frame = 0;
			}
			jump_to_frame(tenthings_current_frame);
		});
	
	/* perform slideshow shifting */
	
		function jump_to_frame(i) {
			tenthings_current_frame = i;
			var destination = $('#tenthings_strip li:nth-child('+(i+1)+')').position().left * -1;
			$('#tenthings_strip').css('left',destination+'px');
			if(tenthings_current_frame == 0)
				$('#tenthings-arrow-left').css('opacity',0);
			else $('#tenthings-arrow-left').css('opacity',1);
						
			$('.tenthings_list li').removeClass('active');
			$('#tenthings_link_'+i).addClass('active');
		}
	
});

