$(document).ready(function () {
	highlight_nav();
	// add corners to highlighted nav buttons
	//$("li.highlight a").corner("4px");	
	anchor_bottom('.anchor-bottom',0);
}); 

// add class 'highlight' to last two menu items in sub nav.
function highlight_nav() {
	var menu_length=$('#nav_sub').children().length;
	$('#nav_sub li:gt(' + (menu_length-3) + ')').addClass('highlight');	
}

//move divs to bottom of <section> with a minimum margin of minMargin
function anchor_bottom(elements,minMargin) {
	// hide elements until they are positioned correctly.
	$(elements).css('visibility','hidden');
	// remove initial margin to even out elements			
	$(elements).css("padding-top",minMargin + "px");
	// make element calculate height including all margins and float of child elements
	//$(elements).css("overflow","auto"); 
	// stop element from squeezing in gaps now it has overflow:auto
	//$(elements).css("clear","both");
	// need delay for images to load
	window.setTimeout(function() {
		$(elements).each(function(){
			var a= $(this);
			//calculate distance between bottom of parent element and section
			var m = a.parents('section').height() - a.parent().outerHeight(true);
			// minimum of 0px margin
			m=Math.max(minMargin,m);
			a.css('padding-top',m+'px');
		});
		// show all elements now they are positioned correctly
		$(elements).css('visibility','visible');
	}, 800); // milliseconds

}


// twitter feed for homepage
jQuery(function($){
    $(".top-tweet").tweet({
        username: "TravelTF",
        count: 1,
        loading_text: "Loading latest tweet...",
		template: "<p>{text}</p>"
    }).bind("loaded",  function() {
	    //anchor_bottom('.anchor-bottom',0);
	});
});

