// 这里是快报列表块的相关JS脚本
//检测时间
function checkTime(){
			$(".checkPostTime").each(function(index, element) {
            var sDT= new Date($(this).attr("time").replace(".0","").replace(/\-/gi,"/"));
			var eDT = new Date();
			if(sDT.dateDiff("s",eDT)>60){
				if(sDT.dateDiff("n",eDT)>60){
					if(sDT.dateDiff("h",eDT)>24){
						$(this).html(sDT.toLocaleString())
					}else{
						$(this).html(sDT.dateDiff("h",eDT)+"小时前")
					}
				}else{
					$(this).html(sDT.dateDiff("n",eDT)+"分钟前")
				}
			}else{
				var time = sDT.dateDiff("s",eDT)
				$(this).html((time>0?time:0)+"秒前")
			}
        });
	}
//删除
function addDeleteKuaibaoBtnListener(event){
		var owner = $(this)
		$.post(appPath+"art-del.action",{
			archiveClz:"Kuaibao",
			artid:owner.attr("vid")
		},function(d){
			if(d.success==true){
				$("#Publishers_"+owner.attr("vid")).slideUp('slow');
			}else{
				alert(d.msg)
			}
		})
	}
//初始化块运行
/*
owner.colorbox({overlayClose:false,escKey:false,
	iframe:true,fixed:true, innerWidth:600, innerHeight:colorboxHeight,onComplete:function(){
		if($.browser.msie && $.browser.version == "6.0"){
			//弹窗的高度,hack IE6 fix bug
			document.getElementById("colorbox").style.setExpression('top', 'eval(document.documentElement.scrollTop+70)');
		}
	}
});
*/
function loadKuaiBaoBlock(documentready){
	$(".deleteKuaibaoBtn").unbind("click").bind("click",addDeleteKuaibaoBtnListener);
	//来自 replay.js 
	$(".kuaibaoBox_replayBtn").unbind("click").bind("click",kuaibaoBox_replayBtnClickHandle)
	//
	$(".Publishers").unbind("mouseenter").bind("mouseenter",showDelte).unbind("mouseleave").bind("mouseleave",hideDelte)
	$(".zhuanfaBtn").colorbox({overlayClose:false,escKey:false,
		iframe:true, innerWidth:500, innerHeight:300
	});
	$(".kuaiBaoBlockEditBtn").each(function(index, element) {
		var owner = $(this)
		var colorboxHeight = owner.attr('innerHeight')?owner.attr('innerHeight'):400
		owner.colorbox({overlayClose:false,escKey:false,
			iframe:true, innerWidth:600, innerHeight:colorboxHeight
		});
	});
	
	checkTime()
	//缩略图点击放大
	$(".showBigImg img").unbind("click").bind("click",showBigImg).unbind("mouseenter").bind("mouseenter",showBigImgShowcuurrse).each(function(index, element) {
        showBigImg($(this))
    });
}
function showDelte(e){
	var deleteKuaibaoBtnSpan = $(this).find(".deleteKuaibaoBtnSpan");
	if(currentUserID == deleteKuaibaoBtnSpan.attr("uid") || currentUserID=='4'){
		deleteKuaibaoBtnSpan.css("visibility","visible")
	}
}
function hideDelte(e){
	$(this).find(".deleteKuaibaoBtnSpan").css("visibility","hidden")
}
function showBigImgShowcuurrse(event){
		
}
function showBigImg(_owner){
	var owner = _owner.currentTarget?$(this):_owner;
	var bigURL = owner.attr("url")
	var p = /\+(\d+)\-(\d+)\+/
	if(!owner.attr("src") || (_owner.currentTarget && owner.attr("src") == bigURL)){
		//取图或将大图转小图.
		var thumb = owner.attr("thumb")
		owner.attr("src",thumb);
		var m = thumb.match(p)
		owner.width(m[1])
		owner.height(m[2])
	}else if(_owner.currentTarget){
		//将小图转大图	
		owner.attr("src",bigURL);
		var m = bigURL.match(p)
		var r = m[1] / m[2]
		var w = owner.attr("maxWidth")?owner.attr("maxWidth"):450;
		if(m[1] > w){
			owner.width(w)
			owner.height(w/r)
		}else{
			owner.width(m[1])
			owner.height(m[2])
		}
	}
}
	
$(document).ready(function(e) {
	checkTime()
	$(document).everyTime(30000, checkTime);
    loadKuaiBaoBlock(true)
});

