
function TurnShow() {
	this.titleRegionId = "#ul_news_item";
	this.showRegionId = "#div_news_img";
	this.selectedClassName="selected";
	this.normalClassName="";
	this.current=0;
	this.next=0;
	this.duration = 16;
	this.autoScroller=0;
	this.scrollInterval=0;
	this.autoScrollTime = 5000;
	this.count = 5;
	this.step = 227;
	this.showRegionId_b = "";
	this.step_b = 227;
	this.isAuto = true;
	var _this = this;
	this.addObjectEventListener(window,"onload",function() {_this.startOnLoad();});
	this.titleElements = null;
}
TurnShow.prototype.startOnLoad=function(){
	this.tryAuto();
}
TurnShow.prototype.tryAuto=function(){
	if(this.isAuto) {
		this.auto();
	}
}
TurnShow.prototype.stopAuto=function(){
	clearInterval(this.autoScroller);
}
TurnShow.prototype.turn=function(index){
	clearInterval(this.autoScroller);
	this.scroll(index);
}
TurnShow.prototype.scroll=function(index){
	var b=this;
	b.next=index;
	if(!$(b.titleRegionId)){
		clearInterval(b.autoScroller);
		return;
	}
	var duration=b.duration;
	var count=0;
	var step=b.step;
	var step_b=b.step_b;
	if(index==b.current&&count>duration/8){
		return;
	}
	clearInterval(b.scrollInterval);
	var items=$(b.titleRegionId).get();
	for(var i=0;i<items.length;i++){
		if(b.selectedClassName!="") {
			items[i].className = items[i].className.replace(b.selectedClassName,"");
			items[i].className = items[i].className + ' ' + b.normalClassName;
		}
	}
	if(b.normalClassName!="") {
		items[index].className = items[index].className.replace(b.normalClassName,"");
	}
	items[index].className = items[index].className + ' ' + b.selectedClassName;

	b.scrollInterval=setInterval(function(){doit()},10);

	//function $(s){return document.getElementById(s);}
	function doit(){
		var span=index-b.current;
		var begin=$(b.showRegionId).get(0).scrollTop;
		var change=span*step+(b.current*step-begin);
		$(b.showRegionId).get(0).scrollTop=cpu(count,begin,change,duration);
		
		if(b.showRegionId_b!="" && $(b.showRegionId_b).size()>0) {
			var span_b=index-b.current;
			var begin_b=$(b.showRegionId_b).get(0).scrollTop;
			var change_b=span_b*step_b+(b.current*step_b-begin_b);
			$(b.showRegionId_b).get(0).scrollTop=cpu(count,begin_b,change_b,duration);
		}		
		count++;
		if(count==duration){
			clearInterval(b.scrollInterval);
			b.scrollInterval=0;
			$(b.showRegionId).get(0).scrollTop=begin+change;
			if(b.showRegionId_b!="" && $(b.showRegionId_b).size()>0) {
				var span_b=index-b.current;
				var begin_b=$(b.showRegionId_b).get(0).scrollTop;
				var change_b=span_b*step_b+(b.current*step_b-begin_b);
				$(b.showRegionId_b).get(0).scrollTop=cpu(count,begin_b,change_b,duration);
			}
			b.current=index;
			count=0;
		}
	}
	function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;};
}

TurnShow.prototype.auto=function(){
	var b = this;
	clearInterval(b.autoScroller);
	var items=$(b.titleRegionId).get();
	var fun_scrooll = function() {
		b.scroll(b.current>=items.length-1?0:b.current+1);
	}
	b.autoScroller=setInterval(fun_scrooll,b.autoScrollTime);
}

TurnShow.prototype.addObjectEventListener = function(obj,eventName,func) {
	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		if(eventName.indexOf("on")==0) {
			eventName = eventName.substring(2);
		}
		obj.addEventListener( eventName, func, false );
	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.attachEvent(eventName, func);
	}
}