$(document).ready(function() {
	// Hide the sidebar
	$('#container-sidebar').addClass('noshow');
	$('#container-foot').addClass('highlight');	
	
	// This makes some of the nav links kick out a thickbox popup
	$(".nav-thickbox").click(function() {
		tb_show($(this).attr('title'), $(this).attr('href').replace('#', '#TB_inline?height=400&width=450&inlineId='), $(this).attr('href'));//pass where to apply thickbox
		return false;
	});
	
	// Get our summary toggle cookie value
	var rg_st = $.cookie('summary') || 'shut';
	var togglerOpen = 'Hide';
	var togglerShut = 'Show';
	var toggler; 
	
	// Handle style settings for selected summary view styles
	if (rg_st == 'shut') {
		toggler = togglerShut;
		$("#container-splash-wrapper").hide();
	} else {
		toggler = togglerOpen;
		$("#container-splash-wrapper").show();
	}
	
	// This handles the summary toggler list item
//	$("#header-nav-links").append('<li class="page_item"><a href="main-content" id="toggle-switch" title="What has been happening around here recently"><span id="toggler">' + toggler +'</span> Recent Items</a></li>');
	
	// Add the close link inside the splash container
	$('#container-splash').prepend('<div id="container-splash-control"><a href="/" class="' + toggler.toLowerCase() + '" id="toggle-switch-inner" title="' + toggler + ' the recent happenings information"><span id="toggler">' + toggler + '</span> recent posts and comments</a></div>');

	// This handles the actually toggling of the summary box
	$('#toggle-switch, #toggle-switch-inner').click(function() {
		if ($("#container-splash-wrapper").is(":hidden")) {
			$("#container-splash-wrapper").slideDown("slow");
			$("#toggler").text(togglerOpen);
			$("#toggle-switch-inner").removeClass('show').addClass('hide');
			$.cookie('summary', 'open', { expires: 180 });
		} else {
			$("#container-splash-wrapper").slideUp("slow");
			$("#toggler").text(togglerShut);
			$("#toggle-switch-inner").removeClass('hide').addClass('show');
			$.cookie('summary', 'shut', { expires: 180 });
		}

		return false;
	});

	// Hide what needs to be hidden
	$('.no-show').css('display', 'none');
	
	// Setup the search box message, changing the text color to lighter when nothing is found there
	if ($('#s').val() == '') {
		$('#s').val($('#s').attr('title')).css('color', '#666');
	}
	
	// Now handle what happens when focus is given to it or removed from it
	$('#s').focus(function() {
		// See if the input field is the default
	 	if ($(this).val() == $(this).attr('title')) {
	 		$(this).val('').css('color', '#333');
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title')).css('color', '#666');
		}
	});

	$('a.recently').click(function() {
		var loc = $(this).attr('href');
		$(loc).ScrollTo(800);
		return false;
	});

	$('a.return-to-top').click(function() {
		$('#top').ScrollTo(800);
		return false;
	});
});
