

jQuery(document).ready(function() {

	// pimp the search box
	jQuery('#searchform #s').bind('click', function() {
		if (jQuery(this).val() == "Search") jQuery(this).val("");
	});
	jQuery('#searchform #s').bind('blur', function() {
		if (jQuery(this).val() == "") jQuery(this).val("Search");
	});
	

	// main navigation
	jQuery('#menu-primary-nav li').hover(
		// over
		function() {

			if (jQuery(this).parent().hasClass('menu')) {		
				jQuery(this).addClass("hover");			
				jQuery(this).children('ul').stop(true, true).slideDown();
			}
		
		},
		// out
		function() {
			
			if (jQuery(this).parent().hasClass('menu')) {
				jQuery(this).removeClass("hover");
				jQuery(this).children('ul').stop(true, true).slideUp('fast');
			}
		
		}
	);
	jQuery('#menu-primary-nav li ul li a').hover(
		// over
		function() {
			jQuery(this).addClass('hover');
		},
		// out
		function() {
			jQuery(this).removeClass('hover');
		}
	);
	
	
	// add the fancy >> to Read more links
	jQuery('a').each(function() {
		var t = jQuery(this).html();
		if (t.toLowerCase() == "read more" || t.toLowerCase() == "learn more" || t.toLowerCase() == "edit") {
			jQuery(this).html(t + " &raquo;");
		}
	});
	
	
	// if there's an image and text, make all the text into a right column
	jQuery('.page .entry-content').each(function() {
	
		var right_width = 0;
	
		// there are three ways this can go
		// <span class="youtube"><object /></span>
		// <div class="wp-cation"><img /></div>
		// <img />
		
		var youtube = jQuery(this).children('.youtubecontainer');
		if (youtube.length > 0) {
			right_width = 960 - youtube.width() - 30;
		} else {
			var captions = jQuery(this).children('h4').children('.wp-caption');
			if (captions.length > 0) {
				// how wide is the caption
				right_width = 960 - captions.width() - 30;
			} else {
				captions = jQuery(this).children('h4').children('img');
				if (captions.length == 0) captions = jQuery(this).children('h4').children('a').children('img');
				right_width = 960 - captions.width() - 30;
			}
		}
		
		if (right_width > 0) {
			jQuery(this).children('.text').css({
				float: 'right',
				width: right_width.toString() + 'px'
			});
		}
	
	});
		
		
	// if page content is long, split it into two columns
//	var num_p = jQuery('.page .entry-content p').length;
//	if (num_p > 5) {
//		jQuery('.page .entry-content').children().addClass('dontsplit');
//		jQuery('.page .entry-content').columnize({ columns: 2, lastNeverTallest: true });
//	}


});
