var maxHeight = 720;
var moveHeight = 240;
var in_animation = false;

function scrollDivInit()
{
	if ($('div.scroll-div').length > 0) {
		hgt = $('div.scroll-div > div').height();
		
		if (hgt > maxHeight) {
		
			$('div.scroll-div').before('<div class="prev-div"><div class="in-active"></div></div>');
			$('div.scroll-div').after('<div class="next-div"><div class="in-active"></div></div>');
			
			$('div.scroll-div > div').css({'position' : 'absolute', 'top' : '0px', 'left' : '0px'});
			
			$('div.prev-div > div').bind('mouseover', mover);
			$('div.next-div > div').bind('mouseover', mover);
			$('div.prev-div > div').bind('mouseout', mout);
			$('div.next-div > div').bind('mouseout', mout);
			$('div.prev-div > div').bind('click', movePrev);
			$('div.next-div > div').bind('click', moveNext);
		}
	}
}

function mover()
{
	dtop = $('div.scroll-div > div').css('top');
	dtop = dtop.replace('px', '');
	hgt = $('div.scroll-div > div').height();
	move = false;
	if ($(this).parent().hasClass('prev-div')) {
		if (dtop < 0) {
		  move = true;
		}
	} else {
		if ((hgt + (parseInt(dtop) - parseInt(moveHeight))) >= maxHeight) {
			move = true;
		}
	}
	if (move) {
		$(this).removeClass('in-active');
		$(this).addClass('active');
	}
}

function mout()
{
	if ($(this).hasClass('active')) {
		$(this).removeClass('active');
		$(this).addClass('in-active');
	}
}

function movePrev()
{
	if (in_animation) {
		return;
	}
	dtop = $('div.scroll-div > div').css('top');
	dtop = dtop.replace('px', '');
	move = false;
	if (dtop < 0) {
		move = true;
	}
	
	if (move) {
		in_animation = true;
		dtop = $('div.scroll-div > div').css('top');
		dtop = dtop.replace('px', '');
		newTop = parseInt(dtop) + parseInt(moveHeight);
		$('div.scroll-div > div').animate({'top' : newTop+'px'}, 'slow', function () {in_animation = false;});
	}
}

function moveNext()
{
	if (in_animation) {
		return;
	}
	dtop = $('div.scroll-div > div').css('top');
	dtop = dtop.replace('px', '');
	hgt = $('div.scroll-div > div').height();
	move = false;
	if ((hgt + (parseInt(dtop) - parseInt(moveHeight))) >= maxHeight) {
		move = true;
	}
	
	if (move) {
		in_animation = true;
		dtop = $('div.scroll-div > div').css('top');
		dtop = dtop.replace('px', '');
		newTop = parseInt(dtop) - parseInt(moveHeight); 
		$('div.scroll-div > div').animate({'top' : newTop+'px'}, 'slow', function () {in_animation = false;});
	}
}

