$(document).ready(function(){

	var distance = '200px'; //How far I want the thing to move in one direction
	var scroll_speed = 500; //Speed in ms
	var fade_speed = 300; //for pop up and images
	var moving_piece = '#timeline'; //The item I want to move
	var timeline = $("#timeline");
	var full_size_src = "images/lrg/"; //Source of all the large images
    var loop = '';
	//The two arrows move the div across the screen
		$('#left_arrow').click(function(){
			var timeline_offset = timeline.offset();
			if(timeline_offset.left <= 20){
				$(moving_piece).animate({marginLeft: '+='+distance},scroll_speed);
			}
			//var timeline_offset = timeline.offset()+distance;
		});

	$('#right_arrow').click(function(){

			var timeline_offset = timeline.offset();
		    if(timeline_offset.left >= -1210){
			$(moving_piece).animate({marginLeft: '-='+distance},scroll_speed);
			}
	});

    $('#right_arrow').mouseout(function(){
         CeaseScroll();
    });

	$('#left_arrow').mouseout(function(){
          CeaseScroll();
		});


    function CeaseScroll(){
   // alert('test');
    loop=false;
    if(timer)
    clearTimeout(timer);
}

	//Animates when user clicks an image and puts on top of links
	$("#timeline a").click(function(){
		var img_src = $(this).attr("title");
		var next_img = $(this).next().attr("title");
		var prev_img = $(this).prev().attr("title");
		$("#popup").stop().fadeTo(fade_speed, 0.7).fadeIn(0).css({zIndex:"4"});
		$('#img_container').stop().animate({marginLeft:"0"},fade_speed-100).fadeIn(fade_speed+700).css({zIndex:"5"}).empty().append("<img src='"+full_size_src+img_src+'.png'+"' />");
		$('#drop_shadow').stop().animate({marginLeft:"0"},fade_speed-200).fadeIn(fade_speed+1500).css({zIndex:"3"});
		$('#close_btn').stop().animate({marginLeft:"0"},fade_speed+500).fadeIn(fade_speed+500).css({zIndex:"7"});
		/*
		//Next and previous lightbox buttons
		$('#lightbox_right').click(function(){
			$('#img_container').empty().append("<img src='"+full_size_src+next_img+'.png'+"' />");
		});

		//Next and previous lightbox buttons
		$('#lightbox_left').click(function(){
			//var picture_id = $("#picture_id").value;
			$('#img_container').empty().append("<img src='"+full_size_src+prev_img+'.png'+"' />");
		});
		 */
		//Closes the pop up and puts the box underneath links
		$('#close_btn').click(function(){
			$('#popup').stop().fadeOut(fade_speed);
			$('#img_container').stop().fadeOut(fade_speed);
			$('#drop_shadow').stop().fadeOut(fade_speed);
			$('#close_btn').stop().fadeOut(fade_speed);
		});
		$(document).pngFix();
	});
});
