//var moving;	

function moveIt(element, time, distance, direction) {
	element.animate({
	    top: direction+'='+distance
	},time);
}

$(document).ready(function() {
	
	var distanceFromTop;
	var distanceFromBottom;
	var upTimer;
	var downTimer;
	var thisHeight;
	
	$('.project-col').each(function() {
		thisHeight = 0;
		i = 0
		$(this).find('.slider-content .project-counter').each(function() {
			i++;
		});
		i--;
		i--;
		i--;
		thisHeight = i*109;
		$(this).attr('data-height', thisHeight);
	});
	
	$('.slider-up').live('mouseover mouseout', function(event) {
		thisHeight = $(this).parent().attr('data-height');
		distanceFromTop = $(this).attr('data-distance');
	    if (event.type == 'mouseover') {
	    	var _this = $(this);
	        upTimer = setInterval(function() {
	        	if(distanceFromTop <= -5) {
	        		distanceFromTop = _this.attr('data-distance');
	        		newDist = Number(distanceFromTop) + 5;
	            	moveIt(_this.parent().find('.slider-content'),100,5,'+');
	            	_this.attr('data-distance', newDist);
	           }
	        }, 100);
	    }
	    else {
	        clearInterval(upTimer);
	    }
	});
	$('.slider-down').live('mouseover mouseout', function(event) {
	    if (event.type == 'mouseover') {
	    	var _this = $(this);
	    	distanceFromTop = $(this).parent().find('.slider-up').attr('data-distance');
	        downTimer = setInterval(function() {
	        	if(distanceFromTop <= 5 || distanceFromTop == 'none') {
	        		distanceFromTop = _this.parent().find('.slider-up').attr('data-distance');
	        		if(distanceFromTop == 'none') {
						distanceFromTop = 0;
					}
					thisHeight = _this.parent().attr('data-height');
					negthisHeight = thisHeight * -1;
	        		//console.log(negthisHeight+' - '+distanceFromTop)
	        		if(negthisHeight < distanceFromTop) {
		            	newDist = distanceFromTop - 5;
		            	moveIt(_this.parent().find('.slider-content'),100,5,'-');
		            	_this.parent().find('.slider-up').attr('data-distance', newDist);
	            	}
	           }
	        }, 100);
	    }
	    else {
	        clearInterval(downTimer);
	    }
	});
	
	$('body').css({'display':'none'});
	$('body').css({'display':'block'});
	
});

