﻿// ----------鼠标滑轮横向滚动
/*(function() {
  var stepSize = 200, //每滚动一格鼠标，移动多少距离
      doc = document.documentElement,
      body = document.body,
      docWidth = doc.clientWidth,
      scrollLeft = 0;
 
  //添加mousewheel事件
  if (document.addEventListener) {
	document.addEventListener('mousewheel', scroll, false);
  } else {
	document.attachEvent('onmousewheel',scroll) //针对老ie浏览器
  }
   
  //处理mousewheel事件的信息
  function scroll (event) {
	var direction = event.wheelDelta;
	//保证滚动到头的时候不再调用update函数
	if (scrollLeft <= 0 && direction > 0) {
	  return;
	}
	if (scrollLeft >= docWidth && direction < 0) {
	  return;
	}
	//根据鼠标滚动的方向确定是往左还是往右移动
	var distance = direction > 0? -stepSize : stepSize;
	update(distance);
  }
   
  //滚动
  function update (distance) {
	scrollLeft += distance;
	doc.scrollLeft = scrollLeft;
	body.scrollLeft = scrollLeft; //针对webkit浏览器
  } 
  })();*/

/*鼠标坐标*/
var xy_x=0;
$(document).mousemove(function(e){
	e = window.event || e;
	xy_x = e.screenX;
});

(function () {
// ----------主导航
  var colors = ['#e74c3c','#9d5cb7','#3498db','#1abc9c','#2ecc71','#f1c40f','#e67e22','#c0392b','#8e44ad','#2980b9','#16a085','#27ae60','#f39c12','#d35400'];
  var liWidth = $('#Menu ul').innerWidth();
  $('#Menu ul').children('li').each(function(i) {
	  var cloneLi = $(this).children('a').clone().css({'background':colors[i],'color':'#fff'});
	  $(this).append(cloneLi);
	  $(this).hover(function(){
		$(this).stop(true,false).animate({left:liWidth*-1},{duration:600,easing:"easeOutBack"})
	  },function(){
		$(this).stop(true,false).animate({left:0},{duration:600,easing:"easeOutBack"})
	  })
  });
  
  /*导航栏自动隐藏*/
  autoHide = setInterval(function() {
	$('#Menu').stop(true,true).animate({'left':liWidth*-1});
	clearInterval(autoHide);
  },15000);
  clearInterval(autoHide);
  
  $('#btns1').click(function(){
	$('#Menu').stop(true,true).animate({'left':0});
	clearInterval(autoHide);
	autoHide = setInterval(function() {
	$('#Menu').stop(true,true).animate({'left':liWidth*-1});
	clearInterval(autoHide);
  },8000);
	autoHide;
  })

  $('#Menu').hover(function(){
	  clearInterval(autoHide);
	  $(this).stop(true,true).animate({'left':0});
  },function(){
	if(xy_x > liWidth){
	  $(this).stop(true,true).animate({'left':liWidth*-1});
	}
  })
	
  /*搜索*/
  $('#btns5').click(function(){
	$(this).fadeOut('fast');
	$('#search_form').fadeIn('fast');
  })
})(jQuery);

/*鼠标移过显示边框*/
(function($){
   $.fn.showBorder = function(options){
	 var defaults = {
		  content:'<div class="selected"></div>'
	  }
	 var options = $.extend(defaults, options);
     return this.each(function () {
		 //var _this = $(this);
		 $(this).hover(function(){
			$(this).append(options.content); 
		 },function(){
			if($(this).children('.selected').length>0){
				 $(this).children('.selected').remove();
			}
		 })	
	 });

  }
})(jQuery);

// ----------翻转类
(function () {
  $.fn.Flip = function (speed,millisec) {
	  return this.each(function (i) {
		  var curr = 0,
		      Flip_li = $(this).children('li').size(),
		      autoFlip = true,
			  LAR = false;
		  if($(this).innerHeight()>$(this).innerWidth() || $(this).attr('data-Mode')==1){
			 LAR = true; 
			 $(this).children('li:last').css({'width':0});
		  }else
		  {$(this).children('li:last').css({'height':0});}
		  
		   
		  function FlipMc(obj) {
		    setInterval(function () {
			  if(autoFlip){
				todo = (curr + 1) % Flip_li;
				var currLi = $(obj).children('li').eq(curr);
				var nextLi = $(obj).children('li').eq(todo);
				if(LAR){/*左右翻*/
				  currLi.stop(true,true).animate({width:'0',left:'50%'},speed).hide('fast',function(){
					nextLi.stop(true,true).css('left','50%').show().animate({width:'100%',left:'0'},speed);
				  });
			    }else{/*上下翻*/
				  currLi.stop(true,true).animate({height:'0',top:'50%'},speed).hide('fast',function(){
					nextLi.stop(true,true).css('top','50%').show().animate({height:'100%',top:'0'},speed);
				  });
				}
				curr = todo;
				return this;
			  }
			}, millisec+i*500);
		  }
		  
		  $(this).hover(function(){
			autoFlip = false;
		  },function(){
			autoFlip = true;
		  })

		  FlipMc($(this));

	  });
  };
})(jQuery);

