


/* ================================================== */
/* ========== rem
/* ================================================== 
$(function(){
	if($(window).width() > 992){
		$('html').css('font-size','10px');
	}else{
		$('html').css('font-size',10 * $(window).width() / 992 + 'px');
	}
	$(window).resize(function(){
		if($(window).width() > 992){
			$('html').css('font-size','10px');
		}else{
			$('html').css('font-size',10 * $(window).width() / 992 + 'px');
		}
	});
});
*/


/* ================================================== */
/* ========== 选项卡 - 01(.iui-tab-one)
/* ================================================== */
$(function(){
	// 设置选项卡宽度
	$('.iui-tab-one .tabs .item').width(100 / $('.iui-tab-one .tabs .item').length + '%');
	
	// 定义变量(当前被选中的选项卡 index)
	var tabIndex = 0;
	
	// 选项卡 hover 事件
	/*$('.iui-tab-one .tabs .item').hover(function(){
		var index = $(this).index();
		$(this).parents('.iui-tab-one').children('.tabs').children('.item').each(function(){
			if($(this).hasClass('active')){
				tabIndex = $(this).index();
			}
		});
		$(this).parents('.iui-tab-one').children('.contents').children('.module').removeClass('active');
		$(this).parents('.iui-tab-one').children('.contents').children('.module').eq(index).addClass('active');
	},function(){
		$(this).parents('.iui-tab-one').children('.contents').children('.module').removeClass('active');
		$(this).parents('.iui-tab-one').children('.contents').children('.module').eq(tabIndex).addClass('active');
	});*/
	
	// 选项卡点击事件
	$('.iui-tab-one .tabs .item').click(function(){
		var index = $(this).index();
		tabIndex = index;
		$(this).siblings('.item').removeClass('active');
		$(this).addClass('active');
		$(this).parents('.iui-tab-one').children('.contents').children('.module').removeClass('active');
		$(this).parents('.iui-tab-one').children('.contents').children('.module').eq(index).addClass('active');
	});
});



/* ================================================== */
/* ========== 模态窗-01(.iui-modal-one)
/* ================================================== */
$(function(){
	// 点击模态窗关闭该模态窗
	$('.iui-modal-one').click(function(e){
		$(this).hide();
	});
	
	// 点击内容区域时不关闭该模态窗
	$('.iui-modal-one .content-wrap').click(function(even){
		even.stopPropagation();
	});
	
	// 点击关闭按钮关闭模态窗
	$('.iui-modal-one .closed').click(function(){
		$(this).parents('.iui-modal-one').hide();
	});
});
// 当右左右切换图片是调用该方法。obj：单张图片盒子对象
function iuiModalOne(obj){
	// 显示模态窗
	$('.iui-modal-one').show();
	
	// 点击模态窗关闭该模态窗
	$('.iui-modal-one').click(function(e){
		$(this).hide();
	});
	
	// 点击内容区域时不关闭该模态窗
	$('.iui-modal-one .content-wrap').click(function(even){
		even.stopPropagation();
	});
	
	// 点击关闭按钮关闭模态窗
	$('.iui-modal-one .closed').click(function(){
		$(this).parents('.iui-modal-one').hide();
	});
	// 变量定义
	var index = obj.index(); // 点击的图片 index
	var len = obj.siblings('.picture-wrap').length + 1; // 获取总图片数
	var autoSrc = obj.find('.picture').attr('src'); // 获取点击图片的 src
	
	// 设置默认显示的图片为点击的图片
	$('.iui-modal-one .show-pictrues').attr('src',autoSrc);
	
	// 点击切换下一张图片
	$('.iui-modal-one .arrow-next').click(function(){
		index++;
		console.log(index + '...' + len);
		if(index >= len){
			index = 0;
		}
		var src = obj.parents('.iui-picture-list').find('.picture-wrap').eq(index).find('.picture').attr('src');
		$('.iui-modal-one .show-pictrues').attr('src',src);
	});
	
	// 点击切换下一张图片
	$('.iui-modal-one .arrow-prev').click(function(){
		index--;
		console.log(index + '...' + len);
		if(index < 0){
			index = len - 1;
		}
		var src = obj.parents('.iui-picture-list').find('.picture-wrap').eq(index).find('.picture').attr('src');
		$('.iui-modal-one .show-pictrues').attr('src',src);
	});	
}

