/*幻灯片样式*/
function SlideClass(DivIdName){
	//幻灯节点对象
	this.DivObj=$("#"+DivIdName);
	//大图节点对象
	this.DivBigImgObj=$("#"+DivIdName+" .list");
	this.BigLiArr=$("#"+DivIdName+" ul li");
	//缩略图节点对象
	this.DivObj.append("<div class='Thumb'></div>");
	this.DivThumbObj=$("#"+DivIdName+" .Thumb");
	this.ThumbLiObj=null;
	//其他设置
	this.index=0;
	this.timeer=null;
	this.speed=4000;//切换速度
}
/**
 * 初始化
 */
SlideClass.prototype.Init=function(n){
	this.setCenter();
	this.SetBtn();
	this.BindEvt();
	this.ShowOne();
	this.Play();
}
/**
 * 设置按钮,没有原始宽度直接忽略
 */
SlideClass.prototype.setCenter = function(){	
	this.BigLiArr.find('img').each(function(){		
		var oldw=$(this).attr("oldw");			
		if(oldw==undefined || oldw==null){	
			return false;			
		}
		$(this).css({'margin-left':"-"+oldw/2+"px",'position':'relative','left':"50%"});
	})
}
/**
 * 设置按钮
 */
SlideClass.prototype.SetBtn = function(){
	//var width=parseInt(59* this.BigLiArr.length, 10);
	//this.DivThumbObj.css({"width": width + "px","position":"relative","left":"50%","margin-left":"-"+(width/2)+"px"});
//	var theHtml = "<ul style='width:" + width + "px;position:absolute;left:50%;margin-left:-"+(width/2)+"px;'>";	
	var theHtml = "<ul>";
	for (var i = 0; i < this.BigLiArr.length; i++) {
		theHtml += "<li rel='" + i + "'><em>&nbsp;</em></li>";
	}
	theHtml += "</ul>";
	$(this.DivThumbObj).html(theHtml);
	this.ThumbLiObj = $(this.DivThumbObj).find("li");
	$(this.ThumbLiObj[0]).addClass("onfocus");
}

/**
 * 为大图及按钮绑定事件
 */
SlideClass.prototype.BindEvt = function(){
	var theObj = this;
	//$(this.BigImgArr).hover(function(){
	//	clearInterval(theObj.timeer);
	//}, function(){
	//	theObj.Play();
	//});
	$(this.ThumbLiObj).hover(function(){
		clearInterval(theObj.timeer);
		theObj.index=parseInt($(this).attr("rel"),10);
		theObj.ShowOne();
		theObj.Play();
	}, function(){
	});
	//this.DivObj.find(".list").hover(function(){
	//		clearInterval(theObj.timeer);
	//},function(){
	//		theObj.Play();
	//})
	this.DivObj.find(".left").click(function(){
		clearInterval(theObj.timeer);	
		theObj.index--;		
		theObj.ShowOne();
		theObj.Play();
	})
	this.DivObj.find(".right").click(function(){
		clearInterval(theObj.timeer);
		theObj.index++;	
		theObj.ShowOne();
		theObj.Play();
	})
}

/**
 * 播放
 */
SlideClass.prototype.Play=function(){
	var theObj=this;
	this.timeer=setInterval(function(){	
		theObj.index++;
		theObj.ShowOne()
	},this.speed);
}
/**
 * 显示一个
 */
SlideClass.prototype.ShowOne=function(){	
	var theObj=this;
	if(this.index<0){//返回最后一个
		this.index=this.BigLiArr.length-1
	}else if(this.index>this.BigLiArr.length-1){//返回第一个
		this.index=0;
	}
	$(this.BigLiArr[this.index]).stop()
	.animate({opacity: 1}, 800, function(){
	}).show()
	.siblings().stop().animate({opacity: 0.3}, 800).hide();	
	$(this.ThumbLiObj).removeClass("onfocus");
	$(this.ThumbLiObj[this.index]).addClass("onfocus");
	
}

