function g(a) {
	return document.getElementById(a)
}
var getElementsByClassName = function(f, g, h) {
		if (document.getElementsByClassName) {
			getElementsByClassName = function(a, b, c) {
				c = c || document;
				var d = c.getElementsByClassName(a),
					nodeName = (b) ? new RegExp("\\b" + b + "\\b", "i") : null,
					returnElements = [],
					current;
				for (var i = 0, il = d.length; i < il; i += 1) {
					current = d[i];
					if (!nodeName || nodeName.test(current.nodeName)) {
						returnElements.push(current)
					}
				}
				return returnElements
			}
		} else if (document.evaluate) {
			getElementsByClassName = function(a, b, c) {
				b = b || "*";
				c = c || document;
				var d = a.split(" "),
					classesToCheck = "",
					xhtmlNamespace = "http://www.w3.org/1999/xhtml",
					namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null,
					returnElements = [],
					elements, node;
				for (var j = 0, jl = d.length; j < jl; j += 1) {
					classesToCheck += "[contains(concat(' ', @class, ' '), ' " + d[j] + " ')]"
				}
				try {
					elements = document.evaluate(".//" + b + classesToCheck, c, namespaceResolver, 0, null)
				} catch (e) {
					elements = document.evaluate(".//" + b + classesToCheck, c, null, 0, null)
				}
				while ((node = elements.iterateNext())) {
					returnElements.push(node)
				}
				return returnElements
			}
		} else {
			getElementsByClassName = function(a, b, c) {
				b = b || "*";
				c = c || document;
				var d = a.split(" "),
					classesToCheck = [],
					elements = (b === "*" && c.all) ? c.all : c.getElementsByTagName(b),
					current, returnElements = [],
					match;
				for (var k = 0, kl = d.length; k < kl; k += 1) {
					classesToCheck.push(new RegExp("(^|\\s)" + d[k] + "(\\s|$)"))
				}
				for (var l = 0, ll = elements.length; l < ll; l += 1) {
					current = elements[l];
					match = false;
					for (var m = 0, ml = classesToCheck.length; m < ml; m += 1) {
						match = classesToCheck[m].test(current.className);
						if (!match) {
							break
						}
					}
					if (match) {
						returnElements.push(current)
					}
				}
				return returnElements
			}
		}
		return getElementsByClassName(f, g, h)
	};

