window.onload = function(){/*
	var n = ww(document.body,".enlarge");
	for(var i=0;i<n.length;i++){
		n[i].onclick = enlarge;
	}*/
	var n = ww(document.body,".enl");
	for(var i=0;i<n.length;i++){
		n[i].onclick = large;
	}
	var result = ww(document.body,'.previewBlog');
	var i=0;
	while(result[i]){
		result[i].onmouseover = function(){previewOver(this);};
		result[i].onmouseout  = function(){previewOut();};
		i++;
	}
	var result = ww(document.body,'.preview');
	var i=0;
	while(result[i]){
		result[i].onmouseover = function(){previewOver(this);};
		result[i].onmouseout  = function(){previewOut();};
		i++;
	}
}
var duration = 0.8;
var container;
var frequent = 40;
var amountY;
var x=1;
var freq = duration*1000/50;
var widthX;
var widthY;
var widthXX;
var widthYY;
var thisImg;
var oriImg;
var dicisive = 1;
var obj;
var closebtn;
var object;
var moving = true;
function large(e){
	if(moving){
		moving = false;
		/*
		if(obj){ 
			obj.onclick = enlarge;
		}*/
		if (!e) var e = window.event;
		if (e.target) object = e.target;
		else if (e.srcElement) object = e.srcElement;
		object.onclick = null;

		var n = ww(object.parentNode,"IMG");
		obj = n[0];
		core(obj);
	}	
}
/* 
function enlarge(e){
	if(moving){
		moving = false;
		if(obj){ 
			obj.onclick = enlarge;
			//closebtn.style.display = "none";
		}
		if (!e) var e = window.event;
		if (e.target) obj = e.target;
		else if (e.srcElement) obj = e.srcElement;
		if (obj.nodeType == 3) obj = obj.parentNode;
		core(obj);
	}
}*/
function core(obj){
		oriImg = obj;
		ori_width = oriImg.offsetWidth;
		ori_height = oriImg.offsetHeight;
		//var src = obj.src.replace(/Normal/,'FullSize');
		var src = obj.src.replace(/christianpost.com\/blogs\/data\/images/,'christianpost.com/blogs/data/image');
		obj.onclick = null;
		var n = ww(obj.parentNode.parentNode,".enl");
		object = n[0];
		object.onclick = null;
		if(container) container.style.display = "none";
		/*container = document.createElement("div");
		container.id = "conto";
		document.body.appendChild(container);
		var inner = document.createElement("div");
		container.appendChild(inner);

		thisImg = new Image();
		thisImg.src = src;
		inner.appendChild(thisImg);*/
		container = document.createElement("div");
		container.id = "photoCon";
		document.body.appendChild(container);
		var inner = document.createElement("div");
		container.appendChild(inner);
		inner.id = 'innerCon';
		
		var topDiv = document.createElement("div");
		
		var topDiv1 = document.createElement("div");
		if(document.getElementById("blogName"))	topDiv1.innerHTML = "<b>"+document.getElementById("blogName").innerHTML+"</b>";
		topDiv1.className = "topDiv1";
		topDiv.appendChild(topDiv1);
		inner.appendChild(topDiv);
		var topDiv2 = document.createElement("div");

		topDiv2.className = "topDiv2";
		topDiv2.innerHTML = "<span onclick='reduce()'>close</span> <img src='/images/tools/closebtn.gif' onclick='reduce()' />";
		topDiv.appendChild(topDiv2);

		thisImg = new Image();
		thisImg.style.clear = "both";
		thisImg.src = src;
		inner.appendChild(thisImg);
/*
		var cbottom = document.createElement("div");
		cbottom.className = "cbottom";
	//	cbottom.innerHTML = "<?=$info['t_source']?>";
		inner.appendChild(cbottom);
		*/
		pos = findPos(obj);
		widthX = ElmWidth(thisImg);
		if(widthX>=ori_width){	
			execute();
			container.style.visibility = "visible";
		}else{
			thisImg.onload=function(){
				widthX = ElmWidth(thisImg);
				if(widthX>=300) execute();
				container.style.visibility = "visible";	
			}						
		}
}

