$(document).ready(function(){
	$('.block-header .nav li.pag').click(function() {
		type = $(this).attr('id').substr(0,2);
		$('.block-content[id^=b'+type+']').hide();
		$(this).parent().children().removeClass('active');
		$('#b'+$(this).attr('id')).show();
		$(this).addClass('active');
		return false;
	});
	
	$('.block-header .nav li.left').click(function() {
		if($(this).parent().find('li.pag.active').prev().hasClass('pag')){
			$(this).parent().find('li.pag.active').prev().click();
		}else{
			$(this).parent().find('li.pag:last').click();
		}
		return false;
	});
	
	$('.block-header .nav li.right').click(function() {
		if($(this).parent().find('li.pag.active').next().hasClass('pag')){
			$(this).parent().find('li.pag.active').next().click();
		}else{
			$(this).parent().find('li.pag:first').click();
		}
		return false;
	});
	
	$('.dotmenu li').click(function(){
		$(this).parent().children('li').children('span').html('○');
		$(this).children('span').html('●');
		$(this).parent().children('li').removeClass('active');
		$(this).addClass('active');
		id = $(this).attr('id').substr(12);
		$(this).parents('.dotblock').children('.content').children('div').addClass('hidden');
		$(this).parents('.dotblock').children('.content').children('div#dotcontent_page'+id).removeClass('hidden');
	});
	
	$('.dotblock').mouseenter(function(){
		clearTimeout(rollTimeout);
	});
	
	$('.dotblock').mouseleave(function(){
		clearTimeout(rollTimeout);
		rollTimeout = setTimeout("rollDotMenu();", rollDelay);
	});
	
	rollTimeout = setTimeout("rollDotMenu();", rollDelay);
});

var rollDelay = 10000;
var rollTimeout;

function rollDotMenu(){
	$('.dotmenu').each(function(){
		if($(this).children('li').length > 1){
			if($(this).children('.active').next().html() != null){
				$(this).children('.active').next().click();
			}else{
				$(this).children('li:first').click();
			}
			clearTimeout(rollTimeout);
			rollTimeout = setTimeout("rollDotMenu();", rollDelay);
		}
	});
}