(function() {
	var xmlHttp;
	function getXmlHttpObject() {
		var xmlHttp = null;
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}
	function page(wpurl, args, start, loading) {
		xmlHttp = getXmlHttpObject();
		if (xmlHttp == null) {
			alert ("Oop! Browser does not support HTTP Request.")
			return;
		}
		var url = wpurl;
		url += "?action=rc_ajax";
		url += "&args=" + args;
		url += "&start=" + start;
		xmlHttp.onreadystatechange = function(){runChange(loading)};
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	function detail(id, wpurl, args, start, loading) {
		xmlHttp = getXmlHttpObject();
		if (xmlHttp == null) {
			alert ("Oop! Browser does not support HTTP Request.")
			return;
		}
		var url = wpurl;
		url += "?action=rc_detail_ajax";
		url += "&id=" + id;
		url += "&args=" + args;
		url += "&start=" + start;
		xmlHttp.onreadystatechange = function(){runChange(loading)};
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	function runChange(loading) {
		var firstItem = document.getElementById("rc_item_1");
		var parent = firstItem.parentNode;
		var navigator = document.getElementById("rc_nav");
		if (xmlHttp.readyState < 4) {
			document.body.style.cursor = 'wait';
			if (navigator) {
				navigator.innerHTML = (loading == undefined) ? "Loading..." : loading + "...";
			}
		} else if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") {
			parent.innerHTML = xmlHttp.responseText;
			document.body.style.cursor = 'auto';
		}
	}
	window['RCJS'] = {};
	window['RCJS']['page'] = page;
	window['RCJS']['detail'] = detail;
})();
(function() {
	var xmlHttp;
	function getXmlHttpObject() {
		var xmlHttp = null;
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}
	function showall(wpurl, args, loading) {
		xmlHttp = getXmlHttpObject();
		if (xmlHttp == null) {
			alert ("Oop! Browser does not support HTTP Request.")
			return;
		}
		var url = wpurl;
		url += "?action=ml_ajax";
		url += "&args=" + args;
		xmlHttp.onreadystatechange = function(){runChange(loading)};
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	function runChange(loading) {
		var navigator = document.getElementById("ml_nav");
		var parent = navigator.parentNode;
		if (xmlHttp.readyState < 4) {
			document.body.style.cursor = 'wait';
			navigator.innerHTML = (loading == undefined) ? "Loading..." : loading + "...";
		} else if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") {
			parent.innerHTML = xmlHttp.responseText;
			document.body.style.cursor = 'auto';
		}
	}
	window['MLJS'] = {};
	window['MLJS']['showall'] = showall;
})();
(function() {
	function $(id) {
		return document.getElementById(id);
	}
	function setStyleDisplay(id, status) {
		$(id).style.display = status;
	}
	window['MGJS'] = {};
	window['MGJS']['$'] = $;
	window['MGJS']['setStyleDisplay'] = setStyleDisplay;
})();
function switchImage(imageId, imageUrl, linkId, linkUrl, preview, title, alt) {
	if(imageId && imageUrl) {
		var image = $(imageId);
			image.src = imageUrl;
		if(title) {
			image.title = title;
		}
		if(alt) {
			image.alt = alt;
		}
	}
	if(linkId && linkUrl) {
		var link = $(linkId);
		link.href = linkUrl;
	}
}
jQuery.getPos = function (e) {
	var l = 0;
	var t = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e) {
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) {
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v) {
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};
jQuery.fx.ScrollTo = function (e, o) {
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};
$(document).ready(function() {
	$('a').attr('onfocus','this.blur()');
	$('.addcomment').click(function(){$('#respond').ScrollTo(1000);setTimeout(function(){$('#comment').focus();},500);return false;});
	if($('input#author[value]').length>0){
		$("#author_info").css('display','none');
		var change='<span id="show_author_info" class="change">change &raquo;</span>';
		var close='<span id="hide_author_info" class="change">close &raquo;</span>';
		$('#welcome').append(change);
		$('#welcome').append(close);
		$('#hide_author_info').css('display','none');
		$('#show_author_info').click(function() {
			$('#author_info').slideDown();
			$('#show_author_info').css('display','none');
			$('#hide_author_info').css('display','inline');
			$('#hide_author_info').click(function() {
				$('#author_info').slideUp();
				$('#hide_author_info').css('display','none');
				$('#show_author_info').css('display','inline');
	})})};
	$('#trackbacks_box').css('display','none');
	$('#trackbacks_hide').css('display','none');
	$('#trackbacks_show').click(function() {
		$('#trackbacks_box').slideDown()
		$('#trackbacks_show').css('display','none');
		$('#trackbacks_hide').css('display','inline');
		$('#trackbacks_hide').click(function() {
			$('#trackbacks_box').slideUp()
			$('#trackbacks_hide').css('display','none');
			$('#trackbacks_show').css('display','inline');
	})});
	if ($('#commentform').length) {
		$('#commentform').submit(function() {
			jQuery.ajax({
				url: 'http://xuzhuoer.com/wp-content/themes/blocks/comments-ajax.php',
				data: $('#commentform').serialize(),   
				type: 'POST',
				beforeSend: function() {
					$('#commenterror').slideUp();
					var submit='<div id="commentload"></div>';
					var error='<div id="commenterror"></div>';
					$('#submit').after(submit);
					$('#comments').after(error);
					$('#commentload').fadeIn();
				},
				error: function(request) {
					$('#commentload').fadeOut();
					$('#commenterror').slideDown().html(request.responseText);
				},
				success: function(data) {
					$('textarea').each(function(){this.value='';});
					$('#commenterror').hide().html();
					if (!$('#comments').length){$('#pinglist').before('<ul id="comments"></ul>');}
					$('#comments').append(data);
					var new_comment = $('#comments li:last').hide();
					new_comment.slideDown();
					$('#commentform:input').attr('disabled', true);
					$('#nocomment').slideUp();
					$('#commentload').slideUp();
					setTimeout(function() {$('#commentform:input').removeAttr('disabled');}, 0);
				}
			});
			return false;
		});
	}
});

