$(document).ready(function(){
	(function() {
		var ua = navigator.userAgent.toLowerCase();
		if (ua.indexOf("safari") != -1) {
			var css = document.getElementById("style");
			css.href = "kyapi3d.css";
		}
	})();

	// rainbow
	$(".rainbow").each(function(i1, e1) {
		function toSpans(element) {
			var str = element.firstChild.data;
			var length = str.length;
			element.removeChild(element.firstChild);
			for (var i = 0; i < length; i++) {
				var span = document.createElement("span");
				span.className = "rainbow_span";
				var content = document.createElement("span");
				content.textContent = str.charAt(i);
				span.appendChild(content);
				element.appendChild(span);
			}
		}

		function colorGenerator(step) {
			return function() {
				step = (step + 1) % 6;
				var r = (step == 5 || step == 0 || step == 1) ? 255 : 0; 
				var g = (step == 1 || step == 2 || step == 3) ? 255 : 0; 
				var b = (step == 3 || step == 4 || step == 5) ? 255 : 0; 
				return "rgb(" + r + "," + g + "," + b + ")";
			};
		}

		function toTextShadow(rgb) {
			return "-8px -8px 64px " + rgb + "," +
			       "+8px -8px 64px " + rgb + "," +
			       "-8px +8px 64px " + rgb + "," +
			       "+8px +8px 64px " + rgb;
		}

		toSpans(e1);
		$(".rainbow_span").each(function(i2, e2) {
			var color = colorGenerator(i2);
			var span = $(this);
			function next() {
				var nextColor = color();
				span.animate({
					color: nextColor,
				}, {
					duration: 2000,
					complete: function() { next(); },
					step: function() {
						span.css({
							textShadow: toTextShadow(span.css("color")),
						});
					},
				});
			}
			next();
		});
	});

	// anywhere
	twttr.anywhere(function (T) {
		T("#tweet_box").tweetBox({
			label: "☆（ゝω・）v",
			defaultContent: "☆（ゝω・）v",
		});
	});
});
