/* slightbox 废弃*/
function slightbox(obj,oclose,opacity,ctime){	
	var _this = this;
	_this.d = jQuery(obj);
	var mkdiv

	_this.cenvelop = function(){	
		if(opacity){
			mkdiv = document.createElement("div");
			jQuery(mkdiv).attr("id","win_pop_mask").css({position:"absolute",zIndex:"9998",left:"0",top:"0",background:"#000000"});			
			if(jQuery.browser.msie && jQuery.browser.version == "6.0"){
					jQuery(mkdiv).html("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\" style=\"filter:alpha(opacity:0)\"></iframe>")
			}
			jQuery("body").append(jQuery(mkdiv));
			jQuery(mkdiv).css("opacity",opacity);
		}
		_this._resize();
	}
	
	_this._resize = function(){
		jQuery(mkdiv).css("height",Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight) + "px");
		jQuery(mkdiv).css("width",document.documentElement.scrollWidth + "px");
		var _x = Math.round((document.documentElement.clientWidth-this.d.width())/2);
		var _y = Math.round((document.documentElement.clientHeight-this.d.height())/2);
		_this.d.css({display:"block","position":"absolute","zIndex":"9999","left":_x+"px","top":_y+document.documentElement.scrollTop+"px"});
	}
	
	_this.closed = function(){
		jQuery(mkdiv).remove();
		_this.d.hide();
		return false;
	}
	
	var sctop = 0;
	
	jQuery(window).resize(function(){
		if(_this.d.css("display") == "none") return;
		_this._resize();
	});
	
	var top = (document.documentElement.clientHeight-this.d.height())/2;
	
	jQuery(window).scroll(function(){
		jQuery(mkdiv).css("height",Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight) + "px");
		jQuery(obj).css("top",document.documentElement.scrollTop - sctop + top + "px");	
		sctop = document.documentElement.scrollTop;
		top = parseInt(jQuery(obj).css("top"));
	});
	
	if(ctime){
		setTimeout(_this.closed, ctime)	
	}
	
	if(oclose){
		jQuery(oclose).click(function(){_this.closed()});
	}
	
	_this.cenvelop();
}
/*
==新窗口提示==
{winopentips()}
*/
function winopentips(){
	var od = document.createElement("img");	
	jQuery(od).css({position:"absolute",top:"0",left:"0",visibility:"hidden",zIndex:"-2",width:"12px",height:"12px"});
	jQuery(od).attr({id:"hoverimg",src:"http://i3.dukuai.com/ui/style/09/ico/f02812.gif",width:"12px",height:"12px"});
	jQuery("body").append(od);
	jQuery("a").mouseover(function(){
		if(jQuery(this).attr("target") == "_blank"){
			jQuery(this).mousemove(function(event){
				var _w = jQuery(this).width();
				var _h = jQuery(this).height();	
				jQuery("#hoverimg").css({visibility:"visible",zIndex:"100"});
				if(jQuery.browser.msie){jQuery(od).css({left:event.clientX+12+"px",top:event.clientY+document.documentElement.scrollTop+15+"px"})}
				if(jQuery.browser.mozilla){jQuery(od).css({left:event.pageX+15+"px",top:event.pageY+17+"px"})}
			})
		}
	}).mouseout(function(){
		jQuery("#hoverimg").css("visibility","hidden");
	});
}
/*
==轮播{对象|对象属性}==
对象属性{宽度|高度|文字大小|自动切换时间}
*/
function dk_slideplayer(object,config){
	this.obj = object;
	this.config = config ? config : {width:"300px",height:"200px",fontsize:"12px",right:"10px",bottom:"10px",time:"5000"};
	this.pause = false;
	var _this = this;
	if(!this.config.right){
		this.config.right = "0px"
	}
	if(!this.config.bottom){
		this.config.bottom = "3px"
	}
	if(this.config.fontsize == "12px" || !this.config.fontsize){
		this.size = "12px";
		this.height = "21px";
		this.right = "6px";
		this.bottom = "10px";
	}else if(this.config.fontsize == "14px"){
		this.size = "14px";
		this.height = "23px";
		this.right = "6px";
		this.bottom = "15px";
	}
	this.count = jQuery(this.obj + " li").size();
	this.n =0;
	this.j =0;
	var t;
	this.factory = function(){
		jQuery(this.obj).css({position:"relative",zIndex:"0",margin:"0",padding:"0",width:this.config.width,height:this.config.height,overflow:"hidden"})
		jQuery(this.obj).prepend("<div style='position:absolute;z-index:20;right:"+this.config.right+";bottom:"+this.config.bottom+"'></div>");
		jQuery(this.obj + " li").css({width:"100%",height:"100%",overflow:"hidden"}).each(function(i){jQuery(_this.obj + " div").append("<a>"+(i+1)+"</a>")});

		jQuery(this.obj + " img").css({border:"none",width:"100%",height:"100%"})

		this.resetclass(this.obj + " div a",0);

		jQuery(this.obj + " p").each(function(i){			
			jQuery(this).parent().append(jQuery(this).clone(true));
			jQuery(this).html("");
			jQuery(this).css({position:"absolute",margin:"0",padding:"0",zIndex:"1",bottom:"0",left:"0",height:_this.height,width:"100%",background:"#000",opacity:"0.4",overflow:"hidden"})
			jQuery(this).next().css({position:"absolute",margin:"0",padding:"0",zIndex:"2",bottom:"0",left:"0",height:_this.height,lineHeight:_this.height,textIndent:"5px",width:"100%",textDecoration:"none",fontSize:_this.size,color:"#FFFFFF",background:"none",zIndex:"1",opacity:"1",overflow:"hidden"})
			if(i!= 0){jQuery(this).hide().next().hide()}
		});

		this.slide();
		this.addhover();
		t = setInterval(this.autoplay,this.config.time);
	}
	
	this.slide = function(){
		jQuery(this.obj + " div a").mouseover(function(){
			_this.j = jQuery(this).text() - 1;
			_this.n = _this.j;
			if (_this.j >= _this.count){return;}
			jQuery(_this.obj + " li").hide();
			jQuery(_this.obj + " p").hide();
			jQuery(_this.obj + " li").eq(_this.j).fadeIn("slow");
			jQuery(_this.obj + " li").eq(_this.j).find("p").show();
			_this.resetclass(_this.obj + " div a",_this.j);
		});
	}

	this.addhover = function(){
		jQuery(this.obj).hover(function(){clearInterval(t);}, function(){t = setInterval(_this.autoplay,_this.config.time)});
	}
	
	this.autoplay = function(){
		_this.n = _this.n >= (_this.count - 1) ? 0 : ++_this.n;
		jQuery(_this.obj + " div a").eq(_this.n).triggerHandler('mouseover');
	}
	
	this.resetclass =function(obj,i){
		jQuery(obj).css({float:"left",marginRight:"3px",width:"15px",height:"14px",lineHeight:"15px",textAlign:"center",fontWeight:"800",fontSize:"12px",color:"#000",background:"#FFFFFF",cursor:"pointer"});
		jQuery(obj).eq(i).css({color:"#FFFFFF",background:"#FF7D01",textDecoration:"none"});
	}

	this.factory();
}
/*
选项卡|显示隐藏层
选项卡属性设置: {mobj:"#m1",mchild:"li",mclass:"tds",eobj:"#m2",echild:"div",first:"1"};
	      mobj: 触发鼠标事件
*/
function optioncard(config){
	this.config	 = config;
	var _this = this;
	
	this.resetall = function(i){
		if(!this.config.mchild && !this.config.echild){
			if(i==0){
				jQuery(_this.config.mobj).removeClass(_this.config.mclass);
				jQuery(_this.config.eobj).hide();
				return;
			}
			if(i==1){
				jQuery(_this.config.mobj).addClass(_this.config.mclass);
				jQuery(_this.config.eobj).show();
				return;
			}
		}else{
			jQuery(this.config.mobj).find(this.config.mchild).removeClass(this.config.mclass);
			jQuery(this.config.eobj).find(this.config.echild).hide();
			jQuery(this.config.mobj).find(this.config.mchild).eq(i).addClass(this.config.mclass);
			jQuery(this.config.eobj).find(this.config.echild).hide().eq(i).show();
		}
	}

	if(this.config.mchild && this.config.echild){
		if(!this.config.first) this.config.first = 1;
		this.resetall(this.config.first-1);
		jQuery(this.config.mobj).find(this.config.mchild).each(function(i){
			if("click" == _this.config.events){
				jQuery(this).click(function(){_this.resetall(i);return false;})
			}else{
				jQuery(this).mouseover(function(){_this.resetall(i);})
			}
		})
	}else{
		jQuery(this.config.mobj).hover(function(){_this.resetall(1)},function(){_this.resetall(0)});
		jQuery(this.config.eobj).hover(function(){_this.resetall(1)},function(){_this.resetall(0)});
	}	
}

