/*PowerBy ydw0117 QQ:59978934*/
;(function($){
$.fn.extend({
/*tabs选项卡*/
"Tabs":function(options){
  options=$.extend({
    mode:"click",
    index:"1"
  },options);
  options.index = parseInt(options.index);
  var caption_li = "#"+$(this).attr("id")+">.tabs_caption>ul>li";
  var tabs_item = "#"+$(this).attr("id")+">.tabs_content>.tabs_item";
  var tabs_caption_a = "#"+$(this).attr("id")+">.tabs_caption>ul>li>a";
  $(caption_li).eq(options.index - 1).addClass("select").siblings().removeClass("select");
  $(tabs_item).eq(options.index - 1).show().siblings().hide();
  if (options.mode == "click") {
    $(caption_li).click(function() {
      options.index = $(this).index(caption_li);
      $(this).addClass("select").siblings().removeClass("select");
      $(tabs_item).eq(options.index).show().siblings().hide();
      return false;
    });
  }
  if (options.mode == "mouseover") {
    $(caption_li).hover(
	  function(){
        options.index = $(this).index(caption_li);
        $(this).addClass("select").siblings().removeClass("select");
        $(tabs_item).eq(options.index).show().siblings().hide();
	  },function(){}
	);
	$(tabs_caption_a).click(function(){return false;});
  }
},
/*******************************************/
/*获得及指定tabs选项卡打开项*/
"Tabs_Current":function(options){
  options=$.extend({
    current:""
  },options);
  if(!options.current){
    var caption_li ="#"+this.attr("id")+">.tabs_caption>ul>li"; 
	var $caption_li_select = $(this).children(".tabs_caption").children("ul").children("li.select"); 
	options.current = $caption_li_select.index(caption_li);
    return (options.current+1);
  }else{
    var caption_li = "#"+this.attr("id")+">.tabs_caption>ul>li"; 
    var tabs_item  = "#"+this.attr("id")+">.tabs_content>.tabs_item";
    $(caption_li).eq(options.current - 1).addClass("select").siblings().removeClass("select");
    $(tabs_item).eq(options.current - 1).show().siblings().hide();
	return (options.current);
  }
},
/*******************************************/
/*值隔行变色及鼠标移上变色*/
"Interlaced_Color":function(options){
  options=$.extend({
    even:"",
	odd:"",
    hover:""
  },options);
  if(options.odd){
    $(this).children(":odd").addClass(options.odd);
  }
  if(options.even){
    $(this).children(":even").addClass(options.even);
  }
  if(options.hover){
    this.children().hover(
      function(){
        $(this).addClass(options.hover);
	  },
	  function(){
	    $(this).removeClass(options.hover);
	  }
    );
  }
  return this;
},
/*input默认值,获得焦点*/
"Default_Values":function(options){
  options=$.extend({
    focus_class:"",
	def_val:""
  },options);
  if(options.def_val){
    $(this).val(options.def_val);
  }
  $(this).focus(function(){
	if(options.focus_class){
	  $(this).addClass(options.focus_class);
	}
	if(options.def_val){
	  var txt_val = $(this).val();
      if(txt_val == options.def_val){
        $(this).val("");
      }
	}
  }).blur(function(){
    if(options.focus_class){
	  $(this).removeClass(options.focus_class);
	}
	if(options.def_val){
	  var txt_val = $(this).val();
      if(txt_val == ""){
        $(this).val(options.def_val);
      }
	}
  });
  return this;
},
/*******************************************/
/*last取消，常用于导航*/
"Last_None":function(options){
  options=$.extend({
    css_name:"background-image"
  },options);
  $(this).css(options.css_name,"none");
  return this;
},
/*******************************************/
/*hover模仿*/
"Hover":function(options){
  options=$.extend({
	css_name:"hover"
  },options);
  $(this).hover(
	function(){
	  $(this).addClass(options.css_name);		
	},
	function(){
	  $(this).removeClass(options.css_name);			
	}
  );
  return this;
},
/*******************************************/
/*列表hover模仿*/
"List_Hover":function(options){
  options=$.extend({
	son_1:"img",
	son_2:"span",
	css_1:"hover",
	css_2:"hover"
  },options);
  $(this).hover(
	function(){
	  $(this).children(options.son_1+","+options.son_2).addClass("hover");		
	},
	function(){
	  $(this).children(options.son_1+","+options.son_2).removeClass("hover");			
	}
  );
  return this;
},
/*******************************************/
/*弹出层*/
"My_box":function(options){
  options=$.extend({
	bg_color:"#000000",
	opacity:"0.4"
  },options);
$(this).click(function(){
  $("body .body_div").remove();	
  var window_height = $(window).height();
  var scroll_top = $(document).scrollTop();
  var body_width = $("body").css("width");
  var body_height = $("body").css("height");
  var count = Math.ceil((parseInt(body_height)/window_height))-1;
  var height=0;
  var curr=0;
  for(i=count;i>=1;i--){
    height =  window_height*i;
	curr = i;
	if(scroll_top>=height){break;}
  }
  scroll_top = curr*scroll_top;
  var ajax_add = $(this).attr("href");
  var con_height;
  $("body").append("<div class='body_div'><div class='bg'></div><div class='div_content'></div>");
  $("body .body_div .bg").css({width:body_width,height:body_height,"background-color":options.bg_color,opacity:options.opacity});
  $("body .div_content").css({width:body_width});
  var app_dom = $(ajax_add).html();
  $("body .div_content").html(app_dom);
  $(ajax_add).html("");
  con_height = $("body .div_content").height();
  if(con_height<window_height){
	var top = Math.ceil((window_height-parseInt(con_height))/2);
    var top_num = top+scroll_top;
	$("body .div_content").css({height:body_height,top:top_num});
  }else{
	var top_num = scroll_top;
	body_height = parseInt(body_height)+con_height;
	$("body .body_div").css({height:body_height+"px"});
	$("body .body_div .bg").css({height:body_height+"px"});
	$("body .div_content").css({top:top_num});  
  }
  $("body .close").live("click",function(){
	$("body .body_div").remove();
	$(ajax_add).html(app_dom);
  });
  return false;
});
},
/*******************************************/
/*Slide*/
"Slide":function(options){
  options=$.extend({
    num:"3"
  },options);
  $(this).append("<div class='banner_num'></div>")
  var id= $(this).attr("id");
  var banner_num  = "#"+id+">.banner_num";
  var num_item = banner_num+">span";
  var banner_a = "#"+id+">a";
  var img_page = $(banner_a).length-1;
  var first = num_item+":first";
  var current = 0;
  var timer;
  var i;
  if(img_page>(options.num)){
	img_page=options.num;  
  }
  for(i=0;i<=img_page;i++){
	$(banner_num).append("<span>"+(i+1)+"</span>");
  }
  $(num_item).click(
  function(){
     clearInterval(timer);
     current = $(this).index(num_item);
       if(current == img_page){
         $(num_item).eq(img_page).addClass("on").siblings().removeClass("on");
	     $(banner_a).eq(img_page).fadeIn(1000).siblings("a").fadeOut(1000);	
	     current = 0;
	   }else{
	     $(num_item).eq(current).addClass("on").siblings().removeClass("on");
         $(banner_a).eq(current).fadeIn(1000).siblings("a").fadeOut(1000);	
	     current++;
	   }
	 timer = setInterval(banner,4500);
   });
   timer = setInterval(banner,4500);
   function banner(){
     $(num_item).eq(current).trigger("click");
   }
  $(first).trigger("click");
},
/*******************************************/
/*Slide*/
"Radio":function(options){
  options=$.extend({
  },options);
  var top = $(this).attr("id");
  var radio_item = "#"+top+" .radio_choose .radio"
  $(radio_item).live("click",function(){
	$(this).addClass("radio_check").siblings().removeClass("radio_check");		
	var index = $(this).index(radio_item);
	$(this).parents(".radio_simulation").find(".raio_receive input").eq(index).attr("checked","checked");
  });	
}
/*******************************************/
});
})(jQuery)
/*无限滚动*/
;(function($){
	$.fn.kxbdMarquee = function(options){
		var opts = $.extend({},$.fn.kxbdMarquee.defaults, options);
		return this.each(function(){
			var $marquee = $(this);
			var _scrollObj = $marquee.get(0);
			var scrollW = $marquee.width();
			var scrollH = $marquee.height();
			var $element = $marquee.children(); 
			var $kids = $element.children();
			var scrollSize=0;
			var _type = (opts.direction == 'left' || opts.direction == 'right') ? 1:0;
			$element.css(_type?'width':'height',10000);
			if (opts.isEqual) {
				scrollSize = $kids[_type?'outerWidth':'outerHeight']() * $kids.length;
			}else{
				$kids.each(function(){
					scrollSize += $(this)[_type?'outerWidth':'outerHeight']();
				});
			}
			if (scrollSize<(_type?scrollW:scrollH)) return; 
			$element.append($kids.clone()).css(_type?'width':'height',scrollSize*2);		
			var numMoved = 0;
			function scrollFunc(){
				var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft':'scrollTop';
				if (opts.loop > 0) {
					numMoved+=opts.scrollAmount;
					if(numMoved>scrollSize*opts.loop){
						_scrollObj[_dir] = 0;
						return clearInterval(moveId);
					} 
				}
				if(opts.direction == 'left' || opts.direction == 'up'){

					var newPos = _scrollObj[_dir] + opts.scrollAmount;
					if(newPos>=scrollSize){
						newPos -= scrollSize;
					}
					_scrollObj[_dir] = newPos;
				}else{
					var newPos = _scrollObj[_dir] - opts.scrollAmount;
					if(newPos<=0){
						newPos += scrollSize;
					}
					_scrollObj[_dir] = newPos;
				}
			}
			var moveId = setInterval(scrollFunc, opts.scrollDelay);
			$marquee.hover(
				function(){
					clearInterval(moveId);
				},
				function(){
					clearInterval(moveId);
					moveId = setInterval(scrollFunc, opts.scrollDelay);
				}
			);
			
		});
	};
	$.fn.kxbdMarquee.defaults = {
		isEqual:true,
		loop: 0,
		direction: 'left',
		scrollAmount:1,
		scrollDelay:20
	};
	$.fn.kxbdMarquee.setDefaults = function(settings) {
	$.extend( $.fn.kxbdMarquee.defaults, settings );
	};
})(jQuery);
