

function turnImg(){}

turnImg.prototype = {

	pDiv : null , //焦点图得父容器
	
	cDiv : null , //每个焦点图容器

	pro : null ,  //过程 

	cDivCount : 0 , //子容器个数

	showNo : 0 , //初始显示序号

	t : 2000 , //时间间隔

	numberControl : null,//数字控制child对象数组

	setShowNo : function(i){
	
		this.showNo = i;

	},

	getO : function(o){ //获取对象

		if(typeof(o) == "string"){

			if(document.getElementById(o)){
			
				return document.getElementById(o);

			}else{
				
				alert("no have " + o);
			
				return null;

			}
		}else{
		
			return o;

		}
	
		
	},
	
	info : function(o){ //初始化
		
		this.pDiv = this.getO(o);
		
		this.cDiv = this.pDiv.getElementsByTagName("div");

		this.cDivCount = this.cDiv.length;

		if(this.showNo >= this.cDivCount){
			
			alert("初始化序号错误! showNo err");

		}

		this.showImg(this.showNo);
		
	
	},

	showImg : function(id){
		
		this.showNo = id;

		for(var i = 0 ; i < this.cDivCount ; i++){

			this.cDiv[i].style.display = (i == this.showNo) ? "block" : "none";

		}

		if(this.numberControl != null){
		
			for(var i = 0 ; i < this.numberControl.length ; i++){
			
				this.numberControl[i].className = "";
			
			}

			this.numberControl[this.showNo].className = "hover";
		
		}
	
	},

	next : function(){

		if(this.showNo >= this.cDivCount-1){
		
			this.showNo = 0;
		
		}else{
		
			this.showNo++;

		}

		this.showImg(this.showNo);

	},

	preview : function(){
	
		if(this.showNo <= 0){
		
			this.showNo = this.cDivCount - 1;
		
		}else{
		
			this.showNo--;

		}

		this.showImg(this.showNo);

	},

	autoPlay : function(){
		
		var _this = this;
	
		this.pro = setInterval(function(){_this.next();},_this.t);

	},

	control : function(pause,play,prev,next){

		var _this = this;
	
		this.getO(pause).onclick = function(){clearInterval(_this.pro);};

		this.getO(play).onclick = function(){clearInterval(_this.pro);_this.autoPlay();};

		this.getO(prev).onclick = function(){clearInterval(_this.pro);_this.preview();_this.autoPlay();};

		this.getO(next).onclick = function(){clearInterval(_this.pro);_this.next();_this.autoPlay();};

	},
	
	show : function(o,tagName,id){

		var c = this.getO(o).getElementsByTagName(tagName);

		for (var i = 0 ; i < c.length  ; i++)

		{

			c[i].className = "";

		}

		c[id].className = "hover";

	},

	idControl : function(o,tagName,b){//数字控制父容器id , 数字控制标签 , 是否自动播放
		
		
		var _this = this;
		
		var c = this.getO(o).getElementsByTagName(tagName);

		this.numberControl = c;

		if(this.cDivCount != c.length){
		
			alert("数字控制个数和显示个数不一致!");
		
			return false;

		}

		c[0].className = "hover";
		
		for(var i = 0 ; i < c.length ; i++){
		
			c[i].value = i;
			
			c[i].onclick = function(){

				clearInterval(_this.pro);

				_this.showImg(this.value);
				
				if(b == true){

					_this.autoPlay();

				}
			}
		}	
	}
}


