$(document).ready(function(){


  /* side bar */
  var $sidebar = $('#sideBar');
  var $body = $('#body');
	var sidebarHeight = $sidebar.height();
	var threshold = sidebarHeight + 240; // minimum outerHeight for #body
	var bodyHeight;
	
	$body.bind('onHeightChange', function(){
		$body.css({height: 'auto'});
		bodyHeight = $body.outerHeight();
		
		if (($('#home').length != 1) && (bodyHeight < threshold)) {
			$body.height( threshold - ( parseInt($body.css('paddingTop')) + parseInt($body.css('paddingBottom')) ) );
			$sidebar.height(threshold);
		}	else {
			$sidebar.height(bodyHeight);
		}				
	});
	
	$body.trigger('onHeightChange');
	

  /* main nav */
  $('#mainNav > li').hoverIntent(function(){
    $(this).children('ul').slideDown(100);
  }, function(){
    $(this).children('ul').slideUp(200);
  });


  /* page title */
  var pageTitle = $('#pageTitle').html();
  var firstSpace = pageTitle.indexOf(' ');

  if (firstSpace > 0) {
    $('#pageTitle').html('<span class="container"><span class="first">' + pageTitle.slice(0, firstSpace) + '</span>' + pageTitle.slice(firstSpace) + '</span>');
  } else {
    $('#pageTitle').html('<span>' + pageTitle + '</span>');
  }

	/* search form */
	$('#searchForm input[type="text"]').focus(function(){
		if (this.value == 'Search...') 
			this.value = '';
	}).focusout(function(){
		if (this.value == '')
			this.value = this.defaultValue;
	});
});