var ori_width;
var ori_height;
function execute(){
	widthY = ElmHeight(thisImg);
	widthXX = widthX - ori_width;
	widthYY = widthY - ori_height;
	targetX = (getavailWidth()-ElmWidth(container))/2+getscrollLeft();
	targetY = (getavailHeight()-ElmHeight(container))/2+getscrollTop();
	if(targetY<8) targetY = 8;
	container.style.left = pos[0]+"px";
	container.style.top  = pos[1]+"px";
	
	amountX = targetX - pos[0];
	amountY = targetY - pos[1];
	thisImg.style.width = ori_width+"px";
	thisImg.style.height = ori_height+"px";
	
	x = 1;
	count = 1;
	dicisive = 1;
	part();										
}
function reduce(){
	if(moving){
		moving = false;
		count = 1;
		dicisive = -1;
		//closebtn.style.display = "none";
		part();
	}
}
function part(){
	if(count>(freq)){ 
		clearTimeout(sss);

		if(dicisive==1) setOpacity(container,100);
		dicisive *= -1;
		if(dicisive == 1){ 
			container.style.display = "none";
			//obj.onclick = enlarge;
			var n = ww(obj.parentNode.parentNode,".enl");
			n[0].onclick = large;
		}else{
			//closebtn = new Image();
			//closebtn.src = "images/images/closebox.png";
			//document.body.appendChild(closebtn);
			//closebtn.onclick = reduce;
			//closebtn.style.position = "absolute";

			//closebtn.style.left = (parseInt(container.style.left)+ElmWidth(container)-20)+"px";
			//closebtn.style.top  = (parseInt(container.style.top)-10)+"px";
			thisImg.onclick = reduce;
			var n = ww(document.body,".enl");
			for(var i=0;i<n.length;i++){
				n[i].onclick = large;
			}
			object.onclick = null;
		}
		moving = true;
		return false;
	}
	thisImg.style.width = (parseInt(thisImg.style.width) + widthXX/2*Math.sin(x/freq*Math.PI)*Math.PI/freq)+"px";
	thisImg.style.height = (parseInt(thisImg.style.height) + widthYY/2*Math.sin(x/freq*Math.PI)*Math.PI/freq)+"px";
	container.style.top = (parseInt(container.style.top) + amountY/2*Math.sin(x/freq*Math.PI)*Math.PI/freq)+"px";
	container.style.left = (parseInt(container.style.left) + amountX/2*Math.sin(x/freq*Math.PI)*Math.PI/freq)+"px";
	if(dicisive==1) setOpacity(container,100/freq*count);
	else setOpacity(container,100-100/freq*count);
	var sss = setTimeout("part()",frequent);
	x++;
	count++;
}
function Mover(val){
	for(var i=1;i<3;i++){
		if(i==val){ 
			document.getElementById("tab"+i).className = "pLeft"+i;
			document.getElementById("cont"+i).style.display = "block";
		}else{
			document.getElementById("tab"+i).className = "active"+i;
			document.getElementById("cont"+i).style.display = "none";
		}
	}
}
function Vover(val){
	for(var i=1;i<3;i++){
		if(i==val){ 
			document.getElementById("sab"+i).className = "pLeft"+i;
			document.getElementById("sont"+i).style.display = "block";
		}else{
			document.getElementById("sab"+i).className = "active"+i;
			document.getElementById("sont"+i).style.display = "none";
		}
	}
}
function openW(url,w,h){
	var pop_win = window.open(url,'pop_win','width='+w+', height='+h+', scrollbars=yes');
}
//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 Mout(){
	if(setT) clearTimeout(setT);
	setP = window.setTimeout("hide()",700);
}
function Xover(){
	var pos = findPos(document.getElementById("btnB"+index));	
	document.getElementById("shBox").style.left = (pos[0]-17)+"px";
	document.getElementById("shBox").style.top = (pos[1]+17)+"px";
	document.getElementById("shBox").style.display = "block";
}
function hide(){
	document.getElementById("shBox").style.display = "none";
}
function Tover(){
	if(setP) clearTimeout(setP);
}
function shareContent(site){
	var obj = document.getElementById("sTitle"+index);
	var Surl = escape(obj.href);
	var Stitle = encodeURIComponent(obj.innerHTML);
	var Sdescription = encodeURIComponent(document.getElementById("asum"+index).innerHTML);
	switch (site) {		
		case "digg":
			pop('http://digg.com/remote-submit?phase=2&url='+Surl+'&title='+Stitle+'&bodytext='+Sdescription,'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='+Surl+'&title='+Stitle+'&notes='+Sdescription+'&tags=', 'delicious','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;		
		case "facebook":
			pop('http://www.facebook.com/sharer.php?u=' + Surl + '&t=' + Stitle, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
			break;		
		case "stumbleit":
			pop('http://www.stumbleupon.com/submit?url=' + Surl + '&title=' + Stitle, '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='+Stitle+'&c='+Sdescription+'&u='+Surl,'myspace','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "linkedin":
			pop('http://www.linkedin.com/shareArticle?mini=true&url='+Surl+'&title='+Stitle+'&summary='+Sdescription+'&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='+Surl,'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='+Surl+'&title='+Stitle+'&description='+Sdescription,'mixx','toolbar=no,resizable=yes,scrollbars=yes,width=700,height=400');
			break;
		case "newsvine":
			pop('http://www.newsvine.com/_tools/seed&save?u='+Surl+'&h='+Stitle, 'newsvine', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
			break;		
	}
}