function PlaySlidePhoto(aoConf){
	this.conf = aoConf;
	this.init();
}
PlaySlidePhoto.prototype = {
	define:function(){
		this.wrap = $(this.conf.wrap);
		this.items = $(this.conf.items);
		this.wraptd = $(this.conf.wraptd);
		this.wrapCont = $(this.conf.wrapCont);
		this.ul = this.wrap.find("ul");
		this.curIdx = 0;
		this.toIdx = 0;

		this.trigs = $(this.conf.trigs);
		this.next=$(this.conf.next);

		this.pWidth = 0;
		this.Timer = null;
	},
	init:function(){
		this.define();
		this.addEvent();
		this.autoRun();
		this.buildDom();
		this.pWidth = $(this.items.get(0)).outerWidth();
		$(this.ul.get(0)).css("width",this.items.length*this.pWidth)
	},
	buildDom:function(){
		if(this.wraptd.length){
			if(this.wraptd.length < 2){
				alert("html结构不对");
			}
		}
		$(this.wraptd.get(1)).html($(this.wraptd.get(0)).html());
	},
	change:function(idx){
		this.wrapCont.stop(true);
		this.toIdx = idx;
		this.slide(idx);
		this.curIdx = idx;

	},
	slide: function(idx){
		var len = this.items.length;
		var that = this;

		var curIdx = this.curIdx;
		var toIdx = this.toIdx;
		if(curIdx == len){
			curIdx = 0;
		}
		if(idx == len){
			toIdx = 0;
		}
		$(this.trigs.get(curIdx)).removeClass("current");
		$(this.trigs.get(toIdx)).addClass("current");
		if(this.trigs.get()){

		}
		this.wrapCont.animate({"margin-left":-(idx*this.pWidth)}, 300, function(){
			if(idx >= len){
				that.wrapCont.css("margin-left",0);
			}
		});
	},

	addEvent:function(){
		var that = this;
		this.trigs.each(function(idx){
			var self = $(this);
			self.bind("click", function(){
				if(that.Timer)clearInterval(that.Timer);
				that.change(idx);
				that.autoRun();

			});
		});
		this.next.bind("click",function(){
			if(that.Timer)clearInterval(that.Timer);
			that.runNext();
			that.autoRun();
		})
	},
	autoRun:function(){
		var that = this;
		var len = this.items.length;
		this.Timer=setInterval(function(){
			that.toIdx++;
			if(that.toIdx > len){
				that.toIdx = 1;
			}
			that.change(that.toIdx);
		}, 9000);	//edit the run time  leoric
	},
	runNext: function(){
		var len = this.items.length;
		this.toIdx++;
		if(this.toIdx > len){
			this.toIdx =1;
		}
		this.change(this.toIdx);
	}
}

window.PSP = new PlaySlidePhoto({"wrap":"#imgfocus", "items":"#imgfocus li", "wrapCont":"#imgfocus table:first", "wraptd":"#imgfocus td", "trigs":"#numfocus li"});

