jQuery(document).ready(function($) {
	$('label.overlabel').overlabel();
	$('select.styled').styledSelect();

	// move the error messages into the content div
	// (easier than going through every view and adding the PHP code)
	$('#flashMessage').prependTo('#content').slideDown();

	// make sure the sidebar is as long as the content section so that the vertical 
	// line extends to the bottom
	var $sidebar = $('#sidebar');
	var $content = $('#content');
	if ($sidebar.length > 0 && $sidebar.height() < $content.height()) {
		$sidebar.height($content.height());
	}
	
	// some IE fixes
	if ($.browser.msie && $.browser.version < 8) {
		$('#main').css('paddingTop', $('#header-bar').outerHeight() + 56);
		$('select.styled').css({ width: 201, height: 32 });
	}
	
	// add the OS to the HTML tag
	$('html').addClass($.client.os.toLowerCase());
	
	if (typeof $.fn.datepicker == 'function') {
		$('#start_date, #end_date').datepicker({
			minDate: 0,
			onClose: function() {
				$(this).triggerHandler('blur'); // to get rid of overlabels
			}
		});
	}
	if (typeof $.fn.timePicker == 'function') {
		$('#start_time, #end_time').timePicker({
			show24Hours: false,
			step: 15
		});
	}

	// toggle advanced search
	var $advSearch = $('#advanced-search');
	$('#sidebar .search .toggle-advanced').click(function() {
		var $advSearch = $('#advanced-search');
		var hide = $advSearch.is(':visible');
		$advSearch.slideToggle();
		$advSearch.find(':input').attr('disabled', hide);
		return false;
	});
	if (!$advSearch.is(':visible')) {
		$advSearch.find(':input').attr('disabled', true);
	}

});

