/* tab切换 */
$.fn.changeTab = function(options) {
	var options = $.extend({
		activeClass: 'active',
		contentTab : '.content-tab'	
	}, options);

	var activeClass = options.activeClass;
	var $contentTab = $(options.contentTab);

	$(this).children('li').each(function(i) {
	   $(this).click(function() {
			$(this).addClass(activeClass).siblings().removeClass(activeClass);
			$contentTab.eq(i).show().siblings(options.contentTab).hide(); 
	   });
	});
}


/* 显示/隐藏客服窗口 */
var offsetLeftS = $('.online-service-s').width() + 10;
var offsetLeft = $('.online-service').width() + 10;
$('.online-service-s .text').click(function() {
	$('.online-service-s').animate({
		right: -offsetLeftS,
		opacity: 'toggle'
	}, 280, function() {
		$('.online-service').animate({
			right: 10,
			opacity: 'toggle'
		}, 280);
	});
});

$('.online-service .close').click(function() {
	$('.online-service').animate({
		right: -offsetLeft,
		opacity: 'toggle'
	}, 280, function() {
		$('.online-service-s').animate({
			right: 10,
			opacity: 'toggle'
		}, 280);
	});
});


/* 返回顶部 */
$('.to-top').click(function() {
	$('html, body').animate({scrollTop: 0}, 300);
});


/* 网站底部弹出微信图片 */
$('.friend-link .right ul li.item2').hover(function() {
	$(this).children().show();
}, function() {
	$(this).children().hide();
});



/* 产品服务-小贷没有链接-hover时改变文字 */
/*$('.list-product ul li.item3 a').hover(function() {
	$(this).text('敬请期待！');
}, function() {
	$(this).text('小额借贷管理系统');
});
*/

/* 跳转菜单 */

var setMenuPosition = function() {
    var sideBlank = ($(window).width() - 1190) / 2;
    if (sideBlank > 72) {
        var menuLeft = sideBlank - 72;
    } else {
        var menuLeft = 0;
    }
    $('head').append('<style>.goto-menu{left: ' + menuLeft + 'px;}</style>');
}
setMenuPosition();

$('.goto-menu a').click(function() {
	if ($(this).parent().hasClass('safe')) {
		var offsetTop = $('.anchor').eq($(this).index()).offset().top;
	} else {
		var offsetTop = $('.anchor').eq($(this).index()).offset().top - 60;
	}
	$('html, body').animate({scrollTop: offsetTop}, 300);
});


$('.goto-menu.disabled a').click(function() {
	return false;
});

if(location.search) {
	var i = parseInt(location.search.replace(/\?/, '')) - 1;
	setTimeout(function () {
		$('.goto-menu a').eq(i).trigger('click');
	}, 500);
}

$(window).scroll(function() {
	$('.anchor').each(function() {
		if((document.documentElement.scrollTop || document.body.scrollTop) >= $(this).offset().top - 60){
			var i = $('.anchor').index($(this));
			$('.goto-menu a').removeClass('current').eq(i).addClass('current');
		}
	});
});

$(window).resize(function() {
	$('.goto-menu').length ? setMenuPosition() : '';
});


/* 文章页图片限宽 */
$(function () {
	$('.news-detail img').each(function() {
		if ($(this).width() > $('.news-detail').width()) {
			$(this).removeAttr('style').attr({width: $('.news-detail').width()});
		}
	});
});