jQuery(function() {
	
	// blog search
	jQuery('#s')
		.focus(function() {
			if (jQuery(this).val() == 'Search...')
				jQuery(this).val('');
		})
		.blur(function() {
			if (jQuery(this).val() == '')
				jQuery(this).val('Search...');
		});
	
	// sidebar nav
 	jQuery("#side_nav .nav").find("ul").hide().css({"height":"0px"});
	var shown = jQuery(".shown");
	shown.css({"height":(shown.find("li").length*32)+"px"}).show();

	jQuery("#side_nav .nav").hover(function() {
	   var ul = jQuery(this).find("ul");
	   if( ul.length > 0 && !ul.hasClass("shown") )
	   ul.stop().animate({"height" : (ul.find("li").length*32)+"px"},"fast","swing");
	}, function() {
	   var ul = jQuery(this).find("ul");
	   if( ul.length > 0 && !ul.hasClass("shown") )
	   ul.stop().animate({"height" : "0px"},"fast","swing",function(){jQuery(this).hide()});
	});
	
	// insert a magical span in our blog sidebar menu
	jQuery('.navigation a').each(function() {
		jQuery(this).prepend('<span></span>');
	});
	
  jQuery('.datepicker').each(function() {
		var element = jQuery(this);
		var format = element.hasClass("mdy") ? "mm/dd/yy" : "dd/mm/yy";

		var image = "";
		var showOn = "focus";
		if(element.hasClass("datepicker_with_icon")) {
		    showOn = "both";
		    image = jQuery('#gforms_calendar_icon_' + this.id).val();
		}
		
		element.datepicker({ yearRange: '-100:+10', showOn: showOn, buttonImage: image, buttonImageOnly: true, dateFormat: format });
  });
	
	// Accordion
  if (jQuery('.accordion').length > 0)
		jQuery('.accordion').accordion({ 'header': "h3.toggler", "active":false, "autoHeight":false, "alwaysOpen":false, 'collapsible': true });
		
	// contact us page
	jQuery('.contact_us_email_field').appendTo('#askaquestion').wrap('<ul style="list-style-type:none;"/>');
	jQuery('#contact_info').prependTo(jQuery('form'));
});