
//主导航
function navFn(nav, navli, downmenu){
	var nav = document.querySelector(nav);
	var navList = document.querySelectorAll(navli);
	var downMenu = document.querySelectorAll(downmenu);
	
	var navWidth = nav.clientWidth;
	var liWidth = navWidth / navList.length;
	
	for(var i=0; i<navList.length;i++){
		navList[i].style.width = liWidth + "px";
		
		navList[i].onmouseover = function(){
			for(var j=0; j<downMenu.length;j++){
				navList[j].className = '';
				downMenu[j].style.display = "none"
			}
			
			this.className = "active";
			if(this.children.length > 1){
				this.children[1].style.display = "block";
				
				var marginRight = navWidth - (i * liWidth);
				var downMenuWidth =  this.children[1].clientWidth;
				if(marginRight <= downMenuWidth){
					this.children[1].style.cssText = 'right:0px; display:block ';
				}
			}
		}
		
		navList[i].onmouseleave = function(){
			for(var k=0; k<downMenu.length; k++){
				navList[k].className = '';
				downMenu[k].style.display = "none"
			}
			this.className = ""
		}
	}
	
}

//选项卡1
function tabFn(tab, tabcont, one, two){
		
	$(tab).hover(function(){
		var _index = $(this).index();
		$(this).addClass(one).siblings().removeClass(one);
		$(tabcont).eq(_index).addClass(two).siblings().removeClass(two);

	});
	
}
/*//选项卡2
function tabFn(tab, tabcont, classOne, classTwo){
	var tabList = document.querySelectorAll(tab);
	var tabcontList = document.querySelectorAll(tabcont);

	tabList.forEach(function(item, index){
		item.onmouseover = function(){
			tabcontList.forEach(function(v, i){
				v.className = "";
				tabList[i].className = "";
			})
			
			this.className = classOne;
			tabcontList[index].className = classTwo;
		}
	})	
}
*/

//友情链接
function linkFn(ele,e){
	var downMenu = $(ele).find("ul"); 
	downMenu.hide();

	$(e).click(function(){ 
		if(downMenu.is(':visible')){
			$(this).siblings("ul").slideUp(100);
		}else{
			$(this).siblings("ul").slideDown(100);
		}
	});
	
	$(ele).mouseleave(function(){
		downMenu.hide();
	})
}

//list左边导航
function eleMen(ele){
	$(ele).each(function () {
		if ($(this)[0].href == String(window.location)) {
			$(this).addClass("active").siblings().removeClass("active");
		}
	});
}

//form表单
function formFn(ele, type){
	if(type == 'text'){
		var inpValue = ele.value;
		
		ele.onfocus = function(){
			if(this.value == inpValue){
				this.value = ''
			}
		}
		
		ele.onblur = function(){
			if(this.value == ''){
				this.value = inpValue
			}
		}
		
	}else if(type == 'password'){
		ele.type = 'text';
		var passValue = ele.value;
		
		ele.onfocus = function(){
			if(this.value == passValue ){
				this.value = '';
				this.type ='password';
			}
		}
		
		ele.onblur = function(){
			if(this.value == '' ){
				this.value = passValue;
				this.type ='text';
			}else{
				this.type ='password';	
			}
		}
		
	}
	
}


$(function(){
	$(window).resize(function(){
		fnNews();
		/*clearTimeout(resizeTimeout)
		resizeTimeout = setTimeout(function(){
			fnNews();
		},100)
		*/
	})

	fnNews();
	function fnNews(){
		var winW = $(window).width();
		var top = 200;
		
		$(document).scroll(function(){
			var scrollTop = $(this).scrollTop();
			if(scrollTop >= top){
				$('.top').addClass('active');
			}else{
				$('.top').removeClass('active');
			}
			
		})

	}

})

