// JavaScript Document

$(document).ready(function(e) {
	var control = $("#focus_turn_control");
	var child = $("#focus_turn ul").children("li");
    var count = child.length;

	var i=0;
	var current=-1;
	for(i=0; i<count; i++) {
		if($(child[i]).hasClass("current")) {
			current = i;
			control.append('<span class="current"'+(i+1)+'</span>');
		}
		control.append("<span>"+(i+1)+"</span>");
	}
	var control_child = control.children("span");
	if(current == -1) {
		$(child[0]).addClass("current");
		$(control_child[0]).addClass("current");
		current = 0;
	}
	control_child.click(function(e) {
        turnTo($(this).html()-1);
    });
	var focus_timer = setInterval(autoTurn,7000);
	function autoTurn() {
		if(current == count -1) {
			next = 0;
		}
		else {
			next = current + 1;
		}
		turnTo(next);
	}
	function turnTo(index) {
		$(child).fadeOut(1000);
		$(child[index]).fadeIn(2000);
		$(control_child).removeClass("current");
		$(control_child[index]).addClass("current");
		current = next;
	}
	
	var news_ul = $("#announce ul")
	var news_count = news_ul.children("li").length;
	var news_current = 0;
	var height = -24;
	var news_timer = setInterval(autoNews,3000);
	function autoNews() {
		if(news_current == news_count -1) {
			next = 0;
		}
		else {
			next = news_current + 1;
		}
		$(news_ul).animate({"top": next * height},1000);
		news_current = next;
	}
	
});
