/**
* 全屏幻灯片类
*/
function slidelfetright(dividname){
//幻灯节点对象
this.divobj=$("#"+dividname);
//大图节点对象
this.divbigimgobj=$("#"+dividname+" .list");
this.bigliarrul = $("#"+dividname+" .list ul");
this.bigliarr=$("#"+dividname+" .list ul li");
//缩略图节点对象
this.next = $("#"+dividname+" .left");
this.prev = $("#"+dividname+" .right");
this.thewidth = this.divobj.width();
this.divobj.append("
");
this.divthumbobj=$("#"+dividname+" .thumb");
this.thumbliobj=null;
this.fangxiang = "left";
this.ishover = false;
//其他设置
this.index=1;
this.timeer=null;
this.speed=5000;//切换速度
}
/**
* 初始化
*/
slidelfetright.prototype.init=function(n){
this.bigliarrul.css("width",(this.thewidth * (this.bigliarr.length+2)));
this.bigliarr.css("width",this.thewidth);
this.setbigmarginleft();
this.setbtn();
this.bindevt();
this.bigliarrul.append(this.bigliarr.eq(0).clone());
this.bigliarrul.prepend(this.bigliarr.last().clone());
this.bigliarrul.css("left",-(this.thewidth*this.index));
this.showone();
this.bigliarr=this.divobj.find(" .list ul li");
this.paly();
}
/**
* 设置大图距离左边的位置
*/
slidelfetright.prototype.setbigmarginleft = function(){
var width = $(this.divbigimgobj).width();
for (var i = 0; i < this.bigliarr.length; i++) {
this.setsize(this.bigliarr[i]);
}
}
/*设置居中*/
slidelfetright.prototype.setsize=function(liobj) {
var thewidht=parseint($(this.divbigimgobj).width(),10);
var imgobj=$(liobj).find("img").get(0);
var width=parseint($(imgobj).attr("oldw"),10);
var height=parseint($(imgobj).attr("oldh"),10);
var nowheight=parseint($(imgobj).height(),10);
var nowwidht=parseint(width*nowheight/height,10);
var left=parseint((thewidht-nowwidht)/2,10);
//$(imgobj).css({"left":left+"px"});
}
/**
* 设置按钮
*/
slidelfetright.prototype.setbtn = function(){
var width=parseint(72 * this.bigliarr.length, 10);
var thehtml = "";
for (var i = 0; i < this.bigliarr.length; i++) {
//thehtml += "- " + parseint(i + 1, 10) + "
";
thehtml += "-
";
}
thehtml += "
";
$(this.divthumbobj).html(thehtml);
$(this.divthumbobj).css({marginleft:"-"+parseint(width/2,10)+"px"});
this.thumbliobj = $(this.divthumbobj).find("li");
$(this.thumbliobj[0]).addclass("onfocus");
}
/**
* 为大图及按钮绑定事件
*/
slidelfetright.prototype.bindevt = function(){
var theobj = this;
$(this.bigimgarr).hover(function(){
clearinterval(theobj.timeer);
}, function(){
theobj.paly();
});
$(this.thumbliobj).hover(function(){
clearinterval(theobj.timeer);
theobj.index=parseint($(this).attr("rel"),10)+1;
theobj.showone();
}, function(){
theobj.paly();
});
this.next.click(function(){
clearinterval(theobj.timeer);
theobj.index++;
theobj.fangxiang = "left";
theobj.showone();
theobj.paly();
})
this.prev.click(function(){
clearinterval(theobj.timeer);
theobj.index--;
theobj.fangxiang = "right";
theobj.showone();
theobj.paly();
})
}
/**
* 播放
*/
slidelfetright.prototype.paly=function(){
var theobj=this;
this.timeer=setinterval(function(){theobj.setpaly()},this.speed);
}
/*播放设置*/
slidelfetright.prototype.setpaly=function(){
if(this.fangxiang == "left"){
this.index++;
}else{
this.index--;
}
this.showone();
}
/**
* 显示一个
*/
slidelfetright.prototype.showone=function(){
var theobj = this;
theobj.bigliarrul.stop().animate({
"left":-(theobj.thewidth * theobj.index)
},800,function(){
if(theobj.index > theobj.bigliarr.length-2){
theobj.index = 1;
theobj.bigliarrul.css("left",-(theobj.thewidth));
}else if(theobj.index < 1){
theobj.index = theobj.bigliarr.length-2;
theobj.bigliarrul.css("left",-(theobj.thewidth*(theobj.index)));
}
})
$(theobj.thumbliobj).removeclass("onfocus");
if(theobj.index > (theobj.thumbliobj.length)){
$(theobj.thumbliobj[0]).addclass("onfocus");
}else if(theobj.index < 1){
$(theobj.thumbliobj[theobj.thumbliobj.length-1]).addclass("onfocus");
}else{
$(theobj.thumbliobj[theobj.index-1]).addclass("onfocus");
}
}