jQuery('html').addClass('js');

// Put all custom plugins here.

(function($){
	
	// toggle element visibility with a handle
	$.fn.toggleElement = function(options) {
		options = $.extend({
			handle: '',
			show: 'More',
			hide: 'Fewer',
            animate: ''
		},
		options);
		
		return $.each(this, function() {
			var self = $(this);
			self.hide();
			$(options.handle).click(function(){
                switch (options.animate) {
                    case 'slide' :
                        self.slideToggle('slow',function(){
                            $(options.handle).text(options[$(this).is(':visible') ? 'hide':'show']);
                        });
                        break;
                    default :
                        self.toggle('slow',function(){
                            $(options.handle).text(options[$(this).is(':visible') ? 'hide':'show']);
                        });
                        break;
                }
				return false;
			});
		});
	}
	
	// Generate Toc from headings
	$.fn.gentoc = function(options) {
		options = $.extend({
			target: ''
		},
		options);
		
		return $.each(this, function() {
		});
	}
	
})(jQuery);
	
jQuery(function($){

	$('.datepicker, .datepicker-datetime, .datepicker-dob').datepicker({
		showOn: 'button',
		buttonImage: '/includes/img/calendar.gif',
		buttonImageOnly: true,
		dateFormat: 'yy-mm-dd'
	});
	$('.datepicker-dob').datepicker('option', {
		changeMonth: true,
		changeYear: true,
		maxDate: '-1d',
		minDate: '-100y',
		yearRange: '-100:0'
	});
	$('.datepicker-datetime').datepicker('option', {
		onSelect: function(dateText, inst) {
			var dt = new Date();
			var time = dt.getHours() +':'+ (dt.getMinutes() < 10 ? '0':'') + dt.getMinutes() +':'+ dt.getSeconds();
			$(this).val(dateText +' '+ time);
		}
	});
	
	// watermark
	//$('.watermark').watermark();
	
//	$('.more-search-options').toggleElement({
//		handle: '.more-search-options-toggle', 
//		show:'More search options', 
//		hide: 'Fewer search options'
//    });
	$('.refine-search').toggleElement({
		handle: '.refine-search-toggle',
		show:'Refine Search',
		hide: 'Close',
        animate: 'slide'
    });

	$('a[rel=gmap]:not(.gmapped)').each(function() {
		var link = $(this)[0].href;
		$('<iframe width="622" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+ link +'&amp;output=embed"></iframe><br />').insertBefore(this);
		$(this).addClass('gmapped');
	});
});