var rr_current_banner = 0;
var rr_banner_paused = false;

function rrShowBanner(index){
	rr_current_banner = index;
	$prev_selected = $('.rr_carousel .rr_selected');
	$('.rr_carousel .rr_content').removeClass('rr_selected');
	$('.rr_carousel .rr_content').eq(index).addClass('rr_selected');
	$('.rr_carousel .rr_selected').fadeIn(500);
	$prev_selected.fadeOut(500);
	$('.rr_carousel .rr_page_num_item').removeClass('rr_page_selected');
	$('.rr_carousel .rr_page_num_item').eq(index).addClass('rr_page_selected');
}

function rrAnimateBanner(){
	if(!rr_banner_paused){
		if(rr_current_banner == 3){
			rrShowBanner(0);
		}
		else{
			rrShowBanner(rr_current_banner + 1);
		}
	}
}

$(document).ready(function(){
	$('.rr_carousel .rr_banner_box').hover(function(){rr_banner_paused = true;}, function(){rr_banner_paused = false;});
	$('.rr_carousel .rr_page_num').hover(function(){rr_banner_paused = true;}, function(){rr_banner_paused = false;}).find('.rr_page_num_item').hover(function(){
		$(this).addClass('hovered');
	}, function(){
		$(this).removeClass('hovered');
	});
	
  $('.rr_carousel .rr_content').each(function(index){
    $(this).css({'background-position':'0px '+ (index * -270) +'px'});
  });
  
	$('.rr_carousel .rr_content').hide();
	$('.rr_carousel .rr_content').eq(0).show();
	
	$('.rr_carousel .rr_page_num_item').each(function(index){
		$(this).click(function(){
			rrShowBanner(index);
		});
	});
		
	setInterval('rrAnimateBanner()', 3000);
});