<!--var $ = $.noConflict();-->
//ban_qh
$.fn.banqh = function(can){
	can = $.extend({
					box:null,//总框架
					pic:null,//大图框架
					pnum:null,//小图框架
					prev_btn:null,//小图左箭头
					next_btn:null,//小图右箭头
					prev:null,//大图左箭头
					next:null,//大图右箭头
					pop_prev:null,//弹出框左箭头
					pop_next:null,//弹出框右箭头
					autoplay:false,//是否自动播放
					interTime:5000,//图片自动切换间隔
					delayTime:800,//切换一张图片时间
					pop_delayTime:800,//弹出框切换一张图片时间
					order:0,//当前显示的图片（从0开始）
					picdire:true,//大图滚动方向（true水平方向滚动）
					mindire:true,//小图滚动方向（true水平方向滚动）
					min_picnum:null,//小图显示数量
					pop_up:false,//大图是否有弹出框
					pop_div:null,//弹出框框架
					pop_pic:null,//弹出框图片框架
					pop_xx:null,//关闭弹出框按钮
					bg:null//朦灰层
				}, can || {});
	var picnum = $(can.pic).find('ul li').length;
	var picw = $(can.pic).find('ul li').outerWidth(true);
	var pich = $(can.pic).find('ul li').outerHeight(true);
	var poppicw = $(can.pop_pic).find('ul li').outerWidth(true);
	var picminnum = $(can.pnum).find('ul li').length;
	var picpopnum = $(can.pop_pic).find('ul li').length;
	var picminw = $(can.pnum).find('ul li').outerWidth(true);
	var picminh = $(can.pnum).find('ul li').outerHeight(true);
	var pictime;
	var tpqhnum=0;
	var xtqhnum=0;
	var popnum=0;
	$('#preview').find('.product-main-slider').css({"max-width":"400px","max-height":"550px","width":"100%","height":"495px"});
	$(can.pic).find('ul').width(picnum*picw).height(picnum*pich);
	$(can.pnum).find('ul').width(picminnum*picminw).height(picminnum*picminh);
	$(can.pop_pic).find('ul').width(picpopnum*poppicw);
	
//点击小图切换大图
	    $(can.pnum).find('li').click(function () {
        tpqhnum = xtqhnum = $(can.pnum).find('li').index(this);
        show(tpqhnum);
		minshow(xtqhnum);
    }).eq(can.order).trigger("click");
//大图弹出框
if(can.pop_up==true){
	$(can.pic).find('ul li').click(function(){
		$(can.bg).height($(document).height()).show();
		$(can.pop_div).show();
		popnum = $(this).index();
		var gdjl_w=-popnum*poppicw;
		$(can.pop_pic).find('ul').css('left',gdjl_w);
		popshow(popnum);
		})
	$(can.pop_xx).click(function(){
		$(can.bg).hide();
		$(can.pop_div).hide();
	})
}

	if(can.autoplay==true){
//自动播放
		pictime = setInterval(function(){
			show(tpqhnum);
			minshow(tpqhnum)
			tpqhnum++;
			xtqhnum++;
			if(tpqhnum==picnum){tpqhnum=0};	
			if(xtqhnum==picminnum){xtqhnum=0};
					
		},can.interTime);	
		
//鼠标经过停止播放
		$(can.box).hover(function(){
			clearInterval(pictime);
		},function(){
			pictime = setInterval(function(){
				show(tpqhnum);
				minshow(tpqhnum)
				tpqhnum++;
				xtqhnum++;
				if(tpqhnum==picnum){tpqhnum=0};	
				if(xtqhnum==picminnum){xtqhnum=0};		
				},can.interTime);			
			});
	}
//小图左右切换			
	$(can.prev_btn).click(function(){
		if(tpqhnum==0){tpqhnum=picnum};
		if(xtqhnum==0){xtqhnum=picnum};
		xtqhnum--;
		tpqhnum--;
		show(tpqhnum);
		minshow(xtqhnum);	
		})
	$(can.next_btn).click(function(){
		if(tpqhnum==picnum-1){tpqhnum=-1};
		if(xtqhnum==picminnum-1){xtqhnum=-1};
		xtqhnum++;
		minshow(xtqhnum)
		tpqhnum++;
		show(tpqhnum);
		})	
//大图左右切换	
	$(can.prev).click(function(){
		if(tpqhnum==0){tpqhnum=picnum};
		if(xtqhnum==0){xtqhnum=picnum};
		xtqhnum--;
		tpqhnum--;
		show(tpqhnum);
		minshow(xtqhnum);	
		})
	$(can.next).click(function(){
		if(tpqhnum==picnum-1){tpqhnum=-1};
		if(xtqhnum==picminnum-1){xtqhnum=-1};
		xtqhnum++;
		minshow(xtqhnum)
		tpqhnum++;
		show(tpqhnum);
		})
//弹出框图片左右切换	
	$(can.pop_prev).click(function(){
		if(popnum==0){popnum=picnum};
		popnum--;
		popshow(popnum);
		})
	$(can.pop_next).click(function(){
		if(popnum==picnum-1){popnum=-1};
		popnum++;
		popshow(popnum);
		})			
//小图切换过程
	function minshow(xtqhnum){
		var mingdjl_num =xtqhnum-can.min_picnum+2
		var mingdjl_w=-mingdjl_num*picminw;
		var mingdjl_h=-mingdjl_num*picminh;
		
		if(can.mindire==true){
			$(can.pnum).find('ul li').css('float','left');
			if(picminnum>can.min_picnum){
				if(xtqhnum<3){mingdjl_w=0;}
				if(xtqhnum==picminnum-1){mingdjl_w=-(mingdjl_num-1)*picminw;}
				$(can.pnum).find('ul').stop().animate({'left':mingdjl_w},can.delayTime);
				}
				
		}else{
			$(can.pnum).find('ul li').css('float','none');
			if(picminnum>can.min_picnum){
				if(xtqhnum<3){mingdjl_h=0;}
				if(xtqhnum==picminnum-1){mingdjl_h=-(mingdjl_num-1)*picminh;}
				$(can.pnum).find('ul').stop().animate({'top':mingdjl_h},can.delayTime);
				}
			}
		
	}
//大图切换过程
		function show(tpqhnum){
			var gdjl_w=-tpqhnum*picw;
			var gdjl_h=-tpqhnum*pich;
			if(can.picdire==true){
				$(can.pic).find('ul li').css('float','left');
				$(can.pic).find('ul').stop().animate({'left':gdjl_w},can.delayTime);
				$(can.pic).find('ul li img').css({"max-width":"467px","max-height":"700px","width":"auto","height":"100%"});
				}else{
			$(can.pic).find('ul').stop().animate({'top':gdjl_h},can.delayTime);
			}//滚动
			//$(can.pic).find('ul li').eq(tpqhnum).fadeIn(can.delayTime).siblings('li').fadeOut(can.delayTime);//淡入淡出
			$(can.pnum).find('li').eq(tpqhnum).addClass("on").siblings(this).removeClass("on");
		};
//弹出框图片切换过程
		function popshow(popnum){
			var gdjl_w=-popnum*poppicw;
				$(can.pop_pic).find('ul').stop().animate({'left':gdjl_w},can.pop_delayTime);
			//$(can.pop_pic).find('ul li').eq(tpqhnum).fadeIn(can.pop_delayTime).siblings('li').fadeOut(can.pop_delayTime);//淡入淡出
		};					
				
}

