/* rounded corners
   ========================================================================= */

$(document).ready(function(){
	/*
	 * <script type="text/javascript" src="{{ MEDIA_URL }}res/js/jquery.curvycorners.min.js"></script>
	 *
	 * Removed Curvy Corners: Not compatible with AdSense and ShareThis.
	 */
	/*
	$('#nav_home').corner();
	$('#navigation').corner();
	$('#footer').corner({
			tl: { radius: 16 },
			tr: { radius: 16 },
			bl: { radius: 16 },
			br: { radius: 16 },
			antiAlias: true,
			autoPad: true,
	});
	$('#aboutmartin').corner({
			tl: { radius: 16 },
			tr: false,
			bl: false,
			br: false,
			antiAlias: true,
			autoPad: true,
	});
	$('#aboutpage').corner({
			tl: false,
			tr: { radius: 16 },
			bl: false,
			br: false,
			antiAlias: true,
			autoPad: true,
	});
	$('#poetry').corner({
			tl: { radius: 16 },
			tr: { radius: 16 },
			bl: false,
			br: false,
			antiAlias: true,
			autoPad: true,
	});
	// if content-meta isn't empty
	if ($('#content-meta').children().length > 0) {
		$('#content').corner({
				tl: { radius: 16 },
				tr: { radius: 16 },
				bl: false,
				br: false,
				antiAlias: true,
				autoPad: true,
		});
		$('#content-meta').corner({
				tl: false,
				tr: false,
				bl: { radius: 16 },
				br: { radius: 16 },
				antiAlias: true,
				autoPad: true,
		});
	// if content-meta is empty
	} else {
		$('#content').corner({
				tl: { radius: 16 },
				tr: { radius: 16 },
				bl: { radius: 16 },
				br: { radius: 16 },
				antiAlias: true,
				autoPad: true,
		});
		$('#content-meta').hide();
	}*/
	if ($('#content-meta').children().length == 0) {
		$('#content').css({
			'-webkit-border-bottom-left-radius': '16px',
			'-webkit-border-bottom-right-radius': '16px',
			'-moz-border-radius-bottomleft': '16px',
			'-moz-border-radius-bottomright': '16px',
		});
		$('#content-meta').hide();
	}
});


/* navigation events
   ========================================================================= */

function searchFieldBlur() {
	if ($("#search-box").is(':visible')) {
		$("#search-box").hide("blind", { direction: "horizontal" }, 800);
		$("#open-search").show("blind", { direction: "horizontal" }, 800);
	}
}
function locationHoverOut() {
	if ($("#location").is(':visible')) {
		$("#location").hide("blind", { direction: "vertical" }, 500);
	}
}
$(document).ready(function(){
	$("#open-search a").click(function () {
		$("#open-search").hide("blind", { direction: "horizontal" }, 800);
		$("#search-box").show("blind", { direction: "horizontal" }, 800);
	});
	$("#search").blur(function () {
		setTimeout("searchFieldBlur()", 2000);
	});

	$("#navigation").hover(
		function () {
			if (!$("#location").is(':visible')) {
				$("#location").stop(true).show("blind", { direction: "vertical" }, 500);
			}
		},
		function () {
			setTimeout('locationHoverOut()', 1000);
		}
	);
});

/* footer events
   ========================================================================= */

function footer_toggle_helper(div, keep, action) {
	var lis = new Array();
	if (keep == 0) {
		lis = $(div);
	} else {
		lis = $(div).children('ol').children('li');
	}
	for (i=keep; i < lis.length; i++) {
		var current_li = $(lis[i]);
		if (action == 'show') {
			if (current_li.is(':hidden')) {
				current_li.stop(true).show("blind", { direction: "vertical" }, 500);
			}
		} else if (action == 'hide') {
			if (!current_li.is(':hidden')) {
				current_li.stop(true).hide("blind", { direction: "vertical" }, 500);
			}
		}
	}
}

$(document).ready(function(){
	var cols = $('#footer').find('div.column');
	var thoughts = cols[0];
	var memories = cols[1];
	var rummaging = $(cols[2]).children('div')[0];
	var headbanging = $(cols[2]).children('div')[1];

	function toggle_footer(action) {
		footer_toggle_helper(thoughts, 2, action);
		footer_toggle_helper(memories, 1, action);
		footer_toggle_helper(headbanging, 0, action);
	}

	toggle_footer('hide'); // initially hide "the rest"

	$("#footer").hover(function(){
		toggle_footer('show');
	}, function(){
		toggle_footer('hide');
	});
});