/* ================================================== */
/* ========== 焦点轮播图 - 01
/* ================================================== */
;(function($,window,document,undefined){
	// 插件实现
	var iCarouseOne = function(element,options){
		this.$element = element;
		this.defaults = {
			// 设置轮播图高度
			height : null,
			
			// 设置轮播图宽度
			width : null,
			
			//默认显示页面，从0开始,默认为0
			pageIndex : 0,
			
			//切换用时，单位（秒）
			slidingTime : 1,
			
			// 是否自动轮播
			autoCarouse : true,
			
			// 自动轮播间隔时间，单位（毫秒）
			interval : 6000,
			
			// 回调函数，参数 index：当前页面 index
			onleave : function(index){},
			
			// 回调函数，参数 index：当前页面 index
			onFadeIn : function(index){},
		};
		this.options = $.extend(true,this.defaults,options||{});
		
		/* ------------------------------ */
		/* 定义对象
		/* ------------------------------ */
		var me = this,
			options = me.options,
			iuiCarouseOne = me.$element, // iuiCarousOne obj
			banners = iuiCarouseOne.children('.banners'), // banners obj
			buttons = iuiCarouseOne.children('.buttons'); // buttons obj
		
		
		/* ------------------------------ */
		/* 定义变量
		/* ------------------------------ */
		var pageIndex = options.pageIndex; // 默认显示页面
		
		
		/* ------------------------------ */
		/* 设置滑动时间
		/* ------------------------------ */
		function setSlidingTime(){
			banners.children('.page').css('transition','all ' + options.slidingTime + 's');
			banners.children('.page').css('-webkit-transition','all ' + options.slidingTime + 's');
			banners.children('.page').css('-moz-transition','all ' + options.slidingTime + 's');
			banners.children('.page').css('-ms-transition','all ' + options.slidingTime + 's');
		}
		setSlidingTime();
		
		
		/* ------------------------------ */
		/* 设置轮播图宽高
		/* ------------------------------ */
		function setArea(){
			if(options.height != null){
				iuiCarouseOne.height(options.height);
			}
			if(options.width != null){
				iuiCarouseOne.width(options.width);
			}
			//宽高随窗口缩放
			$(window).resize(function(){
				if(options.height != null){
					iuiCarouseOne.height(options.height);
				}
				if(options.width != null){
					iuiCarouseOne.width(options.width);
				}
				//console.log(options.height());
			});
			//console.log(options.height());
		}
		setArea();
		
		
		/* ------------------------------ */
		/* 添加按钮，并设置按钮左右居中
		/* ------------------------------ */
		function setButtons(){
			for(var i = 0; i < banners.children('.page').length; i++){
				buttons.append('<li class="button"></li>');
			}
			buttons.css('margin-left',function(){
				return - $(this).outerWidth() / 2 + 'px';
			});
		}
		setButtons();
		
		
		/* ------------------------------ */
		/* 设置默认显示页面
		/* ------------------------------ */
		function setAutoPage(){
			if(pageIndex >= banners.children('.page').length || pageIndex < 0){
				pageIndex = 0;
			}
			banners.children('.page').removeClass('show');
			banners.children('.page').eq(pageIndex).addClass('show');
			
			// 默认在 active 状态的按钮
			buttons.children('.button').eq(pageIndex).addClass('active');
			
			// 回调函数
			options.onFadeIn(pageIndex);
		}
		setAutoPage();
		
		
		/* ------------------------------ */
		/* 右切换函数
		/* ------------------------------ */
		function next(index){
			banners.children('.page').removeClass('show');
			banners.children('.page').eq(index).addClass('show');
			
			// 切换按钮
			buttons.children('.button').removeClass('active');
			buttons.children('.button').eq(index).addClass('active');
			
			// 回调函数 onFadeIn
			options.onFadeIn(index);
		}
		
		
		/* ------------------------------ */
		/* 左切换函数
		/* ------------------------------ */
		function prev(index){
			banners.children('.page').removeClass('show');
			banners.children('.page').eq(index).addClass('show');
			
			// 切换按钮
			buttons.children('.button').removeClass('active');
			buttons.children('.button').eq(index).addClass('active');
			
			// 回调函数 onFadeIn
			options.onFadeIn(index);
		}
		/* ------------------------------ */
		/* 点击按钮事件
		/* ------------------------------ */
		buttons.children('.button').click(function(){
			var index = $(this).index(); // 点击的按钮 index
			
			// 回调函数 onLeave
			options.onLeave(pageIndex);
			
			// 切换页面
			if(index > pageIndex){
				next(index);
			}else{
				prev(index);
			}
			
			// 重置 pageIndex
			pageIndex = index;
		});


		/* ------------------------------ */
		/* 点击下一页按钮事件
		/* ------------------------------ */
		iuiCarouseOne.children('.arrow-next').click(function(){
			// 回调函数 onLeave
			options.onLeave(pageIndex);
			
			pageIndex++;
			
			if(pageIndex >= banners.children('.page').length){
				pageIndex = 0;
			}
			
			// 切换图片
			next(pageIndex);
		});
		
		/* ------------------------------ */
		/* 点击上一页按钮事件
		/* ------------------------------ */
		iuiCarouseOne.children('.arrow-prev').click(function(){
			// 回调函数 onLeave
			options.onLeave(pageIndex);
			
			pageIndex--;
			
			if(pageIndex < 0){
				pageIndex = banners.children('.page').length - 1;
			}
			// 切换图片
			prev(pageIndex);
		});
	
		/* ------------------------------ */
		/* 自动轮播函数
		/* ------------------------------ */
		function autoCarouse(){
			if(options.autoCarouse){
				setInterval(function(){
					// 回调函数 onLeave
					options.onLeave(pageIndex);

					pageIndex++;
					
					if(pageIndex >= banners.children('.page').length){
						pageIndex = 0;
					}
					
					// 切换图片
					next(pageIndex);
				},options.interval);
			}
		}
		autoCarouse();
	}
	// 定义插件
	$.fn.iuiCarouselOne = function(options){
		return this.each(function(){
			var me = $(this),
				instance = me.data('iuiCarouseOne');
			if(!instance){
				instance = new iCarouseOne(me,options);
				me.data('iuiCarouseOne',instance);
			}
		});
	}
})(jQuery,window,document);




