$(document).ready(function(){
	//Button UI.
	$(".button").button();
	
	//Check for banner click.
	$(".banner_item").click(function(){
		//Register banner click.
		$.post("/", { name:"register_banner_click", id:$(this).data("id") });
	});

	/* Masthead */
		//Listen for banner mouse event.
		$("#banner_container #banner .item").mouseenter(function(e){
			//Disable fade for IE < 9.
			if($.browser.msie && $.browser.version < 9){
				//Animate former banner in (hide) and lower opacity of image.
				$("#banner_container #banner .item").stop().animate({ "width":197 }, 500, "swing").children("img").stop();
				
				//Animate selected banner out (show) and increase opacity of image.
				$(this).stop().animate({ "width":562 }, 500, "swing").children("img").stop();
			} else {
				//Animate former banner in (hide) and lower opacity of image.
				$("#banner_container #banner .item").stop().animate({ "width":197 }, 500, "swing").children("img").stop().animate({ "opacity":0.35 }, "swing");
				
				//Animate selected banner out (show) and increase opacity of image.
				$(this).stop().animate({ "width":562 }, 500, "swing").children("img").stop().animate({ "opacity":1 }, "swing");
			}
		});
		
	/* Sub Navigation */
		//Add toggle.
		$("#secondary_navigation > li").prepend("<a class='expand_collapse_toggle expand' href='#'></a>");
	
		//If on a sub-navigation page, auto expand menu items.
		var expand_subnav = $("#secondary_navigation").find(".current");
		if(expand_subnav.length){
			//Determine if top page or sub-page.
			if($(expand_subnav).parent().parent().attr("id") != undefined){
				//Show menu items.
				expand_subnav.parent().children("ul").css({ "display":"block" });
				
				//Fix expand/collpase arrows.
				expand_subnav.parent().children(".expand").addClass("collapse").removeClass("expand");
			} else {
				//Show menu items.
				expand_subnav.parents("ul").css({ "display":"block" });
				
				//Fix expand/collpase arrows.
				expand_subnav.parent().parent().parent().children(".expand").addClass("collapse").removeClass("expand");
			}
		}
		
		//Show/hide.
		$(".expand_collapse_toggle").click(function(e){
			//Prevent default link action.
			e.preventDefault();
			
			//Toggle arrow.
			if($(this).hasClass("expand")){
				$(this).addClass("collapse").removeClass("expand");
			} else {
				$(this).addClass("expand").removeClass("collapse");
			}
			
			//Toggle sub-page display.
			$(this).parent().children("ul").slideToggle();
		});
		
	/* Banner */
		//Check for banner click.
		$(".banner_item").click(function(){
			//Register banner click.
			$.post("/", { name:"register_banner_click", id:$(this).data("id") });
		});

	/* Newborns */
		//Check for month click.
		$(".month h4").click(function(){
			$(this).siblings(".newborn_list").slideToggle(1000, "swing");
		});
	
	/* UI */
		//Button.
		$(".button").button();
		
		//Add stripes to tables.
		$("#right_column table tr:even td").css({ "background":"#FFFFFF" });
		$("#right_column table tr:odd td").css({ "background":"#E5ECF9" });
});