//----------幻灯片类
(function () {
  $.fn.Slideshow = function (speed,millisec) {
	  return this.each(function (i) {
		var curr = 0,
			child_size = $(this).children('li').size(),
			autoPlay = true,
		    _this = $(this);
		
		/*添加按钮*/
		if(child_size>1){
		  var btn = "<a class='prev'><span class='icon-arrow-left3'></span></a>";
		  btn += "<a class='next'><span class='icon-arrow-right3'></span></a>";
		  $(this).append(btn);
		}
		
		/*上一页按钮*/
		$(this).find('.prev').click(function() {
			todo = curr-1<0?child_size-1:curr-1;
			var currLi = _this.children('li').eq(curr);
			var prevLi = _this.children('li').eq(todo);
			currLi.css({'z-index':90}).stop(true,false).animate({'left':'50%'},speed,function(){$(this).css('display','none')});
			prevLi.css({'z-index':91,'display':'block','left':'-100%'}).stop(true,false).animate({'left':'0'},speed);
			curr = todo;
		});
	
		/*下一页按钮*/
		$(this).find('.next').click(function() {
			todo = (curr + 1) % child_size;
			var currLi = _this.children('li').eq(curr);
			var nextLi = _this.children('li').eq(todo);
			currLi.css({'z-index':91}).stop(true,false).animate({'left':'-100%'},speed,function(){$(this).css('display','none')});
			nextLi.css({'z-index':90,'display':'block','left':'50%'}).stop(true,false).animate({'left':'0'},speed);
			curr = todo;
		});
		
		/*自动播*/
		autoPlay = setInterval(function() {
		  if(autoPlay && child_size>0){
		    _this.find('.next').click();
		  }
		},millisec+i*250);
		
		$(this).hover(function() {
		  autoPlay = false;
	    },function() {
		  autoPlay = true;
	    })

	  });
  };
})(jQuery);

//----------图标类
(function () {
  $.fn.Icon = function () {
	  return this.each(function () {
		 $(this).find('span').css('font-size',$(this).innerWidth()<=$(this).innerHeight()?$(this).innerWidth()*0.5:$(this).innerHeight()*0.5)
	  });
  };
})(jQuery);

//----------图片类
(function () {
  $.fn.picture = function (speed,millisec) {
	  return this.each(function (i) {
		 if($(this).attr('data-mode')!='noTit' && $(this).children('span').length >0){
		  var tit = $(this).children('span');
		  $(this).hover(function(){
			  tit.stop().animate({bottom:0},'fast')
		  },function(){
			  tit.stop().animate({bottom:tit.innerHeight()*-1},'fast')
		  })
		} 
	  });
  };
})(jQuery);

//--------------------------------------Label切换定义
  window.SwitchLable = function(Lable,SwitchContent,BtnID){
	$(Lable + " li:first").addClass("active");
	if($(BtnID).length > 0 && $(Lable + " li:first").children("a").attr("rel").length>0){
	  	$(BtnID).attr("href",$(Lable + " li:first").children("a").attr("rel"));
	}
	var perWidth = $(SwitchContent).children().first().outerWidth(true);
	$(Lable + " li").each(function(i){
	  $(this).click(function(){
	   //currLabel=i;
	   $(this).addClass("active");
	   $(this).siblings().removeClass("active");
	   $(SwitchContent).stop(true,true).animate({'left':i*perWidth*-1},{duration:800,easing:'easeInQuart'});
	   
	   if($(BtnID).length > 0 && $(this).children("a").attr("rel").length>0){
		  $(BtnID).attr("href",$(this).children("a").attr("rel"));
		}
		
	  })
	});
  };