// JavaScript Document
var moving = false;
function previousReel()
{
	if($('#sampleReels ul li:first').position().top > -1 * (145 * ($('#sampleReels ul li').size() - 2)) && !moving)
	{
		moveReel(-1)
	}
}
function nextReel()
{
	if($('#sampleReels ul li:first').position().top < 0 && !moving)
	{
		moveReel(1)
	}
}
function moveReel(dir)
{
	moving = true
	$('#sampleReels ul li').css('position','relative');
	$('#sampleReels ul li').each
	(
	 function(i)
	 {
		var curTop = Number($(this).css('top').replace('px',''));
	 	var newTop = curTop + (dir * 145);
		$(this).animate({top: newTop + 'px'},500,'swing',function(){finalizeMove($(this),newTop)});
	 }
	 )
}
function finalizeMove(reel,pos)
{
	reel.css('top',pos);
	if(reel[0] == $('#sampleReels ul li:last')[0])
	{
		moving = false;	
	}
}
function startReelsAtLink()
{
	$('#sampleReels ul li').css('position','relative');
	var script = window.location.href.replace("http://" + window.location.host,'');
	var currentReel = $("#sampleReels ul a[href $= '" + script +"'],#sampleReels ul a[href $= '" + script.concat("#video") +"']");
	
	if(currentReel.length > 0)
	{
		var pos = currentReel.parent().position().top;
		$("#sampleReels ul li").css('top',-1 * pos);
	}
}

$(document).ready
(
 function()
 {
	 startReelsAtLink()
 }
 )
