var colors = {
	0: {
		hex: "#ff5640",
		hexDark: "#d51900",
		hexLight: "#ffaba0"
	},
	23: {
		hex: "#ffa040",
		hexDark: "#d56a00",
		hexLight: "#ffcfa0"
	},
	45: {
		hex: "#ffe640",
		hexDark: "#d5b800",
		hexLight: "#fff2a0"
	},
	68: {
		hex: "#cfff40",
		hexDark: "#a0d500",
		hexLight: "#e7ffa0"
	},
	90: {
		hex: "#89ff40",
		hexDark: "#52d500",
		hexLight: "#c4ffa0"
	},
	113: {
		hex: "#40ff40",
		hexDark: "#00d500",
		hexLight: "#a0ffa0"
	},
	135: {
		hex: "#40ff86",
		hexDark: "#00d54e",
		hexLight: "#a0ffc3"
	},
	158: {
		hex: "#40ffcf",
		hexDark: "#00d5a0",
		hexLight: "#a0ffe7"
	},
	180: {
		hex: "#40e9ff",
		hexDark: "#00bcd5",
		hexLight: "#a0f4ff"
	},
	203: {
		hex: "#40a0ff",
		hexDark: "#006ad5",
		hexLight: "#a0cfff"
	},
	225: {
		hex: "#4059ff",
		hexDark: "#001cd5",
		hexLight: "#a0acff"
	},
	248: {
		hex: "#7040ff",
		hexDark: "#3500d5",
		hexLight: "#b7a0ff"
	},
	270: {
		hex: "#b640ff",
		hexDark: "#8300d5",
		hexLight: "#daa0ff"
	},
	293: {
		hex: "#ff40ff",
		hexDark: "#d500d5",
		hexLight: "#ffa0ff"
	},
	315: {
		hex: "#ff40b9",
		hexDark: "#d50087",
		hexLight: "#ffa0dc"
	},
	338: {
		hex: "#ff4070",
		hexDark: "#d50035",
		hexLight: "#ffa0b7"
	}
};

$("#colors").children().each(function()
	{
		$(this).click(function()
			{
				var hue = $(this).attr("href").match(/[&?;]hue=(\d+)$/)[1];
				setCookie("hue", hue);
				$("#link-colors").remove();
				$("head").append("<style id=\"link-colors\"><!--\r\n" +
					"a, #section-header > nav a, #section-header > .nav a { " +
						"border-bottom-color : " + colors[hue]["hexDark"] + "; " +
					"}\r\n" +
					"a, #section-header > nav a, #section-header > .nav a, #twitter-feed a { " +
						"color : " + colors[hue]["hexDark"] + "; " +
					"}\r\n" +
					"a:hover, #section-header > nav a:hover, #section-header > .nav a:hover { " +
						"border-bottom-color : " + colors[hue]["hex"] + "; " +
					"}\r\n" +
					"a:hover, #section-header > nav a:hover, #section-header > .nav a:hover, #twitter-feed a:hover { " +
						"color : " + colors[hue]["hex"] + "; " +
					"}\r\n" +
					"body > header > section, body > .header > .section { " +
						"background-color : " + colors[hue]["hex"] + "; " +
						"background-image : url(\"/images/sliders/gradients/" + hue + ".jpg\"); " +
					"}\r\n" +
					"body > header > section div.background, body > .header > .section div.background { " +
						"background-image : url(\"/images/sliders/" + hue + ".jpg\"); " +
					"}\r\n" +
				"--><\/style>");
				$("#rss").children().remove();
				$("#rss").append(
					'<a href="/feeds/rss.rss" title="Subscribe to CharlesStover.com">' +
					'<img alt="Subscribe to CharlesStover.com" height="32" src="/images/icons/32/rss/' + hue + '.png" width="32" />' +
					'<\/a>'
				);
				return false;
			}
		);
		$(this).hover(function(e)
			{
				var attributes = {
					mouseenter: {
						borderRadius: "8px",
						height: "16px",
						margin: "-2px 1px 0 -2px",
						width: "16px"
					},
					mouseleave: {
						borderRadius: "6px",
						height: "12px",
						margin: "0 3px 0 0",
						width: "12px"
					}
				};
				for (a in attributes[e.type])
					$(this).css(a, attributes[e.type][a]);
			}
		);
		var hue = $(this).attr("href").match(/[&?;]hue=(\d+)$/)[1];
		if (
			readCookie("hue") == hue ||
			(
				!readCookie("hue") &&
				hue == 23
			)
		)
			$(this).click();
	}
);
$("#rss img").live("hover", function(e)
	{
		$(this).fadeTo(250, e.type == "mouseover" ? 0.66 : 1);
	}
);
