function popularOver(obj){
	var n = ww($("popularTop"),"li");
	var i = 0;
	while(n[i]){
		if(n[i]==obj){ 
			n[i].className = "selected";
		}else{ 
			n[i].className = "";
		}
		i++;
	}
}
var tabTime;
function popular(obj){
	if(tabTime) clearTimeout(tabTime);
	if(obj) tabTime = setTimeout(function(){popularOpen(obj)},300);
}
function popularOpen(obj){
	var n = ss("#popularTop li");
	var m = ss("#popular >ul");
	var i = 0;
	while(n[i]){
		if(n[i]==obj){ 
			n[i].className = "selected";
			m[i].style.display = "block";
		}else{
			n[i].className = "";
			m[i].style.display = "none";
		} 
		i++;
	}	
}
//photonews
var allows = 1;
var antes = 0;
var autoSlide = true;
function numOver(val){
	var n = ss("#article .pageNum div");
	var i=0;
	while(n[i]){
		if(i==antes)	n[i].className = "selected";
		else if(i==val)	n[i].className = "over";
		else	n[i].className = "";
		i++;
	}
}
function autoPhoto(val){
	if(allows){
		allows = 0;
		k=0;
		after = val;
		mm();
	}
}
function goNextPhoto(val){
	var a = antes+val;	
	if($("photo_"+a))	direction(a);
	else direction(0);
}
function direction(val){
	if(allows){
		if(autoSlide) clearTimeout(autoSlide);
		autoSlide = false;
		allows = 0;
		k=0;
		after = val;
		mm();
	}
}				
function mm(){
	setOpacity($("photo_"+antes),100-k);
	k += 15;
	var sss = setTimeout("mm();",50);
	if(k>=100){
		clearTimeout(sss);
		setOpacity($("photo_"+antes),0);
		k=0;
		$("photo_"+antes).style.display = "none";
		$("photo_"+after).style.display = "block";	
		antes = after;
		numOver(antes);
		if($("imgIdx")) $("imgIdx").innerHTML = after+1;
		sss = setTimeout("mm2()",200);
	}
}
function mm2(){
	setOpacity($("photo_"+after),k);
	k += 10;
	var sss = setTimeout("mm2();",50);
	if(k>=100){
		clearTimeout(sss);
		setOpacity($("photo_"+after),100);
		allows = 1;
		if(autoSlide){ 
			var n = ss("#article .pageNum div");
			if(n.length==(after+1)) var next = 0;
			else var next = after+1;
			setTimeout(function(){autoPhoto(next);},5000);
		}
	}					
}
function seeFull(){
	clearTimeout(autoSlide);
	autoSlide = false;
	var n = ww($("photo_"+antes),".targetCaption");
	var m = ww($("photo_"+antes),"cite");
	var o = ww($("photo_"+antes),"img");
	$("pimg").src = o[0].src.replace(/a-Image/,"a-FullSize");
	if(m[0]) $("pcredit").innerHTML = m[0].innerHTML;
	if(n[0]) $("pcaption").innerHTML = n[0].innerHTML;	
	$("pimg").onload = function(){
		$("pimg").style.visibility = "visible";
		if($("pimg").offsetWidth){ 
			if(m[0] && n[0])	$("pcredit").style.width = $("pcaption").style.width =  ($("pimg").offsetWidth-8)+"px";
			$("fullImage").style.width = $("pimg").offsetWidth+"px";
		}	
	}
	$("fullBox").style.display = "block";
}
function closeFull(){
	$("fullBox").style.display = "none";
}
//font size
if(getCookie('fSize')) var fSize = getCookie('fSize');
else var fSize = 9;
function fontSize(val){
	fSize = parseInt(parseInt(fSize)+val);
	if(fSize<7) fSize = 7;
	if(fSize>15) fSize = 15;
	$("article").style.fontSize = fSize+"pt";
	setCookie('fSize',fSize,30);
}