/* dk_lightbox {原slightbox}*/
(function(jQuery) {
	jQuery.dk_lightbox = function(object, options) {
		options = jQuery.extend({},options);
		var $jqobj = jQuery(object);
		var ie6		= (jQuery.browser.msie && jQuery.browser.version < 7);
		var $body	= jQuery(document.body);
		var $window	= jQuery(window);
		var $document	= jQuery(document);

		if(ie6){
				jQuery('select').css('visibility','hidden');
		}
		
		if(options.opacity){
			$ojbfade = jQuery("<div class=\"dk_lightboxfade\" id=\"dk_lightboxfade\"></div>").appendTo($body);
		}

		var ie6scroll = function(){
			$jqobj.css({top:$window.scrollTop()+($window.height() - $jqobj.height())/2});
		};

		var positionLightBox = function(){
			$jqobj.css({
				position: (ie6) ? "absolute" : "fixed",
				top: (ie6) ? ($window.height() - $jqobj.height())/2+$window.scrollTop() : ($window.height() - $jqobj.height())/2,
				left: "50%",
				zIndex:"328",
				marginLeft: (($jqobj.outerWidth()/2)*-1)
			});
			if(options.opacity){
				$ojbfade.css({
					position: "absolute",
					zIndex: 327,
					height: $document.height(),
					width: "100%",
					background: (options.background) ? options.background : "#000000",
					opacity: options.opacity,
					top: 0,
					left: 0,
					right: 0,
					bottom: 0
				});
			}
		};

		var removePrompt = function(){
			if(options.opacity){$ojbfade.hide();}
			$jqobj.hide();
			if(ie6) {$body.unbind('scroll',ie6scroll);}
			$window.unbind('resize',positionLightBox);
			$jqobj.fadeOut('fast',function(){
				jQuery('select').css('visibility','visible');
			});
		};

		positionLightBox();
		
		if(ie6) {
			$window.scroll(ie6scroll);
		}
		$window.resize(positionLightBox);
	
		if(options.closed){
			$jqobj.find(options.closed).click(function(){removePrompt()});
		}
		
		if(options.closedtime){
			setTimeout(removePrompt,options.closedtime);
		}
		
		if(options.closedobj){
			jQuery(options.closedobj).click(function(){removePrompt()});
		}
		$jqobj.show();
	};
})(jQuery);
//simplescroll
(function($){
	$.fn.dk_simplescroll = function(options){
		var opt = $.extend({},$.fn.dk_simplescroll.defaults,options);
		var $this = $(this);
		var scrollPause = false //是否暂停自动播放
		var scrollWrapId = "scrollWrap_"+$this.attr('id');//包裹对象id
		var $scrollWrap;//包裹对象
		var ChildSize = $this.children().size(); //获得子节点数量
		var singleSize = opt.type == "x" ? $this.children().outerWidth() : $this.children().outerHeight(); //获得单个子节点尺寸
		var overPlus = opt.type == "x" ? $this.width() - ChildSize* singleSize : $this.height() - ChildSize* singleSize;
		
		if(overPlus >= 0) {return false} //内容不够多时候自动退出

		if(opt.auto){
			opt.cycle = true;
			opt.action = "single";
		}
		
		//初始化
		var init = function(){
			$this.css({position:"relative",zIndex:0});
			
			if(opt.cycle){ //循环播放时将类容复制3份
				opt.action = "single";
				$this.html("<div id='"+scrollWrapId+"' style='position:absolute;z-index:0;'>"+$this.html() + $this.html() + $this.html()+"</div>");
			}else{
				$this.html("<div id='"+scrollWrapId+"' style='position:absolute;z-index:0;'>"+$this.html()+"</div>");
			}
			$scrollWrap = $this.find("#"+scrollWrapId);

			if(opt.type == "x"){
				$scrollWrap.width(singleSize*$scrollWrap.children().size()).css({left:0,top:0});
				if(opt.cycle){
					$scrollWrap.css("left",singleSize*ChildSize*(-1));
				}
			}else{
				$scrollWrap.height(singleSize*$scrollWrap.children().size()).css({top:0,left:0});
				if(opt.cycle){
					$scrollWrap.css("top",singleSize*ChildSize*(-1));
				}
			}
			
			//绑定事件
			if(opt.nextId){
				$("#" + opt.nextId).click(function(){
					if(opt.auto) {clearInterval(timeout);}
					if(opt.action == "single"){
						doanimate(-1);
					}else	if(opt.action == "group"){
						if(opt.type == "x"){
							doanimate(0-$this.width()/singleSize);
						}else{
							doanimate(0-$this.height()/singleSize);
						}
					}
					return false;
				});
			};
			if(opt.prevId){
				$("#" + opt.prevId).click(function(){
					if(opt.auto) {clearInterval(timeout);}
					if(opt.action == "single"){
						doanimate(1);
					}else	if(opt.action == "group"){
						if(opt.type == "x"){
							doanimate($this.width()/singleSize);
						}else{
							doanimate($this.height()/singleSize);
						}
					}
					return false;
				});
			}
			if(opt.auto){
				$this.hover(function(){
						clearInterval(timeout);
						timeout = "mmover";
					},
					function(){
						timeout = window.setInterval(function(){
							doanimate(-1);
						},opt.autotime)
					}
				)
			}
		}

		//移动事件
		var doanimate = function(n){
			if(scrollPause){return false;}
			scrollPause = true;
			var tmpPosVal = opt.type == "x" ? parseInt($scrollWrap.css("left")) : parseInt($scrollWrap.css("top"));
			if(tmpPosVal == 0  && n >0){scrollPause = false;return false;}
			if(tmpPosVal <= overPlus && !opt.cycle && n<0){scrollPause = false;return false;}
			if(opt.type == "x"){
				$scrollWrap.animate({left:tmpPosVal + n*singleSize},opt.speed,function(){
					checkPosition(tmpPosVal + n*singleSize,"x");
				});
			}else{
				$scrollWrap.animate({top:tmpPosVal + n*singleSize},opt.speed,function(){
					checkPosition(tmpPosVal + n*singleSize,"y");
				});
			}
		}
		
		//检测
		var checkPosition = function(v,p){
			scrollPause = false;
			if(opt.cycle){
				if(v == 0){
					if(p == "x"){
						$scrollWrap.css("left",singleSize*ChildSize*(-1));
					}else{
						$scrollWrap.css("top",singleSize*ChildSize*(-1));
					}
				}
				if(v <= singleSize*ChildSize*(-2)){
					if(p == "x"){
						$scrollWrap.css({left:singleSize*ChildSize*(-1)});
					}else{
						$scrollWrap.css({top:singleSize*ChildSize*(-1)});
					}
				}
			}
			if(opt.auto && timeout != "mmover"){
				clearInterval(timeout);
				timeout = window.setInterval(function(){
					doanimate(-1);
				},opt.autotime)
			}
		}

		if(opt.auto){
			var timeout = window.setInterval(function(){
				doanimate(-1);
			},opt.autotime)
		}
		
		init();

	}

	$.fn.dk_simplescroll.defaults = {
		type:   "x",         //滚动方向{x|y} 横向、纵向 默认x
		action: "single",    //滚动方式{single|group}单张、组 默认single
		cycle:  false,       //是否循环 默认false
		auto:  false,        //是否自动播放，自动播放时cycle默认为true 默认false
		autotime: 3000,      //自动播放间隔时间 默认为3000毫秒(3秒)
		speed: 500           //速度 300 默认500毫秒(5秒)
	}

	
})(jQuery);