var boxTopicInterval = 10000;
var boxTopicTimeout = null;
var boxTopicMousePos = null;
var boxTopicItems = null;
var boxTopicNaviButtons = null;
var boxTopicSelected = 0;
var boxTopicNaviHTML = '';

function boxTopicSwitch(newitem) {
	if (boxTopicTimeout)
		clearTimeout(boxTopicTimeout);
	var selected = parseInt($(boxTopicNaviButtons).filter(".selected").text());
	selected = (isNaN(selected) ? null : selected - 1);
	var newitem = (typeof(newitem) == 'undefined' ? (selected == null ? 0 : ((selected + 1) % boxTopicItems.length)) : (isNaN(newitem) ? 0 : newitem - 1));
	newitem = Math.max(Math.min(newitem, boxTopicItems.length - 1), 0);
	if (boxTopicMousePos == null || boxTopicMousePos == newitem) {
		if (selected != null) 
			boxTopicItems.eq(selected).fadeOut('slow');
		boxTopicItems.eq(newitem).fadeIn('slow');
		boxTopicItems.removeClass("selected");
		boxTopicNaviButtons.removeClass("selected");
		boxTopicItems.eq(newitem).addClass("selected");
		boxTopicNaviButtons.eq(newitem).addClass("selected");
		boxTopicTimeout = setTimeout('boxTopicSwitch()', boxTopicInterval);
	}
}

function boxTopicInit() {
	boxTopicItems = $("#boxTopicItems .item");
	for (var i = 0; i < boxTopicItems.length; i++)
		boxTopicNaviHTML += '<a href="javascript:void(null);">' + (i + 1) + '</a>';
	$("#boxTopicNavi").html(boxTopicNaviHTML);
	boxTopicNaviButtons = $("#boxTopicNavi a");
	boxTopicNaviButtons.click(function(e) {
		e.preventDefault();
		boxTopicSwitch(parseInt($(this).text()));
	});
	boxTopicNaviButtons.mouseover(function(e) {
		boxTopicMousePos = parseInt($(this).text() - 1);
	});
	boxTopicNaviButtons.mouseout(function(e) {
		boxTopicMousePos = null;
	});
	boxTopicSwitch();
}