//模拟Select//
$.fn.extend({
	jselect:function(){
		return $(this).each(function(){
			var width = this.style.width;//因为ff取不到auto
			$(this).after("<input type=\"hidden\" /><div class='jslct'><div class='jslct_t'><em></em></div><dl></dl></div>");
			var ipt = $(this).next("input");
			var lst = ipt.next("div");
			var itms = $("dl",lst);
			var itm;
			var opt = $("option",$(this));
			var opts = $("option:selected",$(this));
			var opts_index = opt.index(opts);
			var em = $("em",lst);
			var fn_change=$(this).attr("onchange");
			/*if(width!=""){lst.css("width",$(this).css("width"));em.css("width","100%");};*/
			ipt.attr("name",$(this).attr("name"));
			ipt.attr("id",$(this).attr("id"));
			em.text($("option:selected",$(this)).text());
			opt.each(function(i){
				itms.append("<dd></dd>");
				itm = $("dd",itms);
				var dd = itm.eq(i);
				dd.attr("val",$(this).val()).text($(this).text());
			});
			itm.eq(0).addClass("noborder")
			itm.eq(opts_index).addClass("jslcted");
			$(this).remove();
			lst.hover(function(){$(this).addClass("jslct_hover");return false},function(){$(this).removeClass("jslct_hover");return false});
			itm.hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
			itms.addClass("hovered")
			lst.click(function(){lstshow();});
			$(document).mouseup(function(){lsthide();});
			itm.click(function(){
							   if(fn_change!=null){(eval(fn_change))();}
							   itm.removeClass("jslcted");
							   $(this).addClass("jslcted");
							   em.text($(this).text());
							   ipt.val($(this).attr("val"));
							   lsthide();
							   return false;
							   })
			function lstshow(){
					var maxheight =$(document).height()-200;
					itms.css({height:"auto"});
					maxheight = itms.height()>maxheight?maxheight:"auto";
					itms.css({height:maxheight});
					itms.show();
					lst.css("z-index","9998")
			};
			function lsthide(){
					$(".jslct dl").hide();
					$(".jslct").css("z-index","0")
			};
		});	
	}						
});

$(function(){
	$(".selectMian").jselect();
});