//窗口水平居中
$(window).resize(function(){
    tc_center();
});

function tc_center(){
    var _top=($(window).height()-$(".layerbox").height())/2;
    var _left=($(window).width()-$(".layerbox").width())/2;

    $(".layerbox").css({top:_top,left:_left});
}

//全选反选
function checkall(form, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		e.checked = form.elements[checkall].checked;
	}
}

$(document).ready(function(){

	//瀑布流代码
	var $container = $('.picbox');
	$container.imagesLoaded(function(){
		$container.masonry({
			itemSelector: '.item',
			columnWidth: 0
		});
	});

    //导航菜单
	$(".nav-bar ul").slide({
	    type: "menu",
	    titCell: ".m",
	    targetCell: ".nav-menu",
	    effect: "show",
	    titOnClassName: "current",
	    delayTime: 100,
	    triggerTime: 100,
	    returnDefault: true
	});

    $(function(){
        $('.search-tab ul li').on('click',function () {
            $('.search-tab ul li').removeClass('selected');
            $(this).addClass('selected');
        });
    });

	//弹出框调用部分
	$(function(){
		//登录框
		$('.login-layer').click(function() {
			$('.loginmask').show();
			$('#loginbox').fadeIn();
			tc_center();
		});
		$('.switch-close').click(function() {
			$('#loginbox').hide();
			$('.loginmask').hide();
		});
		$('.loginmask').click(function() {
			$('#loginbox').hide();
			$('.loginmask').hide();
		});

	});

});

$(function() {
    $('#search').on('click', function() {
        var kw = $('#kw').val();
        if(kw) {
            window.location.href="search.php?kw="+kw;
        }else{
		   document.getElementById("kw").setAttribute("placeholder","请输入你要查找的关键字");
           return false;	
		}
    });
});