$(function(){
	var eventX = 0;
	var eventY = 0;
	function handleTouchEvent(event) {		
	    //只跟踪一次触摸	   
	    if (event.touches.length == 1) {	        
	        switch (event.type) {
	        	// dj
	            case "touchstart":
	            	eventX = event.changedTouches[0].clientX; 
	                break;
	            // lk
	            case "touchend":	               
	            	eventY = event.changedTouches[0].clientX;	   
					
					if(eventY>eventX) {						
						$('.index-case-carousel-mb .banners').find('.page').each(function(){
							$this = $(this);
							thisi = $this.index();
							
							$('.index-case-carousel-mb .banners ').find('.page').eq(thisi+1).addClass('show').siblings('.page').removeClass('show');
							})
						}   
						 	
	                break;
	            // hd
	            /*case "touchmove":
	               // $('.iui-carousel-one .banners .page').css({'left':event.changedTouches[0].clientX-eventX+'px'});	                
	             break;*/
	        }
	    }
	}
	
	$('.index-case-carousel-mb .banners').bind('touchstart touchend touchmove',function(){
		handleTouchEvent(event);
	});	
	
	$('.index-case-carousel-mb .banners').on('touchend',function(){
		eventY = event.changedTouches[0].clientX;
		eventnum = 	eventY-eventX;	
					if(eventnum>30) {												
						eventindex = $('.index-case-carousel-mb ul.buttons').find('.active').index();
										
						$('.index-case-carousel-mb ul.buttons').find('li').eq(eventindex+1).click();
						} 
					if(eventnum<30){
						eventindex = $('.index-case-carousel-mb ul.buttons').find('.active').index();
										
						$('.index-case-carousel-mb ul.buttons').find('li').eq(eventindex-1).click();
						}
		})
});


