var current = 1;
var direction = 1;
var last;

var timer;

$(document).ready(function(){
	last = $("#home_scroll li").size();
	$("#b_back img").hide();
	$("#b_back img").click(function(){slide(-1)});
	$("#b_next img").click(function(){slide(1)});
	
	timer = setTimeout('autoSlide()', 3000);
});

function slide(move)
{
	clearTimeout(timer);
	current += move
	
	$("#scroller ul").animate({left: (-829 * (current - 1)).toString() + 'px'}, 1500 );
		
	if (current == 1)
	{
		$("#b_back img").fadeOut();
		direction = 1;
	}else{
		if ( $('#b_back img').is(':hidden') ) {
        	$("#b_back img").fadeIn();
		};
	};
	
	if (current == last)
	{
		$("#b_next img").fadeOut();
		direction = -1;
	}else{
		if ( $('#b_next img').is(':hidden') ) {
        	$("#b_next img").fadeIn();
		};
	};
	timer = setTimeout('autoSlide()', 4500);
}

function autoSlide()
{
	slide(direction)
}
