$(function() {
	var slider = $('span.slider'),
	cur = $('ul.menu > li.current, ul.menu > li.current-parent'),
	minLeft = $('ul.menu').position().left,
	interval = null,
	tries = 0;
	slideTo = function (ele, animate) {
		var left = (ele.length) ? ele.position().left + minLeft + parseInt(ele.css('marginLeft')) : 0,
		opts = {
			left: (left < minLeft) ? minLeft : left,
			'width': (ele.length) ? ele.width() : 0
		};
		
		slider.css('visibility', 'visible').stop().animate(opts, (animate === false)? 0 : 500);
	};
	
	$('ul.menu > li').hover(function() {
		clearInterval(interval);
		slideTo($(this), true);
		$(this).addClass('hover');
	},
	function() {
		slideTo(cur, true);
		$(this).removeClass('hover');
	});
	slideTo(cur, false);
	// Temporary fix to reposition slider when TypeKit loads fonts
	interval = setInterval(function() {
		if (tries == 20) {
			clearInterval(interval);
		}
		slideTo(cur, false);
		tries++;
	}, 100);
});

function positionFooter() {
	if($("body").hasClass('landing_page')) {
		return;
	}
	var extra = ($("#footer").css('position') == "absolute") ? $('#footer').height() + 10 : 0;
	// Show the footer, but only once this function is called. Solves the "jumping footer" problem
	$("#footer").css({display: "block"});
	if($(document.body).height() + extra < $(window).height()) {
		$("#footer").css({position: "absolute",bottom: 0});
	} else {
		$("#footer").css({position: ""});
	}
}
$(window).resize(positionFooter);
$(document).ready(positionFooter);
