// 轮播
(function(A) {
    A.fn.th_video_focus = function(E) {
        var G = {
            actClass: "cur",
            navContainerClass: ".focus_pic_preview",
            focusContainerClass: ".focus_pic",
            animTime: 600,
            delayTime: 5000
        };
        if (E) {
            A.extend(G, E)
        }
        var C = G.actClass,
            D = G.navContainerClass,
            B = G.focusContainerClass,
            F = G.animTime,
            H = G.delayTime,
            I = null;
        return this.each(function() {
            var O = A(this),
                M = A(D + " li", O),
                P = A(B + " li", O),
                L = M.length,
                K = O.height();

            function N(R) {
                var V = K * R * -1;
                var U = A(B + " li", O),
                    W = null,
                    T = null;
                for (var S = 0; S <= R; S++) {
                    W = U.eq(S);
                    T = W.find('script[type="text/templ"]');
                    if (T.length > 0) {
                        W.html(T.html())
                    }
                }
                A(B, O).stop().animate({
                    top: V
                }, F, function() {
                    var Y = O.find("h3"),
                        X = Y.height();
                    Y.height(0).html(A(B + " li").eq(R).find("img").attr("alt")).animate({
                        height: X
                    }, 600)
                });
                A(D + " li").eq(R).addClass(C).siblings().removeClass(C)
            }

            function Q() {
                if (I) {
                    clearInterval(I)
                }
                I = setInterval(function() {
                    var R = A(D + " li." + C).index();
                    N((R + 1) % L)
                }, H)
            }
            O.hover(function() {
                if (I) {
                    clearInterval(I)
                }
            }, function() {
                Q()
            });
            var J = null;
            M.hover(function() {
                var R = A(this).index();
                if (I) {
                    clearInterval(I)
                }
                J = setTimeout(function() {
                    N(R)
                }, 300)
            }, function() {
                if (J) {
                    clearTimeout(J)
                }
                Q()
            }).click(function(T) {
                var R = A(this).index(),
                    S = P.eq(R).find("a");
                if (document.uniqueID || window.opera) {
                    S[0].click();
                    T.stopPropagation();
                    T.preventDefault()
                }
            });
            Q()
        })
    }
    })(jQuery);
    $(function() {
    $(".film_focus").th_video_focus({
        navContainerClass: ".film_focus_nav",
        focusContainerClass: ".film_focus_imgs",
        delayTime: 3000
    });
});
$(function() {
    // 搜索选择
    $(".search_item_hd").click(function(){
        $("#search_switch_list").toggle(100);
    });
    $(".mi_soso").click(function(){
        $("#search_switch_list").toggle(100);
    });
    // /点击分类展开
    $("label").click(function(){
        $(".nav .side").toggle(100);
    });
    // 返回顶部
	$(window).scroll(function(){
		if($(window).scrollTop()>100){
			$("#side-bar .gotop").fadeIn();	
		}
		else{
			$("#side-bar .gotop").hide();
		}
	});
	$("#side-bar .gotop").click(function(){
		$('html,body').animate({'scrollTop':0},500);
	});
    // 管理信息
    $('.guanlixinxi').on('click', function(){
        var data_url = $(this).attr('data_url');
        var title = $(this).attr('title');
        layer.prompt({
        title: '管理信息 - 请输入密码',
        formType: 1
        },function(content, index) {
            $.ajax({
                url: data_url + "?content=" + content,
                type: "GET",
                dataType: "json",
                success: function(data) {
                    loading = layer.load(3);
                    if (data.code == 1) {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1000
                        },function() {
                            // 弹出iframe层管理
                            layer.open({
                                type: 2,
                                title: title,
                                shadeClose: true,
                                shade: 0.8,
                                area: ['1080px', '90%'],
                                content: data.url
                            }); 
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                }
            });
        });
    });
    //查看号码
    $('.get_haoma').on('click', function(){
        var data_url = $(this).attr('url');
        $.ajax({
            url: data_url,
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.confirm(data.haoma, {
                        title: '获取成功',
                        btn: ['取消']
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
    // 发布信息
    $('.k_add').on('click', function(){
        var data_url = $(this).attr('data_url');
        var title = $(this).attr('title');
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            shade: 0.8,
            area: ['1080px', '90%'],
            content: data_url
        }); 
    });
    // 举报
    $('.jubao').on('click', function(){
        var data_url = $(this).attr('data_url');
        var title = $(this).attr('title');
        layer.prompt({
        title: '举报',
        value: title, 
        formType: 2
        },function(content, index) {
            $.ajax({
                url: data_url + "?content=" + content,
                type: "GET",
                dataType: "json",
                success: function(data) {
                    loading = layer.load(3);
                    if (data.code == 1) {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1000
                        },function() {
                            layer.close(index)
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                }
            });
        });
    });
    // 通用表单提交
    $('#link_form').on('click', function(){
        var form = new FormData($("#itemForm")[0]);
        var url = $(this).attr('url');
        $.ajax({
            url: url,
            type: "post",
            data:form,
            dataType:'json', 
            processData:false,
            contentType:false,
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },function() {
                        location.reload();
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
    // 复制链接
    $(".share-btn").click(function(){
        var text = document.getElementById("text").innerText;
        var input = document.getElementById("input");
        input.value = text; 
        input.select(); 
        document.execCommand("copy"); 
        layer.alert('链接复制成功 快去分享给别人吧', {
            title: '分享',
            skin: 'layui-layer-rim',
            closeBtn: 0
        });
    });
    //添加折叠菜单
    $(".postsortitem").click(function(){
        $(".dsort").hide(100);
        $(".postsortitem").removeClass("on"); 
        $(this).addClass("on"); 
    	$(".on .dsort").show(100);
    });
    // 收藏
    $('.shoucang').on('click', function(){
        var url = $(this).attr('url');
        $.ajax({
            url: url,
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        $(".shoucang span").html("已收藏");
                    });
                } else if (data.code == 0) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        $(".shoucang span").html("收藏");
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });

    });
    // 弹出相片
    layer.photos({
        photos: '.xiangce'
        ,anim: 4
    }); 
    //弹出发送信息
    $(".k_f").click(function() {
        var data_url = $(this).attr('data_url');
        var title = $(this).attr('title');
        layer.prompt({
            title: title,
            formType: 2
        },
        function(text, index) {
            $.ajax({
                url: data_url+"?config=" + text,
                type: "GET",
                dataType: "json",
                success: function(data) {
                    loading = layer.load(3);
                    if (data.code == 1) {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1000
                        },
                        function() {
                            location.reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                }
            });
        });
    });
    $('.yemian').on('click', function(){
        var css = $(this).attr("css");
        var ws = $(this).attr("w");
        var hs = $(this).attr("h");
        var tblr = $(this).attr("tblr");
        var anim = $(this).attr("anim");
        var skin = $(this).attr("skin");
        var title = $(this).attr("title");
        if(!title){
            var title = false;
        }
        layer.open({
          type: 1,
          offset: tblr,
          skin: skin, 
          shade: 0.5,
          closeBtn: 0,
          title: title,
          shadeClose: true,  
          anim: anim,
          area: [''+ws+'', ''+hs+''], //宽高
          content: $('.'+css),
        });
     });
    $('.yemianf').on('click', function(){
        var url = $(this).attr("url");
        var ws = $(this).attr("w");
        var hs = $(this).attr("h");
        var tblr = $(this).attr("tblr");
        var anim = $(this).attr("anim");
        var skin = $(this).attr("skin");
        var title = $(this).attr("title");
        if(!title){
            var title = false;
        }
        layer.open({
          type: 2,
          offset: tblr,
          skin: skin, 
          shade: 0.5,
          title: title,
          closeBtn: 0,
          shadeClose: true,  
          anim: anim,
          area: [''+ws+'', ''+hs+''], //宽高
          content: url,
        });
     });
    // 触发链接
    $('.chufa').on('click', function(){
        var url = $(this).attr('url');
        $.ajax({
            url: url,
            type: "get",
            dataType: "json",
            success: function(data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },function() {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
});