var main = function($) {
	
	// Private members
	var search_prompt_string = 'type then enter';
	var extras_open = true;
	
	var reset_search_box = function() {
		var $q = $('#q');
		if ($q.val() == '') {
			$q.val(search_prompt_string).css('color','#bbb');
		}
	}
	
	// Public members
	return {
		
		init : function() {
			
			// Initially hide home logo
			$('#site-title').css('opacity', 0.01).mouseover(function(){
				$('#site-title').stop().fadeTo(20, 1);
			}).mouseout(function(){
				$("#site-title").stop().fadeTo(2000, 0.01);
			});
			
			// Add some PNG fixing.
			$('#body, #site-title a').pngfix({sizingMethod: "crop"});

			if ($('#body>article.home').length > 0) {
				// Keep it small
				var article_height = $('#body>article').height();
				$('#body>article').height(250).css({visibility:"visible"});

				var $body_more = $('<div id="body-more"><a href="#more">More &nbsp;&#9660;</a></div>')

				.click(function(){
					$('#body>article').animate({height:article_height}, 2000, function(){
						$(this).css({overflow: "visible"});
					});
					$(this).remove();
					return false;
				});

				$body_more.appendTo('#body').pngfix({sizingMethod: "crop"});
			}
			

			
			
			// Initialise the search box
			reset_search_box();
			$('#q').blur(reset_search_box);
			$('#q').focus(function(){
				if ($(this).val() == search_prompt_string) {
					$(this).val('').css('color', '#000');
				}
			});
			
			// Style up the dialog heading.
			$(document).bind('dialogopen', function() {
				Cufon.replace('.ui-dialog-title');
			});
			
			// Setup the extras
			var $extras = $('body>footer>div.extras:first-child').hide();
			var $switch = $('<a href="#extras" id="extras-switch">On</a>').css('opacity', 0.5).mouseover(function(){
				console.log(this);
				$(this).stop().fadeTo(20, 50);
			}).mouseout(function() {
				console.log(this);
				$(this).stop().fadeTo(20, 0.2);
			}).click(function() {
				$extras.slideToggle();
				return false;
			});
			$switch.insertAfter($extras);
		}
		
		
	}
	
}(jQuery);

// Initialise the JS
jQuery(function() {
	main.init();
});
