$(function() {
	$('.calendar_field').attr('autocomplete','off').calendar({
		autoPopUp : 'focus',
		changeFirstDay : false,
		changeMonth : false,
		changeYear : false,
		dateFormat : 'MDY/',
		defaultDate : null,
		closeText : "X Close",
		dayNames : ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
		speed : '',
		closeAtTop : false
	});

	catchPopups();

	setTimeout(function() {}, 10);
	$('.search').touchHeight();
});

jQuery.fn.extend({
	touchHeight : function(color) {
		var $this = this;
		$this.each(function() {
			setTimeout(function() {$this.height('100%')}, 10);
		});
		return this;
	}
});

function catchPopups() {
	// Anchor rel attribute in format: popup[width,height]
	$('a[@rel^=popup]').each(function() {
		var href = $(this).attr('href');
		var prefs = $(this).attr('rel');
		var pu_width = 800;
		var pu_height = 600;
		prefs = prefs.match(/\[(\d+),(\d+)\]/);
		if (prefs) {
			pu_width = prefs[1];
			pu_height = prefs[2];
		}
		$(this).click(function() {
			window.open(href,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+pu_width+',height='+pu_height);
			return false;
		});
	});
}