var interval = null;
var idx = 0;
var idx1 = 0;

$(document).ready(function() 
{
	$.scrollTo.defaults.axis = 'x';
	$.scrollTo.defaults.queue = false;
	$.scrollTo( 0 );
	$('#sections').scrollTo( 0 );

	$(".rb_title_off").mouseover(function(){
		window.clearInterval( interval );
		el = $(this);
		idx1 = $('#mn2 li').index(this);
		if ( idx != idx1 ) interval = window.setInterval("moveLeft(el)", 650);
	}).mouseout(function(){
		window.clearInterval( interval );
	});

	$(".prev").click(function(){
		window.clearInterval( interval );
		moveNext(-1);
	});

	$(".next").click(function(){
		window.clearInterval( interval );
		moveNext(+1);
	});

	moveNext(0);
});

function moveNext(d)
{
	idx = idx + d;
	window.clearInterval( interval );

	if ( idx < 0 ) idx = 5;
	if ( idx > 5 ) idx = 0;

	$('#screen').fadeOut('fast', function() {
		$('#sections').scrollTo( '#mn1 li:eq(' + idx + ')', 0 );	
	});
	$('#screen').fadeIn('fast');

	$("#mn2 li").each(function (i,item) {
		$(this).removeClass("rb_title_on");
		$(this).addClass("rb_title_off");
	});

	$('#mn2 li:eq(' + ( idx ) + ')').removeClass("rb_title_off");
	$('#mn2 li:eq(' + ( idx ) + ')').addClass("rb_title_on");
}

function moveLeft(el)
{
	idx = idx1;
	window.clearInterval( interval );
	
	$('#screen').fadeOut('fast', function() {
		$('#sections').scrollTo( '#mn1 li:eq(' + idx + ')', 0 );	
	});
	$('#screen').fadeIn('fast');

	$("#mn2 li").each(function (i,item) {
		$(this).removeClass("rb_title_on");
		$(this).addClass("rb_title_off");
	});

	el.removeClass("rb_title_off");
	el.addClass("rb_title_on");
}
