jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$.easing.elasout = function(x, t, b, c, d) {
	var s=1.70158;var p=0;var a=c;
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};

$(document).ready(function(){

	$('div#related_videos_container').serialScroll({
		prev:'#up',
		next:'#down',
		items:'div#related_video',
		//start:0, //as we are centering it, start at the 2nd
		duration:1200,
		offset:0,
		axis:'y',
		force:true,
		stop:true,
		lock:false,
		easing:'easeOutQuart', //use this easing equation for a funny effect
		step:1,
		cycle:false, //don't pull back once you reach the end
		onBefore:function(e, elem, $pane, $items, pos){
			
			var total_videos = $('div#app_video_related_videos').html();
			if(total_videos - 3 == pos)
			{
				$('img#down').hide();
				$('img#down_image').show();
			}
			else
			{
				$('img#down').show();
				$('img#down_image').hide();
			}
		}
	});

	$('div#videos_container').serialScroll({
		prev:'#prev',
		next:'#next',
		items:'div#video_item',
		offset:-492, //when scrolling to photo, stop 230 before reaching it (from the left)
		//start:0, //as we are centering it, start at the 2nd
		duration:1200,
		axis:'x',
		force:true,
		stop:true,
		lock:false,
		easing:'easeOutQuart', //use this easing equation for a funny effect
		step:4,
		cycle:false, //don't pull back once you reach the end
		//jump: true //click on the images to scroll to them

		onBefore:function(e, elem, $pane, $items, pos){
			/**
			 * 'this' is the triggered element
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			//if(pos == 4)
			var total_videos = $('div#app_home_top_video').html();

			if(pos == 0)
			{
				$('#prev').hide();
				$('#prev_text').show();
			}
			else
			{
				$('#prev').show();
				$('#prev_text').hide();
			}

			if(total_videos == pos+4)
			{
				$('#next').hide();
				$('#next_text').show();
			}
			else
			{
				$('#next').show();
				$('#next_text').hide();
			}

		}

	});

});