function Tfocus(){
	alert("Please login, first.");
	var n = ss("#inputComment .cTop input");
	n[0].focus();
}
function TextFocus(obj){
	if(trim(obj.value) == obj.defaultValue) obj.value = '';
}
function TextBlur(obj){
	if(trim(obj.value)=='') obj.value = obj.defaultValue;
}
function sorted(obj,val,val2){
	sorting = val;
	commentNum = 0;
	setCookie('commentSort',val,3);
	bringComment(1,val2);
	
	var m = ss("#sorting img");
	if(m[0]) m[0].style.visibility = "visible";
	var n = ss("#sorting a");
	var i = 0;
	while(n[i]){
		if(n[i]==obj) n[i].className = "selected";
		else n[i].className = "";
		i++;	
	}
}
var sorting;
var commentNum = 0;
function bringComment(val,val2){
	sorting = getCookie('commentSort');
	if(!sorting) sorting = 'newest';
	var n = ww($("nextComment"),"IMG");
	if(n[0]) n[0].style.display = "block";
	xmlHT=GetXmlHttpOBJ();
	var url = "/us/article/getCommentBox.php?aid="+aid+"&sid="+Math.random();
	url += "&sort="+sorting;
	url += "&num="+commentNum;
	url += "&many="+val;
	url += "&simple="+val2;
	xmlHT.onreadystatechange=function(){
		if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){
			var a = xmlHT.responseText.split("=*=#");
			if(a[0]==0)		$("nextComment").style.display = "none";
			else	$("nextComment").style.display = "block";
			if(commentNum)	$("commentList").innerHTML += a[1];
			else	$("commentList").innerHTML = a[1];
			if(n[0])	n[0].style.display = "none";
			var m = ss("#sorting img");
			if(m[0])	m[0].style.visibility = "hidden";
			$("rctop").innerHTML = a[2];
			$("sorting").innerHTML = a[3];
			commentNum++;
		}
	}; 
	xmlHT.open("GET",url,true);
	xmlHT.send(null);		
}
function viewLess(){
	commentNum = 0;
	var m = ss("#sorting img");
	if(m[0]) m[0].style.visibility = "visible";	
	bringComment(1,1);
}
function commentReply(obj,val,user){
	while(obj.nodeName != "LI" && obj.nodeName!="BODY"){
		obj = obj.parentNode;
	}
	var m = ww(replyObj,"label");
	m[0].innerHTML = "Replying to "+user;
	var o = ww(replyObj,"Form");
	o[0].parent.value = val;
	var n = ww(obj.parentNode,"LI");
	var i = 0;					
	while(n[i]){
		if(n[i]==obj){
			if(n[i+1]){ 
				if(n[i+1].className=="reply input") obj.parentNode.removeChild(n[i+1]);
				else	obj.parentNode.insertBefore(replyObj,n[i+1]);
			}else	obj.parentNode.appendChild(replyObj);
		}
		i++;
	}
}
function closeComment(obj){
	while(obj.nodeName != "LI" && obj.nodeName!="BODY"){
		obj = obj.parentNode;
	}
	obj.parentNode.removeChild(obj);					
}
function vote(obj,id,val){
	xmlHT=GetXmlHttpOBJ();
	var url = "/us/article/comment_vote.php?c_id="+id+"&vote="+val;
	var n = ww(obj,"span");
	xmlHT.onreadystatechange=function(){
		if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){
			if(xmlHT.responseText){
				if(isNaN(xmlHT.responseText)) alert(xmlHT.responseText);
				else n[0].innerHTML = xmlHT.responseText;
			}
		}
	}; 
	xmlHT.open("GET",url,true);
	xmlHT.send(null);																				
}
function delComment(id){
	location.href="/us/article/comment_delete.php?id="+id+"&url="+window.location.href;	
}
function showComment(obj,val){
	obj.style.display = "none";
	var n = ww(obj.parentNode,"."+val);
	if(n[0]) n[0].style.display = "block";
}
function flag(obj,id){
	xmlHT=GetXmlHttpOBJ();
	var url = "/us/article/comment_flag.php?c_id="+id;
	var n = ww(obj,"span");
	xmlHT.onreadystatechange=function(){
		if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){
			if(xmlHT.responseText){ 
				if(isNaN(xmlHT.responseText)) alert(xmlHT.responseText);
				else n[0].innerHTML = xmlHT.responseText;
			}
		}
	}; 
	xmlHT.open("GET",url,true);
	xmlHT.send(null);	
