/**
 * @author mike
 */
$(document).ready(function(){
	
	
//模拟下拉菜单js  Start	
	var s_btn=0;
	$(document).click(function(){
		if(s_btn==1){
			$(".simulateSelectWrap").removeClass("sel");
			s_btn=0;
		}else{
			return;
		}
	})
	//页面加载时判断通知模式
	var settingRow=$("#quickSetting .row")
	var tzMode=settingRow.eq(0).find("input:hidden").val();
	if(tzMode==1){
		settingRow.eq(1).find(".simulateSelectBtn").removeClass("dis");
		var txt=settingRow.eq(1).find(".simulateSelectList").next(":hidden").val();
		settingRow.eq(1).find(".simulateSelectInner").find("div").html(txt+"分钟");
	}else{
		settingRow.eq(1).find(".simulateSelectBtn").addClass("dis");
		settingRow.eq(1).find(".simulateSelectInner").find("div").html("即时发送");
	}
	//通知设置js 下拉菜单展开
	$(".simulateSelectBtn").click(function(){//激活状态的下拉菜单点击时
		if($(this).hasClass("dis")){//当某个按钮被锁定时加上dis样式，即不可选
			return false;
		}
		if ($(this).parent().hasClass("sel")) {//如果当前的父元素有sel样式
			$(this).parent().removeClass("sel");
			s_btn = 0;
			return false;
		}
		else {
			$(this).parent().toggleClass("sel");
			//$(this).parents("#quickSetting").find(".simulateSelectWrap").removeClass("sel");
			$(".simulateSelectWrap").removeClass("sel");
			$(this).parent().addClass("sel");
			s_btn = 1;
			return false;
		}
	})
	
	//设置下拉选择
	$(".simulateSelectList li a").bind("click",function(){//这里的bind不能改live，会导致赋值出错
		var txt=$(this).html();
		var att=$(this).attr("rel");
		$(this).parent().parent().parent().siblings(".simulateSelectInner").find("div").eq(0).html(txt);
		$(this).closest(".simulateSelectWrap").find(":hidden").eq(0).val(att);
		$(this).closest(".simulateSelectWrap").removeClass("sel");
		return false;
	})
	
	//单选
	$("#quickSetting .simulateRadioWrap").click(function(){
		$(this).addClass("checked").siblings().removeClass("checked");
		var att=$(this).attr("rel");
		$(this).siblings(":hidden").eq(0).val(att);
		
		var i=$("#quickSetting .simulateRadioWrap").index(this);
		if(i==0){
			$(this).parent().next().find(".simulateSelectBtn").addClass("dis");	
			$(this).parent().next().find(".simulateSelectInner").find("div").html("即时发送");
		}else{
			$(this).parent().next().find(".simulateSelectBtn").removeClass("dis");
			var txt=$(this).parent().next().find(".simulateSelectList").next(":hidden").val();
			$(this).parent().next().find(".simulateSelectInner").find("div").html(txt+"分钟");
		}
	})
//模拟下拉菜单js  End		

	
	
	//保存设置
	$(".btn_edit_save").click(function(){
		var ele=$(this);
		var param=$("#quickSetting :input").serialize();
		param+="&showmode=2";
		//$(this).closest(".my_setting_bd").html("传递的参数:"+param);
		/*
$.getJSON("api/web/NotifyOption.ashx?"+param,function(data){
			ele.parent().siblings(".pop").show();
			$(".pop_cont").html(data+"<button>确定</button>")	
			$(".pop_cont button").click(function(){
			$(this).closest(".pop").hide();
		})
		}
)*/
		$.ajax({
			type:"GET",
			url:"../api/web/NotifyOption.ashx",
			data:param,
			dataType:"json",
			beforeSend:function(){
				ele.parent().siblings(".warn").show().find(".warn_cont").html("<img src='../../../../s/i/loading.gif'>处理中...");
			},
			success:function(msg){
			   ele.parent().siblings(".warn").show();
			   var ReturnCode=msg.StatusInfo.ReturnCode;
			   $(".warn_cont").html(ReturnCode+"<button>确定</button>")	
			   $(".warn_cont button").click(function(){
			   $(this).closest(".warn").hide();
			     })
			   } ,
			 error:function(){
			 	//alert("出错了");
				ele.parent().siblings(".warn").show();
				$(".warn_cont").html("连接服务器失败!<button>确定</button>")	
				$(".warn_cont button").click(function(){
			   $(this).closest(".warn").hide();
			     })
			 }  
		})
		
		
		return false;
	})
	
/*
	//静态弹出窗
	$(".pop:not(.skip) .btn_pop_ok").click(function(){
		//$(this).closest(".pop").hide();
		$(this).parent().hide();
		$(".pop").find(".pop_loading").show();
	})
	$(".skip .btn_pop_ok").click(function(){
		$(this).closest(".pop").hide();
	})
	$(".btn_pop_close").click(function(){
		//$(this).closest(".pop").hide();
		$(this).closest(".pop").hide();
	})
	$(".pop_close").click(function(){
		//alert("关闭");
		$(this).closest(".pop").hide();
	})
	$(".btn_pop_cancel").click(function(){
		//alert("关闭");
		$(this).closest(".pop").hide();
	})
*/

   //主要为了解决IE6的:hover问题
   
   $(".post(:not(.weather)) .post_item").mouseover(function(){
   	$(this).addClass("hover");
   }).mouseout(function(){
   	$(this).removeClass("hover");
   })
   
   //返回顶部
    $('#backTop').click(function(){
                    $('html,body').animate({
                        scrollTop: '0px'
                    }, 800, function(){
                        if ($(document).scrollTop() <= 0) {
                            $("#backTop").hide();
                        }
                    });
                });
                $(window).scroll(function(){
					
                    if ($(document).scrollTop() <= 0) {
						
                        $("#backTop").hide();
                    }
                    else {
                        $("#backTop").show();
                    }
                })

$(".WapSiteDemo").click(function(){
if(typeof ZhuiCont=="undefined"){//如果没有加载zhui.js 返回
return false;
}
    var hash=Math.random();
	var cont='<div class="mobileWebSite"><div class="mobileWebSiteInner"><iframe id="wapWebIframe" src="" width="240" height="320" frameborder="0" scrolling="auto"></iframe><div style="text-align:center;background-color:#fff;width:100%; padding-top:60px;" id="wapWebFrameLoading"><img src="/s/i/icon_loading_big.gif" alt=""/><br />正在打开,请稍后……</div></div></div>';
	ZhuiCont("手机版追信",cont,324,"auto",false);
	$("#wapWebIframe").attr("src","http://m2.zhui.cn/?random="+hash);
	$(".pop_wrap").css({"padding-bottom":"10px"})
	$("#wapWebIframe").hide();
	$("#wapWebIframe").load(function(){
		$(this).show();
		$("#wapWebFrameLoading").hide();
			
		})
})


							

})

function resizeImg(ele, w, h){//动态调整图片
				var maxWidth = w; // 图片最大宽度
				var maxHeight = h; // 图片最大高度
				var ratio = 0; // 缩放比例
				$(ele).each(function(){
					
					var width = $(this).width(); // 图片实际宽度
					var height = $(this).height(); // 图片实际高度
					// alert(width);
					//alert(width+","+height)
					//return false;
					if (width < 50 || height < 50) {//opera下默认1
						//setTimeout("resizeImg()", 10);
						//return false;
						
					}
					// 检查图片是否超宽
					if (width > maxWidth) {
						ratio = maxWidth / width; // 计算缩放比例
						width = maxWidth;
						height = height * ratio;
						$(this).width(width); // 设定实际显示宽度
						$(this).height(height); // 设定等比例缩放后的高度  
					}
					
					$(this).css({
						"position": "absolute",
						"left": "50%",
						"top": "50%",
						"margin-left": "-" + width / 2 + "px",
						"margin-top": "-" + height / 2 + "px"
					})
					
				})
			}
			

function AjaxRequest(method,url,data,type,before,success,error){
		$.ajax({
			type:method,
			url:url,
			data:data,
			dataType:type,
			beforeSend:before,
			success:success,
			error:error
		})
	}			