function getCookie(a) {
	var b, reg = new RegExp("(^| )" + a + "=([^;]*)(;|$)");
	if (b = document.cookie.match(reg)) {
		return unescape(decodeURI(b[2]))
	} else {
		return ""
	}
}
function setCookie(a, b, c) {
	var d = new Date();
	d.setTime(d.getTime() + Number(c) * 3600 * 1000);
	document.cookie = a + "=" + b + "; path=/;expires = " + d.toGMTString()
}
function setCommentForm(a, b, c, d) {
	if (g("author") != null) g("author").value = a;
	if (g("email") != null) g("email").value = b;
	if (g("url") != null) g("url").value = c;
	if (g("ck") != null) g("ck").value = d
}
function checkComment() {
	var a = document.getElementById('comment').value;
	if (document.getElementById('author') != null) {
		if (document.getElementById('author').value == "" || document.getElementById('email').value == "" || a == "") {
			alert("你好像还有东西没填耶！");
			return false
		}
	}
	re = /[\u4E00-\u9FA5]{1,}/ig;
	r = a.match(re);
	if (r == null || r.length <= 0) {
		alert("需要输入至少1个中文...");
		return false
	}
	return true
}
function checkSearchForm() {
	if (g("searchTextbox").value == "") {
		alert("木有字囧么搜索啊！？");
		return false
	}
	return true
}
function goTop() {
	window.scrollTo(0, 1)
}
function forceNormalTheme() {
	setCookie("force_normal_theme", "true", 96);
	window.location.reload()
}
function showSubmenu(a) {
	if (g(a) == null) {
		return false
	}
	if (null != g("submenu_bg_div")) {
		hideAllSubmenu();
		return false
	}
	hideAllSubmenu();
	createBgDiv();
	g(a).style.display = "block";
	if (a == "nav_search") {
		g("searchTextbox").focus()
	}
}
function createBgDiv() {
	var a = document.createElement("DIV");
	a.id = "submenu_bg_div";
	a.style.top = 0;
	a.style.left = 0;
	a.style.display = "block";
	a.style.zIndex = 997;
	a.style.background = '#000';
	a.style.visibility = 'visible';
	a.style.position = "absolute";
	a.style.height = document.body.clientHeight + "px";
	a.style.width = document.body.clientWidth + "px";
	a.style.opacity = 0.8;
	document.body.appendChild(a);
	a.onclick = hideAllSubmenu
}
function delBgDiv() {
	var a = g("submenu_bg_div");
	if (null != a) a.parentNode.removeChild(a)
}
function hideAllSubmenu() {
	if (null != g("searchTextbox")) g("searchTextbox").blur();
	delBgDiv();
	var a = document.getElementsByClassName("submenu");
	for (var i = 0; i < a.length; i++) {
		var a = document.getElementsByClassName("submenu");
		a[i].style.display = "none"
	}
}
function changeOrientation() {
	var a = g("submenu_bg_div");
	if (null != a) {
		a.style.width = document.body.clientWidth + "px";
		a.style.height = document.body.clientHeight + "px"
	}
}
if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {
	addEventListener("onorientationchange" in window ? "orientationchange" : "resize", changeOrientation, false)
} else {
	addEventListener("resize", changeOrientation, false)
}
function loadAdTop() {
	if (document.body.clientWidth < 720) {
		document.writeln('<center><div style="border-top:1px solid #ddd;margin:-5px 0"><scr' + 'ipt type=\"text/javascript\">');
		document.writeln("google_ad_client = \"ca-pub-2420325514385307\";");
		document.writeln("/* [ipcbox手机版] 顶部横幅 */");
		document.writeln("google_ad_slot = \"4839624429\";");
		document.writeln("google_ad_width = 320;");
		document.writeln("google_ad_height = 50;");
		document.writeln("</scri" + "pt>");
		document.writeln("<scr" + "ipt type=\"text/javascript\"");
		document.writeln("src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">");
		document.writeln("</scr" + "ipt></div></center>")
	} else {
		document.writeln("<center><scri" + "pt type=\"text/javascript\">");
		document.writeln("google_ad_client = \"ca-pub-2420325514385307\";");
		document.writeln("/*[ipcbox平板版] 顶部横幅728x90 */");
		document.writeln("google_ad_slot = \"9269824023\";");
		document.writeln("google_ad_width = 728;");
		document.writeln("google_ad_height = 90;");
		document.writeln("</scr" + "ipt>");
		document.writeln("<scr" + "ipt type=\"text/javascript\"");
		document.writeln("src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">");
		document.writeln("</scr" + "ipt></center>")
	}
}
function loadAdPagenav() {
	if (document.body.clientWidth < 720) {
		document.writeln("<center><script type=\"text/javascript\"><!--");
		document.writeln("google_ad_client = \"ca-pub-2420325514385307\";");
		document.writeln("/* [ipcbox手机版] 分页导航下方 */");
		document.writeln("google_ad_slot = \"1746557220\";");
		document.writeln("google_ad_width = 300;");
		document.writeln("google_ad_height = 250;");
		document.writeln("//-->");
		document.writeln("</script>");
		document.writeln("<script type=\"text/javascript\"");
		document.writeln("src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">");
		document.writeln("</script></center>")
	} else {
		document.writeln("<center><scri" + "pt type=\"text/javascript\">");
		document.writeln("google_ad_client = \"ca-pub-2420325514385307\";");
		document.writeln("/*[ipcbox平板版] 分页导航下方728x90 */");
		document.writeln("google_ad_slot = \"3223290423\";");
		document.writeln("google_ad_width = 728;");
		document.writeln("google_ad_height = 90;");
		document.writeln("</scr" + "ipt>");
		document.writeln("<scr" + "ipt type=\"text/javascript\"");
		document.writeln("src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">");
		document.writeln("</scr" + "ipt></center>")	}
}
function postDigg(typee, id) {
	jQuery.ajax({
		type: "POST",
		url: "/",
		data: {
			type: typee,
			postid: id
		},
		success: function(data) {
			if (data == "请勿非法提交！" || data == "您已经顶过该日志，请不要重复顶日志！") {
				alert(data)
			} else {
				jQuery("#qlwz-digg").html(data)
			}
		},
		error: function() {
			alert("Digg出错")
		}
	})
}
(function($) {
	$.fn.colorTip = function(settings) {
		var defaultSettings = {
			color: 'yellow',
			timeout: 500
		}
		var supportedColors = ['red', 'green', 'blue', 'white', 'yellow', 'black'];
		settings = $.extend(defaultSettings, settings);
		return this.each(function() {
			var elem = $(this);
			if (!elem.attr('title')) return true;
			var scheduleEvent = new eventScheduler();
			var title = elem.attr('title'),
				tip = new Tip(title);
			elem.append(tip.generate()).addClass('colorTipContainer');
			var hasClass = false;
			for (var i = 0; i < supportedColors.length; i++) {
				if (elem.hasClass(supportedColors[i])) {
					hasClass = true;
					break
				}
			}
			if (!hasClass) {
				elem.addClass(settings.color)
			}
			elem.hover(function() {
				elem.removeAttr('title');
				tip.show();
				scheduleEvent.clear()
			}, function() {
				scheduleEvent.set(function() {
					tip.hide();
					elem.attr('title', title)
				}, settings.timeout)
			})
		})
	}
	function eventScheduler() {}
	eventScheduler.prototype = {
		set: function(func, timeout) {
			this.timer = setTimeout(func, timeout)
		},
		clear: function() {
			clearTimeout(this.timer)
		}
	}
	function Tip(txt) {
		this.content = txt;
		this.shown = false
	}
	Tip.prototype = {
		generate: function() {
			return this.tip || (this.tip = $('<span class="colorTip">' + this.content + '<span class="pointyTipShadow"></span><span class="pointyTip"></span></span>'))
		},
		show: function() {
			if (this.shown) return;
			this.tip.css('margin-left', -this.tip.outerWidth() / 2).fadeIn('fast');
			this.shown = true
		},
		hide: function() {
			this.tip.slideToggle("slow");
			this.shown = false
		}
	}
})(jQuery);