﻿	var bind = function(object, fn){
        return function(){
            fn.apply(object, arguments);
        }
    }
	
	function fcs(id,time){
		return new fcs.prototype.init(id,time);
	}
	fcs.prototype={
		init:function(id,time){
			var othis=this;
			this.idx=0;
			this.itv=false;
			this.time=time || 3000;
			this.ppt=document.getElementById(id);
			this.mpc=this.ppt.getElementsByTagName("div")[0];
			this.mpcdiv=this.mpc.getElementsByTagName("div");
			this.mpclen=this.mpcdiv.length;
			this.mpcimg=this.mpc.getElementsByTagName("img");
			this.ul=document.createElement("ul");
			for(var i=0; i<this.mpclen; i++){
				this.ul.innerHTML+="<li>"+(i+1)+"<\/li>";
			}
			this.mpc.appendChild(this.ul);
			this.li=this.ul.getElementsByTagName("li");
			this.hdlr();
		},
		hdlr:function(){
			this.play();
			this.auto();
			var othis=this;
			for(var i=0; i<this.mpclen; i++){
			(function(){
				var ii=i;
				othis.li[ii]["onclick"]=function(){
					othis.idx=ii;
					othis.play();
				}				
				})()	
			}
			this.ppt.onmouseover=function(){ othis.pause() }
			this.ppt.onmouseout=function(){ othis.auto() }
		},
		play:function(){
			for(var i=0; i<this.mpclen; i++){
				if(i!==this.idx){					
					this.mpcdiv[i].style.display="none";
					this.li[i].className="";
					}else{
					this.mpcdiv[i].style.display="";	
					this.li[i].className="cur";
				}				
			}			
		},
		step:function(){
			this.idx+=1;
			//alert(this.idx)
			if(this.idx==this.mpclen) this.idx=0;
			this.play();
		},
		auto:function(){			
			if(!this.itv){			
				this.itv=window.setInterval(bind(this,this.step),this.time);
			}
		},
		pause:function(){	
			var othis=this;
			if(othis.itv){	
			window.clearInterval(othis.itv);
			othis.itv=false;
			}
		}
	}
	fcs.prototype.init.prototype=fcs.prototype;
	//实例化 可以传进两个参数 第一个为id 第二个为可选的时间间隔

    fcs("ppt2",2000);	
