/*
***
Recent References Slider
by Jan Tackmann
***
*/

var offsetCount = 1;
var offsetImagesStatic = -575;
var offsetImages = offsetImagesStatic;
var offsetMaxCount = 3;

openInfo();
startTimer();

function startTimer() {
	time = offsetMaxCount;
	$(document).everyTime(8200, function() {
	  nextItem(); 
	}, time);
};	


function nextItem() {
	if(offsetCount < offsetMaxCount){ 
			$("#references_container").animate({ left : offsetImages }, 500	);
			offsetCount = offsetCount + 1;	
			offsetImages = offsetImagesStatic * offsetCount;	
			//$(".ref_info").animate({ bottom: -40 }, 10, function() { openInfo(); });
		} else {
			/*
			$(".btn-prev").css("display","block");
			$(".btn-next").animate({ 
      		"opacity": "toggle" 
			}, { duration: "slow" });
			$(".btn-prev").animate({ 
      		opacity: 1
			}, { duration: "slow" });
			*/
			//$(".reference-last").css("display","block");
			$("#references_container").animate({ left : 0 }, 500, function() {
				offsetImages = offsetImagesStatic;
				offsetCount = 1;
				startTimer();
			});
	};	
};

function openInfo() {
	$(".ref_info").delay(800).animate({
		bottom: 0 },
		{ duration: 500,
		specialEasing: {
			width: 'linear',
			height: 'easeOutBounce' }
		}
	);
};

$(".btn-ref-reset")
	 .click(function(){
			$("#references_container").animate({ left : 0 }, 300 );
			offsetImages = offsetImagesStatic;
			offsetCount = 1;
			startTimer()
			$(".btn-next").animate({ opacity: 1 });
			$(".btn-ref-info").animate({ opacity: 1 });
			$(".reference-last").animate({ opacity: 0 }, 300,
			function(){	
					$(".reference-last").css("display","none");	
			});
});		 


$(".btn-prev")
	 .click(function(){	
			$("#references_container").animate({ left : offsetImages - 575 }, 300,
				function(){  
					$(".btn-next").animate({ "opacity": "toggle" }, { duration: "slow" }),
					$(".btn-prev").animate({ opacity: 0 }, 100),
					$(".btn-prev").css("display","none");
				}
			);
			offsetCount = 1;	
			offsetImages = -575;						
});

var opacitystatus = true;

$(".btn-ref-info")
	 .click(function(){
			if( opacitystatus == true){
				$(".btn-ref-info").animate({ 
      			"opacity": "0" }, { duration: "slow" });
				$(".ref_info").animate({ 
      			"opacity": "1" }, { duration: "slow" });
				opacitystatus = false;
			} else {
				$(".btn-ref-info").animate({ 
      			"opacity": "1" }, { duration: "slow" });
				$(".ref_info").animate({ 
      			"opacity": "0" }, { duration: "slow" });
				opacitystatus = true;	
			}		
});

$(".btn-ref-info").toggle(
    function() {
        $(this).addClass('btn-ref-info-close');
    },
    function() {
        $(this).removeClass('btn-ref-info-close');
    }
);

$(".btn-ref-info-close")
	 .click(function(){
			if( opacitystatus == true){
				$(".btn-ref-info").animate({ 
      			"opacity": "0" }, { duration: "slow" });
				$(".ref_info").animate({ 
      			"opacity": "1" }, { duration: "slow" });
				opacitystatus = false;
			} else {
				$(".btn-ref-info").animate({ 
      			"opacity": "1" }, { duration: "slow" });
				$(".ref_info").animate({ 
      			"opacity": "0" }, { duration: "slow" });
				opacitystatus = true;	
	}	
});

