jQuery(document).ready(function() {
	// enable syntax highlighter
	sh_highlightDocument();

	// auto select the short url of the article
	jQuery('#share-form input').click(function() {
		this.focus();
		this.select();
	});

	// setup fixed search bar
	jQuery('#header').css({ position:'fixed', top:'0px' });
	jQuery('#search-form').css({ marginBottom:'0px' });
	jQuery('#page').css({ paddingTop:'106px' });

	// setup the live search
	var search_page = $('#search-page');
	var page_data = "";

	jQuery('#search-form input').focus(function() {
		jQuery(this).val("");

		if(parseInt(search_page.length) > 0) {
			// save current page data
			page_data = jQuery('#page').html();
			// display loading indicator
			// jQuery('#ajax-loader').fadeIn();

			// save page object
			var page = jQuery('#page');
			page_height = page.height();

			setTimeout(function() {
				// replace page data with archive
				page.height(page_height).children().fadeOut();
				page.html(search_page.html()).children().hide().fadeIn();
				page.height('auto');

				// setup live search
				jQuery('#search-form input#s').liveUpdate('div.listing ul');
				// hide ajax loader indicator
				// jQuery('#ajax-loader').fadeOut();
			}, 250);
		} else {
			// setup live search
			jQuery('#search-form input#s').liveUpdate('div.listing ul');
		}
	});

	jQuery('#search-form input#s').blur(function() {
		jQuery(this).val("Browse this site... Differently.");

		if(parseInt(search_page.length) > 0) {
			setTimeout(function() {
				// save page object
				var page = jQuery('#page');
				page_height = page.height();

				// restore page data to original
				page.height(page_height).children().fadeOut();
				page.html(page_data).children().hide().fadeIn();
				page.height('auto');
			}, 250);
		}
	});

});