$(function(){
	var eventX = 0;
	var eventY = 0;
	function handleTouchEvent(event) {		
	    //只跟踪一次触摸	   
	    if (event.touches.length == 1) {	        
	        switch (event.type) {
	        	// dj
	            case "touchstart":
	            	eventX = event.changedTouches[0].clientX; 
	                break;
	            // lk
	            case "touchend":	               
	            	eventY = event.changedTouches[0].clientX;	   
					
					if(eventY>eventX) {						
						$('.index-firend-chain-carousel-mb .banners').find('.page').each(function(){
							$this = $(this);
							thisi = $this.index();
							
							$('.index-firend-chain-carousel-mb .banners ').find('.page').eq(thisi+1).addClass('show').siblings('.page').removeClass('show');
							})
						}    	
	                break;
	            // hd
	            /*case "touchmove":
	               // $('.iui-carousel-one .banners .page').css({'left':event.changedTouches[0].clientX-eventX+'px'});	                
	             break;*/
	        }
	    }
	}
	$('.index-firend-chain-carousel-mb .banners').bind('touchstart touchend touchmove',function(){
		handleTouchEvent(event);
	});	
	$('.index-firend-chain-carousel-mb .banners').on('touchend',function(){
		eventY = event.changedTouches[0].clientX;
		eventnum = 	eventY-eventX;	
					if(eventnum>30) {												
						eventindex = $('.index-firend-chain-carousel-mb ul.buttons').find('.active').index();
										
						$('.index-firend-chain-carousel-mb ul.buttons').find('li').eq(eventindex+1).click();
						} 
					if(eventnum<30){
						eventindex = $('.index-firend-chain-carousel-mb ul.buttons').find('.active').index();				
						$('.index-firend-chain-carousel-mb ul.buttons').find('li').eq(eventindex-1).click();
						}
		})
});

$(function(){
	var eventX = 0;
	var eventY = 0;
	function handleTouchEvent(event) {		
	    //只跟踪一次触摸	   
	    if (event.touches.length == 1) {	        
	        switch (event.type) {
	        	// dj
	            case "touchstart":
	            	eventX = event.changedTouches[0].clientX; 
	                break;
	            // lk
	            case "touchend":	               
	            	eventY = event.changedTouches[0].clientX;	   
					
					if(eventY>eventX) {						
						$('.index-case-carousel-mb .banners').find('.page').each(function(){
							$this = $(this);
							thisi = $this.index();
							
							$('.index-case-carousel-mb .banners ').find('.page').eq(thisi+1).addClass('show').siblings('.page').removeClass('show');
							})
						}   
						 	
	                break;
	            // hd
	            /*case "touchmove":
	               // $('.iui-carousel-one .banners .page').css({'left':event.changedTouches[0].clientX-eventX+'px'});	                
	             break;*/
	        }
	    }
	}
	$('.index-case-carousel-mb .banners').bind('touchstart touchend touchmove',function(){
		handleTouchEvent(event);
	});	
	$('.index-case-carousel-mb .banners').on('touchend',function(){
		eventY = event.changedTouches[0].clientX;
		eventnum = 	eventY-eventX;	
					if(eventnum>30) {												
						eventindex = $('.index-case-carousel-mb ul.buttons').find('.active').index();
										
						$('.index-case-carousel-mb ul.buttons').find('li').eq(eventindex+1).click();
						} 
					if(eventnum<30){
						eventindex = $('.index-case-carousel-mb ul.buttons').find('.active').index();
										
						$('.index-case-carousel-mb ul.buttons').find('li').eq(eventindex-1).click();
						}
		})
});








