//弹出层
function dialoghide(dialoghide){
	$("#fullbg").hide(); 
	$(".border_dialog").fadeOut(200); 
}

function show(show){
	var bh = $(window).height(); 
	var bw = $(window).width(); 
	$("#fullbg").css({ 
		height:bh, 
		width:bw, 
		display:"block" 
	}); 
	var name=show;
	var width=$("." + name).width();  
	var height=$("." + name).height();  
	var t=height/2;
	var l=width/2;
	$("." + name).css({ 
		width:width, 
		"margin-top":-t,
		"margin-left":-l
	});
	if(typeof document.body.style.maxHeight === "undefined") {
		var liu=document.documentElement.clientHeight/2;
		var h=height/2;
		var mar_t=liu-h;
	$("." + name).css({ 
		"margin-top":mar_t
	}); 
	}
	$("." + name).fadeIn(500);
}

$(function(){
//关注回复页面
//回复内容切换
$('.hf_list li').on('click',function(){
	$(this).addClass('on').siblings().removeClass('on');
	var index=$(this).index();
	$('.hf_list_cont').eq(index).show().siblings('.hf_list_cont').hide();
});

//素材管理（图文消息） 切换 删除
$('.tuwen_del').on('click',function(){
	$(this).closest('li').remove();
});

//素材管理页面 
//鼠标滑过显示编辑删除
var timer;
$('.tianjiatw').on('mouseover','.sucai',function(event) {
	var mask = $(this).find('.sc1_mask');
	clearTimeout(timer);
	timer = setTimeout(function() {
		mask.animate({
			'right': '0px'
		});
	}, 400);
}).on('mouseleave','.sucai',function(event) {
	var mask = $(this).find('.sc1_mask');
	clearTimeout(timer);
	timer = setTimeout(function() {
		mask.animate({
			'right': '-305px'
		});
	}, 0);
});
$('.tianjiatw').on('mouseover','.sucai1',function(event) {
	var mask = $(this).find('.sc1_mask');
	clearTimeout(timer);
	timer = setTimeout(function() {
		mask.animate({
			'right': '0px'
		});
	}, 400);
}).on('mouseleave','.sucai1',function(event) {
	var mask = $(this).find('.sc1_mask');
	clearTimeout(timer);
	timer = setTimeout(function() {
		mask.animate({
			'right': '-200px'
		});
	}, 0);
});

/* 添加图文及对应表单 */
var  newid=1;
$(".sc_add").on('click', function(){
    $('.sc_form').hide();
	var newid_index = $('.sucai1').last().index();
    if(newid_index<=7){
    	var add_target='<div class="sucai1 editor clearfix">'+
				'<div class="fl sc1_tit">标题</div>'+
				'<div class="fr sc1_thumb"><img src="../images/img1.jpg"></div>'+
				'<div class="sc1_mask">'+
					'<i class="iconfont sc_edit" data-id="cloneId'+newid+'">&#xe61c;</i>'+
					'<i class="iconfont sc_delete" data-id="cloneId'+newid+'">&#xe61b;</i>'+ 
				'</div>'+
			'</div>';
			$(".tianjiatw").append(add_target);
		}else{
			alert('最多添加9条信息');
	}
	//克隆右边表单
	var clone_form = '<div class="sc_form" id="cloneId'+newid+'">'+
			'<form action="http://localhost/1.php" target="cloneId'+newid+'" class="clone_class">'+
			'<input type="text" value="cloneId'+newid+'" name="wenzhangId">'+
			'<div class="mb10 clearfix">'+
				'<span class="sc_bti">标题：</span>'+
				'<input type="text" class="sc_inp scgl_title">'+
			'</div>'+
			'<div class="mb10 clearfix">'+
				'<span class="sc_bti">作者：</span>'+
				'<input type="text" class="sc_inp scgl_author">'+
			'</div>'+
			'<div class="mb10 clearfix">'+
				'<span class="sc_bti">简介：</span>'+
				'<textarea rows="5" class="sc_inp scgl_description"></textarea>'+
				'<p class="f12 t_r">还可以输入120字</p>'+
			'</div>'+
			'<div class="mb10 clearfix">'+
				'<span class="sc_bti">封面图片：</span>'+
				'<div class="fl">'+
					'<input type="text" class="sc_inp">'+
					'<div class="sc_upload">'+
						'<label for="file" class="white_btn mt10">上 传</label>'+
						'<input type="file" id="file" class="displayNone">'+
					'</div>'+
					'<div class="uploadImg clearfix displayNone">'+
						'<img src="../images/img3.jpg" alt=""> <a href="javascript:;" class="uploadImg_del">删除</a>'+
					'</div>'+
				'</div>'+
			'</div>'+
			'<div class="mb10 clearfix">'+
				'<span class="sc_bti">正面内容：</span>'+
				'<div class="fl sc_ueditor">'+
				    '<script id="container'+newid+'" name="content" type="text/plain"></script>'+
				    '<script type="text/javascript">var ue = UE.getEditor("container'+newid+'");</script>'+
				'</div>'+
			'</div>'+
			'<div class="clearfix">'+
				'<span class="sc_bti">原文链接：</span>'+
				'<input type="text" class="sc_inp">'+
			'</div>'+
		'</form>'+
		'<iframe name="cloneId'+newid+'" src="" class="displayNone"></iframe>'+
		'</div>';
	$('.sc_bianji').append(clone_form);
	newid++;
});

//遍历 form 表单提交
$(".form_save").on('click',function(){
  	  $(".clone_class").each(function(){
		$(this).submit();
	  });
});

//上传图片删除
$('.uploadImg_del').on('click',function(){
	$(this).parent('.uploadImg').remove();
});
	
/* 删除图文及对应表单 */
$(".tianjiatw").on('click','.sc_delete', function(){
    var editor_del_id = $(this).attr('data-id');
	$(this).closest('.sucai1').remove();
	$('#'+editor_del_id).remove();
	$('.sc_form').last().show();
});

/* 编辑图文及对应表单 */	
$(".tianjiatw").on('click','.sc_edit', function(){
    var editor_del_id = $(this).attr('data-id');
	$('#'+editor_del_id).show().siblings().hide();
});
	
//微官网 相册名称
//删除上传图片
$('.pic_delete').on('click',function(){
	$(this).parent('li').remove();
});

//批量编辑
$('.piliangguanli').on('click',function(){
	$(this).parents('.xiangcemcheng').hide();
	$('.xiangcemcheng1').show();
});

$('.fanhui_xiangcemcheng').on('click',function(){
	$(this).parents('.xiangcemcheng1').hide();
	$('.xiangcemcheng').show();
});

$('.loupanxiangce1 li').on('click',function(){
	$(this).find('.xiangce_edit_icon').toggleClass('on');
});

//首页配置选择模版
$('.picList .pic,.picList_radio').on('click',function(){
    var radio = $('.picList .picList_radio');
    var index = $(this).parents('li').index();
    $('.picList_radio').prop('checked',false);
    $(this).parents('li').find(radio).prop('checked',true);
    $('.picList_cont').eq(index).show().siblings('.picList_cont').hide();
})
$('.picList .pic,.picList_radio').eq(0).click();
//添加幻灯片
$('.huandengpian_set').on('click','.wgw_set_add',function(){
    var addLength = $(this).parents('.huandengpian_set').find('li').length+1;
    var caidanAdd = '<li class="clearfix">'+
                '<div class="fl caidanming">'+
                    '<h3>幻灯片<span class="test_num">'+addLength+'</span><span class="f12 col_7f pl10">图片建议尺寸：640*200</span></h3>'+
                    '<div class="mt10 ml20 clearfix">'+
                        '<span class="fl mt5">图片：</span><input type="text" class="wgw_inp fl">'+
                        '<a href="javascript:;" class="white_btn fl"><input type="file" class="type_file">上传</a>'+
                    '</div>'+
                    '<div class="mt10 ml20 clearfix">'+
                        '<span class="fl mt5">链接：</span><input type="text" class="wgw_inp fl">'+
                    '</div>'+
                '</div>'+
                '<div class="fl"><p class="chengAdd wgw_set_add">添 加</p><div class="mt15"><p class="chengAdd wgw_set_delete">删 除</p></div></div>'+
            '</li>';
    
    if(addLength<=4){
        $(this).parents('.huandengpian_set').append(caidanAdd);
    }else{
        alert('最多只添加4个幻灯片');
    }
    $('.huandengpian_set').on('click','.wgw_set_delete',function(){
        $(this).parents('li').remove();
        $('.test_num').each(function(i){
            var index = $(this).parents('li').index()+1;
            $(this).text(index);
        });
    });
});
//添加文章列表
$('.wzhliebiao_set').on('click','.wgw_set_add',function(){
    var addLength = $(this).parents('.wzhliebiao_set').find('li').length+1;
    var caidanAdd = '<li class="clearfix">'+
                    '<div class="fl caidanming">'+
                        '<h3>文章列表<span class="test_num">'+addLength+'</span></h3>'+
                        '<div class="mt10 ml20 clearfix">'+
                            '<span class="w80 mt5">标题文字：</span><input type="text" class="wgw_inp fl"> <em>0/12</em>'+
                        '</div>'+
                        '<div class="mt10 ml20 clearfix">'+
                            '<span class="ym_miaoshu w80 mt5">简介：</span><input type="text" class="wgw_inp inp_ym_desc fl" style="width:530px;"> <em>0/120</em>'+
                        '</div>'+
                        '<div class="mt10 ml20 clearfix">'+
                            '<span class="w80 mt5">封面图片：</span><input type="text" class="wgw_inp fl">'+
                            '<a href="javascript:;" class="white_btn fl"><input type="file" class="type_file">上传</a>'+
                        '</div>'+
                        '<div class="ml100 mt5 f12 col_7f">建议图片大小：640*1136</div>'+
                        '<div class="mt10 ml20 clearfix">'+
                            '<span class="w80 mt5">文章链接：</span><input type="text" class="wgw_inp fl">'+
                            '<a href="javascript:;" class="white_btn fl"><input type="file" class="type_file" style="width:100px; font-size:28px;">请选择页面</a>'+
                        '</div>'+
                        '<div class="ml100 mt5 f12 col_7f">填写点击按钮时所跳转的连接，或从功能中心中选择一个页面或活动</div>'+
                    '</div>'+
                    '<div class="fl"><p class="chengAdd wgw_set_add">添 加</p><div class="mt15"><p class="chengAdd wgw_set_delete">删 除</p></div></div>'+
                '</li>';   
    if(addLength<=9){
        $(this).parents('.wzhliebiao_set').append(caidanAdd);
    }else{
        alert('最多只添加9个幻灯片');
    }
    $('.wzhliebiao_set').on('click','.wgw_set_delete',function(){
        $(this).parents('li').remove();
        $('.test_num').each(function(i){
            var index = $(this).parents('li').index()+1;
            $(this).text(index);
        });
    });
});


})