(function(){
	var browse = navigator.userAgent,
		ischrome,
		isfirefox;

	browse = browse.toLowerCase();
	ischrome = browse.indexOf('chrome') >= 0 ? true : false;
	isfirefox = browse.indexOf('firefox') >= 0 ? true : false;
	console.log(browse, "ischrome", ischrome, "isfirefox", isfirefox);
	//菜单锚点动画
	$('.js_navItem').on('click', function (e) {
		e.preventDefault();
		var href = $(this).attr('href'),
			$el = $(href);
		$('html,body').animate({
            scrollTop: $el.offset().top
        }, 1000, function() {
        	//!$el.hasClass('active') && $el.addClass('active');
        });
	});
})();


(function (){
	//招聘弹层
	var COUNT = 1;
	$('.jsJobItem').click(function () {
		var $this = $(this),
			panel,
			page_id = $this.attr('data-pageid'),
			url = JC.f.addUrlParams(page_id, {'format': 'html'}); 
   		
   		$.get(url).done(function(res){
   			panel = JC.Dialog( JC.f.printf( JC.f.scriptContent( $('#jobtpl') ), COUNT, res ), 'dialog string panel' );
	   		panel.on('beforeshow', function(_evt, _panel){
	   			$('.mod-job-detail').addClass('bounceIn').removeClass('bounceOut');
	   		});
	   		panel.on('close', function(_evt, _panel){
				$('.mod-job-detail').removeClass('bounceIn').addClass('bounceOut');
	   		});
   		});
    	COUNT++;
	});
})();


(function(){
	//浏览器滚动滚动动画
	var a = $(window).height(),
		h = [];

	$(window).on('resize', function () {
		a = $(window).height();
	});

	$('.js_page').each(function () {
		var $this = $(this);
		h.push( $this.offset().top + Math.floor($this.height() / 2) );
	});

	$(window).on('scroll', function(){
		var s = $(window).scrollTop();
		$('.js_page').each(function (ix, item) {
			if (Math.floor(a / 2) + s >= h[ix]) {
				if (!$(item).hasClass('active')) {
					$(item).addClass('active');
				}
			}
		});
	});
})();

(function(){
	//分类导航
	var $articlelist = $('#js_modPage'),
		catId = '',
		paged = 1;

	var paginator = new Paginator({
		totalItems: $('.js_cntposts').val(),
        itemsPerPage: 8,
        parentNode: '.mod-article-page',
        firstLast: false,
        showTotal: false,
        prevNext: false,
        pageSpan: 10
	});	

	paginator.on('change:page', function(evt, newVal, oldVal){
        var $this = $(this),
        	url;

		paged = newVal + 1;
		url = JC.f.addUrlParams(location.href,{'format': 'html', 'paged':paged, 'cat': catId});
		$.get(url).done(function (res) {
			$articlelist.html(res);
			//分类背景色
			$('.js-cat-tag').each(function () {
				var $this =  $(this);
				$this.addClass($this.text());
			});

		});
    });

	//分类导航
	$('.mod-cate li').first().addClass('all').find('a').addClass('active');

	$(document).delegate('.mod-cate li>a', 'click', function (e) {
		e.preventDefault();
		paged = 1;

		var $this = $(this),
			totalItems,
			url;

		$('.mod-cate li>a').removeClass('active');
		$this.addClass('active');

		if ( $this.find('.cat-total').length ) {
			totalItems = parseInt($this.find('.cat-total').data('num').replace(/[^\d]+/g, '' ), 10);
		} else {
			totalItems = parseInt($('.js_cntposts').val(), 10); 
		} 
		
		catId = $(JC.f.getJqParent($this, 'li')).attr('class').replace(/[^\d]+/g, '' );
		url = JC.f.addUrlParams(location.href,{'format': 'html', 'paged':paged, 'cat': catId});

		$.get(url).done(function (res) { 
			$articlelist.html(res);
			//分类背景色
			$('.js-cat-tag').each(function () {
				var $this =  $(this);
				$this.addClass($this.text());
			});

		});
		paginator.set('totalItems', totalItems);
		paginator.set('page', 0);
        paginator.updateUI();
	});


	$('.js-cat-tag').each(function () {
		var $this =  $(this);
		$this.addClass($this.text());
	});
	
})();