var slideheight = 400;
var slidetime   = 900;

addresses = {
	"personal":  String.fromCharCode(109, 101, 64, 100, 97, 110, 105, 101, 108, 113, 117, 105, 110, 110, 46, 111, 114, 103),
	"corporate": String.fromCharCode(99, 111, 114, 112, 111, 114, 97, 116, 101, 64, 100, 97, 110, 105, 101, 108, 113, 117, 105, 110, 110, 46, 111, 114, 103)
}


function slider_setup() {

	var box  = $(this);
	var body = box.html();

	if (box.height() > slideheight) {
		box.attr("alt", box.height());
		box.html("\
			<div class=\"slider_content\">" + body + "</div>\
			<div class=\"slider_toggle\"><a href=\"#\" class=\"more\">More</a></div>\
		");
	}

}


function slider_toggle(box) {
	var action = (box.text() == "More") ? "open" : "close";
	var container = box.parents(".slider");
	if (action == "open") {
		var h = container.attr("alt");
		container.children(".slider_content").animate({"height": h}, {"duration": slidetime });
		box.removeClass("more");
		box.addClass("less");
		box.text("Less");
	} else {
		container.children(".slider_content").animate({"height": slideheight.toString() + "px"}, {"duration": slidetime });
		box.removeClass("less");
		box.addClass("more");
		box.text("More");
	}
}


$(document).ready(function(){


	// Email obfuscation
	$("a.fml").each(function(){
		$(this).attr("href", String.fromCharCode(109,97,105,108,116,111,58) + addresses[$(this).attr("title")]);
	});


	// Partial show/hide
	$(".slider").each(slider_setup);
	$(".slider .slider_content").css("height", slideheight.toString() + "px");
	$(".slider .slider_toggle a").click(function() {
		slider_toggle($(this));
		return false;
	});

	if ( window.addEventListener ) {

		var state = 0, konami = [38,38,40,40,37,39,37,39,66,65];

		window.addEventListener("keydown", function(e) {

			if ( e.keyCode == konami[state] ) {
				state++;
			} else {
				state = 0;
			}

			if ( state == 10 ) {
				alert("That's right, you're a rockstar :-)");
				window.location.href = "/blog/random/favourite/";
			}

		}, true);

	}


});

