//$(".search").hover(function(){
//	$(".searchbox").stop(true,true).fadeIn(300);
//},function(){
//	$(".searchbox").stop(true,true).fadeOut(300);	
//})

$(".admin").hover(function(){
	$(".land").stop(true,true).fadeIn(300);
},function(){
	$(".land").stop(true,true).fadeOut(300);	
})

dealingWithAnErrorPicture();
//处理地址错误图片
function dealingWithAnErrorPicture(_range){
	var _target = $('img');
	if(_range){
		_target = _range;
	}
	
	//检测是否是字段链接，字段链接不做处理
	var srcReg = /^{.+}$/g;

	for(var i=0;i<_target.length;i++){
		var type = _target[i].getAttribute('type');
		var imgSrc = _target[i].src;
		if(srcReg.test(imgSrc) == false){
			replaceDefaultImg(_target[i],type,imgSrc);
			
		}
	}	
}

//替换默认图片地址
function replaceDefaultImg(_target,type,imgSrc){
	
	//创建图片对象
	var ImgObj = new Image();
	//设置图片对象地址
    ImgObj.src = imgSrc;
    //出错处理
   	
    ImgObj.onerror = function(){
	    switch (type){
			case 'teacher':
				_target.src = '/sysimg/tavatar.jpg';
				break;
			case 'expert':
				_target.src = '/sysimg/eavatar.jpg';
				break;
			case 'user':
				_target.src = '/sysimg/avatar.jpg';
				break;
			case 'noicon':
				_target.src = '/sysimg/fileicon/chm.gif';
				break;
			case 'exam':
				_target.src = '/SysImg/exam/shijuan.jpg';
				break;
			case 'logo':
				_target.src = '/SysImg/nologo.gif';
				break;
			default:
				_target.src = '/sysimg/nopic_225_142.png';
				break;
		}
    }
	
	
}


function getImgLoadState(imgurl) {
    var imgObject = new Image();
    imgObject.src = imgurl;

    if ($(imgObject)[0].width > 0 && $(imgObject)[0].height > 0) {
        return true;
    } else {
        return false;
    }
}

//执行页面动画
$('.page-animate').each(function() {
    var ofTop = $(this).offset().top-$(window).height();
    var maxTop = $(this).offset().top+$(this).outerHeight();
	var type = $(this).attr('data-type');
	if(!type){
		type = 'fadeInUp';
	};
	var $that = $(this);
	if($(window).scrollTop()>ofTop&&$(window).scrollTop()<maxTop){
		var delay = $that.attr('data-delay');
		if(delay){
			$that.css({animationDelay:''+delay+'s'});
		};
		$that.removeClass('page-animate').addClass('animated '+type+'');
	};
	$(window).scroll(function(){
		if($(window).scrollTop()>ofTop&&$(window).scrollTop()<maxTop){
			$that.removeClass('page-animate').addClass('animated '+type+'');
		};
	});
});


function subNav(text){
	$('.sub-header').find('li').each(function() {
        if($(this).text()==text){
			$(this).addClass('active');
		};
    });
};



subContMinHeight();
$(window).resize(function(){
    subContMinHeight();
});
function subContMinHeight(){
    var minH = $(window).height()-$('.sub-header').outerHeight(true)-$('.sub-footer').outerHeight(true);
    $('#subContMinHeight').css({minHeight:minH+'px'});
};

//头部选中状态
var locationUrl = window.location.href
$('.headerbox .header_c li').each(function() {
	if($(this).find('a').attr('href') == locationUrl){
		$(this).addClass('curr').siblings('li').removeClass('curr')
		console.log($(this).find('a').attr('href'))
	}
});

function navActive(name){
	$('.header_c').find('li').each(function(){
		var content =  $(this).find('a').text();
		if(content ===name){
			$(this).addClass('curr').siblings().removeClass('curr')
		}
	})
}

/**
 * 搜索框focus
 */
$('#key-text').focus(function(){
	$('.scbox').addClass('focus')
})
$('#key-text').blur(function(){	
	$('.scbox').removeClass('focus')
})