function windowLoadingPage(){// 页面加载执行
	var winw = $(window).width();
	var winh = $(window).height();
	
	$('#header-block').height($('#header').outerHeight());
	
	/*text-line兼容*/
	$('.text-line').each(function(){
		var lineHeight = parseFloat($(this).css('line-height'));
		var this_class = $(this).attr('class');
		var this_reg = /line[0-9]$/;
		if(this_class.match(this_reg)){
			var this_match = this_class.match(this_reg);
			var this_height = this_match[0].replace(/line/,'');
			$(this).css({'height':lineHeight*this_height+'px'});
		}else{
			$(this).height(lineHeight*2);
		}
	});
	
}

$(window).off('load,resize').on({
	load: function(){
		windowLoadingPage();
	},
	resize: function(){
		windowLoadingPage();
	}
});

$(window).scroll(function(){// 页面滚动

	var wins = $(window).scrollTop();
	
	if(!$('#header').hasClass('relative')){
		$('#header').removeClass('cur');
	}
	$('#phone-nav').stop(true,true).slideUp();
	
	/*首页*/
	if($('#index').size()){
		
		/*头部*/
		if(wins>1){
			$('#header').addClass('cur');
		}else{
			$('#header').removeClass('cur');
		}		
	}
	
	/*页面滚动*/
	if($(window).width()>=1024){
		$('[data-scroll-top]').each(function(){
			
			var t = $(this),
				obj = t.attr('data-scroll-top'),
				objt = $(obj).offset().top,
				objh = $(obj).outerHeight(),
				sct = t.offset().top;
			
			if(wins>objt && wins<sct){
				//console.log(wins,objt,(wins-objt));
				t.css({'margin-top':'-'+(wins-objt)+'px'});
			}
		});
	}
	
})




$(document).ready(function(){// 开始执行js
	
	$('[data-top]').click(function(){
		$('html,body').animate({scrollTop:0}, 700);
	});
	
	$('[data-index-one]').click(function(){
		if($(this).hasClass('cur')){
			window.location.href = $(this).attr('url');
		}
	})
	
	$('#index .one .item-five .slide .list').click(function(){
		var p_index = $(this).parents('.slide').index()*9;
		var t_index = $(this).index();
		var index = p_index+t_index;
		
		$('#index .one .item-five .slide .list').removeClass('cur');
		$(this).addClass('cur');
		
		$.swiper('.inside-CaseViewOne .img .item-one').slideTo(index);
	})
	
	$('[data-why-click]').click(function(){
		var index = $(this).index();
		$('[data-why-click]').eq(index).addClass('cur').siblings('[data-why-click]').removeClass('cur');
		$('#index .thr .item').find('[data-why-click]').eq(index).addClass('cur').siblings('[data-why-click]').removeClass('cur');
	})
	
	$('#header .target').click(function(){
		$('#header').toggleClass('cur');
		$('#phone-nav').stop(true,true).slideToggle();
	})
	
	$('#footer .one .item .title').click(function(){
		var p = $(this).parents('.item');
		
		p.toggleClass('cur');
	})
	
	if($(window).width()<1024){
		$('#header .right .other .search .icon').click(function(){
			$('#header .right .other .search .form').toggleClass('cur');
		})
	}
	
	if($('[data-map-slide]').size()){
		
		/*鼠标移动过去展示*/
		function mouseShow(){
			if($(window).width()>980){
				$('[data-map-slide]').hover(function(){
					var index = $(this).index(),
						obj = $(this).data('map-slide');
					
					$(obj).eq(index).addClass('cur').siblings().removeClass('cur');
				},function(){
					var obj = $(this).data('map-slide');
					$(obj).removeClass('cur');
				});
			}else{// 手机版改成点击事件
				$('[data-map-slide]').click(function(){
					var index = $(this).index(),
						obj = $(this).data('map-slide');
					
					$(this).addClass('cur').siblings().removeClass('cur');
					$(obj).eq(index).addClass('cur').siblings().removeClass('cur');
				});
			}

			$('[data-map-slide]').click(function(){
				$(this).addClass('on');
			})
			$('[data-map-slide]').hover(function(){

			},function(){
				$('[data-map-slide]').removeClass('on');
			})
		}
		mouseShow();
		
		$('[data-country]').click(function(){
			var CateId = $(this).data('country');
			$.post('/ajax/inside-country',{CateId:CateId},function(data){
				$('[data-country-append]').append(data);
				mouseShow();
			});
		});
		
		/*随机波浪*/
		$('[data-map-slide]').each(function(){
			
		});
		
	}
		
})

/*弹窗开始*/

function alertWindow(State,ExtId){
	$.post('/ajax/alert-window',{State:State,ExtId:ExtId},function(data){

		if($('#alert-window').length){return false;}
		if(data=='false'){$.alert({str:'错误操作',btn:1});}

		$('body').append(data);
		submitFeedback();
		sendSms();
		
		setTimeout(function(){
			$('#alert-window').addClass('show');
		},100);
		
	});
}

function alertWindowShutdown(){
	$('#alert-window').removeClass('show');
	setTimeout(function(){
		$('#alert-window').remove();
	},300);
}

/*弹窗结束*/

function submitFeedback(){
	$('[data-feedback]').form({// feedback
		url:'/api/web/feedback',
		check: function(c,f){
			this.load = $.alert('loading');
		},
		end: function(d,f){
			this.load.remove(function(){
				if(d.ret=='download'){
					window.location.href = "/api/web/download?id="+d.msg;
				}else if(d.ret=='join'){
					$.alert({str:d.msg,time:1500,end:function(){
						window.location.reload();
					}});
				}else{
					$.alert({str:d.msg,btn:1});
				}
			});
		}
	});
}

function sendSms(){
	var sendCode = {//获取验证码
		b : '.sendBtn',
		s : true,
		time : 60,
		sendTitle : '获取验证码',
		downTitle : '重新发送{countDown}s',
		timer : new Object,
		send : function(btn){
			var self = this;
			//var Email = $("input[name='Email']").val();
			var Phone = $("input[name='Phone']").val();
			
			if(!self.s) return false;
			if(Phone){
				
				var SmsEquipment = Phone;
				
				$.post('/api/web/sms_api',{SmsEquipment:SmsEquipment,type:btn.attr('data-type')},function(data){
					
					if(data.ret=='-1'){
						$.alert({str:('请在'+data.msg+'秒后再获取验证码'),time:1000});
						return false;
					}else{
						$.alert({str:data.msg,time:1000});
					}
					
					if(data.ret=='1'){
						self.s = false;
						self.countDown(btn);
					}else{
						self.s = true;
					}
					
				},'json');
				
			}else{
				$.alert({str:'请填写好信息，以便获取验证码',time:1000});
				return false;
			}
		},
		countDown : function(btn){
			var self = this,
			time = self.time;
			smsrun = true;
			self.timer = setInterval(function(){
				if(!smsrun){clearInterval(self.timer);return false;}
				btn.html(self.downTitle.replace('{countDown}',time));
				//console.log(time);
				if(time <= 0){
					self.s = true;
					btn.html(self.sendTitle);
					time = 60;
					smsrun = false;
				}
				time--;
			},1000);
		},
		init : function(){
			var self = this;
			$(self.b).click(function(){
				self.send($(this));
			});
		}
	}
	sendCode.init();
}