//	location.href = "/us/article/comment_flag.php?c_id="+id+"&url="+window.location.href;
}
function seeBlockedComment(obj){
	var n = ww(obj.parentNode.parentNode,".flagText");
	var m = ww(obj.parentNode.parentNode,".commentText");
	if(n[0]) n[0].style.display = "none";
	if(m[0]) m[0].style.display = "block";
}
function hideBlockedComment(obj){
	var n = ww(obj.parentNode.parentNode,".flagText");
	var m = ww(obj.parentNode.parentNode,".commentText");
	if(n[0]) n[0].style.display = "block";
	if(m[0]) m[0].style.display = "none";
}
function postComment(obj){
	var pos = findPos(obj);
	$("popupLogin").style.left = (pos[0]-150)+"px";
	$("popupLogin").style.top = (pos[1]+15)+"px";
	$("popupLogin").style.display = "block";
	$("loginForm").login.focus();
	$("loginForm").url.value = location.href+"#postComment";		
}
function viewAllComment(obj){
	var m = ss("#sorting img");
	if(m[0]) m[0].style.visibility = "visible";
	bringComment(0,1);
}
function addComment(slug){
   var  xmlHT=GetXmlHttpOBJ();
    var url = "/us/template/checkLogin.php";
	url += "?sid="+Math.random();
	xmlHT.onreadystatechange=function(){
        if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){
            if(xmlHT.responseText){
				location.href = '/us/article/goComment.php?aid='+aid+'&title='+slug;
            }else{
				var pos = findPos($("addC"));
				$("popupLogin").style.left = (pos[0]-350)+"px";
				$("popupLogin").style.top = (pos[1]+15)+"px";
				$("popupLogin").style.display = "block";
				$("loginForm").onsubmit = null;
				$("loginForm").url.value = '/us/article/goComment.php?aid='+aid+'&title='+slug;
			}    
        }
    }; 
    xmlHT.open("GET",url,true);
    xmlHT.send(null);
}	
//share article
var setT = null;
var setP = null;
var index = null;
function Zover(val){
	index = val;
	setT = window.setTimeout("Xover()",400);
	if(setP) clearTimeout(setP);
}
function Xout(){
	if(setT) clearTimeout(setT);
	setP = window.setTimeout("hide()",700);
}
function Xover(){
	var pos = findPos($("btnB"+index));	
	$("shBox").style.left = (pos[0]-17)+"px";
	$("shBox").style.top = (pos[1]+17)+"px";
	$("shBox").style.display = "block";
}
function hide(){
	$("shBox").style.display = "none";
}
function Tover(){
	if(setP) clearTimeout(setP);
}
function shareArticle(site){
	shareUrl = escape(location.href);
	var n = ss("#container h1");
	shareTitle = encodeURIComponent(n[0].innerHTML);
	var n = ss("#article p");
	shareDescription = encodeURIComponent(n[0].innerHTML);
	shareContent(site);
}
function shareContent(site){
	switch (site) {		
		case "digg":
			pop('http://digg.com/remote-submit?phase=2&url='+shareUrl+'&title='+shareTitle+'&bodytext='+shareDescription,'digg','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;		
		case "delicious":
			pop('http://del.icio.us/post?tags=test&v=4&noui&jump=close&url='+shareUrl+'&title='+shareTitle+'&notes='+shareDescription+'&tags=', 'delicious','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;		
		case "facebook":
			pop('http://www.facebook.com/sharer.php?u=' + shareUrl + '&t=' + shareTitle, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
			break;		
		case "stumbleit":
			pop('http://www.stumbleupon.com/submit?url=' + shareUrl + '&title=' + shareTitle, 'stumbleupon', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
			break;	
		case "myspace":
			pop('http://www.myspace.com/Modules/PostTo/Pages/?t='+shareTitle+'&c='+shareDescription+'&u='+shareUrl,'myspace','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "linkedin":
			pop('http://www.linkedin.com/shareArticle?mini=true&url='+shareUrl+'&title='+shareTitle+'&summary='+shareDescription+'&source=The Christianp Post','Linkedin','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "yahoobuz":
			pop('http://buzz.yahoo.com/buzz?targetUrl='+shareUrl,'yahoobuz','toolbar=yes,location=1,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "mixx":
			pop('http://mini.mixx.com/submit/story?page_url='+shareUrl+'&title='+shareTitle+'&description='+shareDescription,'mixx','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "newsvine":
			pop('http://www.newsvine.com/_tools/seed&save?u='+shareUrl+'&h='+shareTitle, 'newsvine', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
		case "twitter":
			pop('http://twitter.com/home?status='+shareTitle+' - '+shareUrl, 'twitter', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
		case "reddit":
			pop('http://reddit.com/submit?url='+shareUrl+'&title='+shareTitle, 'reddit', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;	
		case "blogger":
			pop('http://www.newsvine.com/_tools/seed&save?u='+shareUrl+'&h='+shareTitle, 'blogger', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
		case "wordpress":
			pop('http://twitter.com/home?status='+shareTitle+' - '+shareUrl, 'wordpress', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
		case "G-bookmarks":
			pop('http://www.google.com/bookmarks/mark?op=edit&bkmk='+shareUrl+'&title='+shareTitle, 'G Bookmarks', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;	
		case "live":
			pop('http://favorites.live.com?quickadd.aspx?mkt=en-us&url='+shareUrl+'&title='+shareTitle, 'Live', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
		case "technorati":
			pop('http://www.technorati.com/faves?add='+shareUrl, 'Technorati', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;							
	}
}
//left box size
function resizeBox(val,val2){
	$("articleThumbnail").style.width = val+"px";
	if(val2==0){
		var n = ss("#articleThumbnail .insetZoomTargetBox");
		if(n[0]) n[0].style.display = "none";
	} 
}
//comment collapse
function ecComment(){
	if($("commentBody").style.display=="none"){
		$("ecImg").src = "http://graphic.christianpost.com/images/article/collapse.gif";
		$("commentBody").style.display = "block";
	}else{
		$("ecImg").src = "http://graphic.christianpost.com/images/article/expand.gif";
		$("commentBody").style.display = "none";	
	}
}
//video
var videoObj;
var vx = 1;
var vfrequent = 50;
var vduration = 0.7;
var vfreq = vduration*1000/vfrequent;
var iframe_ok = 0;
function showVideo(obj){
	var n = ww(obj.parentNode,"IFRAME");
	n[0].src = "/us/article/video.php?id="+n[0].id.substr(1);
	n[0].style.display = "block";	
	var n = ww(obj.parentNode,"img");
	videoObj = n[0];
	n[1].style.display = "none";	
	var p = ww(obj.parentNode,".vTitle");	
	p[0].style.display = "none";
	videoObj.style.width = "256px";
	videoObj.style.height = "144px";
	videoObj.style.marginTop = 0;
	videoObj.style.top = 0;
	widthXX = 608-256;
	widthYY = 402-144;
	vTop = 40;
	vx = 1;
	division = 1;
	execute();
}
function videoSimgC(){
	var n = ww(videoObj.parentNode,"img");
	var m = ww(videoObj.parentNode,".close");
	var o = ww(videoObj.parentNode,"IFRAME");
	m[0].style.display = "block";	
	n[0].style.display = "none";	
	o[0].width = 608;
	o[0].height = 432;//387		
}
function closeVideo(obj){
	var n = ww(obj.parentNode,"img");
	n[0].style.display = "block";
	videoObj = n[0]; 
	var n = ww(obj.parentNode,".close");
	n[0].style.display = "none";
	var n = ww(obj.parentNode,"IFRAME");
	n[0].src = "";
	n[0].style.display = "none";
	var p = ww(obj.parentNode,".vTitle");	
	p[0].style.display = "block";	
	obj.parentNode.className = "relatedVideo";
	widthXX = -608+256;
	widthYY = -402+144;
	vTop = -30;	
	vx = 1;
	division = 0;
	execute();
}
function execute(){
	if(vx>=vfreq){ 
		clearTimeout(sss);
		if(division){
			videoObj.parentNode.className = "videoselected";
			videoObj.style.width = "608px";		
			//videoSimgC();
		}else{
			var n = ww(videoObj.parentNode,"img");
		//	var m = ww(videoObj.parentNode,".close");
			var o = ww(videoObj.parentNode,"IFRAME");			
			n[1].style.display = "block";
			videoObj.style.width = "256px";
			videoObj.style.height = "144px";
			o[0].style.display = "none";
			o[0].width = 1;
			o[0].height = 1;			
			videoObj.style.marginTop = 0;
		}	
		return false;
	}
	var ta = Math.sin(vx/vfreq*Math.PI)*Math.PI/vfreq;
	videoObj.style.width = (parseInt(videoObj.style.width) + widthXX/2*ta)+"px";
	videoObj.style.height = (parseInt(videoObj.style.height) + widthYY/2*ta)+"px";
	videoObj.style.marginTop = (parseInt(videoObj.style.marginTop) + vTop/2*ta)+"px";
	var sss = setTimeout("execute()",vfrequent);
	vx++;									
}
//setTimeout("location.reload();",1200000);
function addComment(slug,count){
	if(!count){
	   var  xmlHT=GetXmlHttpOBJ();
		var url = "/us/template/checkLogin.php";
		url += "?sid="+Math.random();
		xmlHT.onreadystatechange=function(){
			if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){
				if(xmlHT.responseText){
					location.href = '/us/article/goComment.php?aid='+aid+'&title='+slug;
				}else{
					var pos = findPos($("addC"));
					$("popupLogin").style.left = (pos[0]-350)+"px";
					$("popupLogin").style.top = (pos[1]+15)+"px";
					$("popupLogin").style.display = "block";
					$("loginForm").onsubmit = null;
					$("loginForm").url.value = '/us/article/goComment.php?aid='+aid+'&title='+slug;
				}    
			}
		}; 
		xmlHT.open("GET",url,true);
		xmlHT.send(null);
	}else location.href = '/us/article/goComment.php?aid='+aid+'&title='+slug;
}