jQuery(function($){
	
	$("input, textarea").not('input[type="submit"]').focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

	// turn on Twipsy tooltips for 'a rel=twipsy'
	$("a[rel=twipsy]").twipsy();

	// turn on Twipsy tooltips on focus for 'input.has-tooltip'
	$("input.has-tooltip").twipsy({
		trigger: 'focus'
	});

	// mobile browsers only
	if( navigator.userAgent.match(/Android/i) ||
	navigator.userAgent.match(/webOS/i) ||
	navigator.userAgent.match(/iPhone/i) ||
	navigator.userAgent.match(/iPod/i) ) {
		$('.tile-list .image-tile img').wrap(function() {
			return '<a href="' + $(this).prev('a').attr('href') + '" />';
		});
		$('.tile-list .image-tile a').hide();
		$('.tile-list .image-tile a:first-child').show(); 
		$('.tile-list .image-tile a:first-child').click(function(e) { 
			$(this).toggleClass('open').next().toggle();
			e.preventDefault();
		});
	} // end mobile browsers only

	// Desktop browsers only
	if(!( navigator.userAgent.match(/Android/i) ||
	navigator.userAgent.match(/webOS/i) ||
	navigator.userAgent.match(/iPhone/i) ||
	navigator.userAgent.match(/iPod/i) )) {
	
		// make info-dropdown boxes draggable
		$('.info-dropdown:not(#search-dropdown, #subnav), .info-link, .info-panel:not(#subnav)').draggable({ 
			handle: 'h3',
			stack: '.info-dropdown',
			containment: 'document',
			start: function(event, ui) {
				$(this).closest('div.info-dropdown').addClass('noclick');
			}
		});
	
		// toggle info-dropdown boxes open/closed
		$('.info-dropdown h3 a').filter(function(){return $(this).html().toLowerCase() != "free";}).click(function() {
			if ($(this).closest('div.info-dropdown').hasClass('noclick')) {
				// only when we're dragging something
				$(this).closest('div.info-dropdown').removeClass('noclick');
			} else {
				// actual click event code
				$(this).closest('div.info-dropdown').toggleClass('open');
				$(this).closest('div.info-dropdown').children('.dropdown-contents').toggle('blind', 250);
			}
		});
		$('.info-dropdown h3 a').filter(function(){return $(this).html().toLowerCase() == "free";}).css('background-image', 'none');

		// masthead fade out after page load, fades back on mouse enter
		$('#logo').not('.home #logo').delay(2000).animate({ opacity: 0 }, 500);
	  $('#logo').not('.home #logo').mouseenter(function() { $(this).clearQueue().animate({ opacity: 1 }, 500); });
	  $('#logo').not('.home #logo').mouseleave(function() { $(this).clearQueue().animate({ opacity: 0 }, 500); });
	
	}
	// end desktop browsers only
 
	// show hide stuff in containers with .accordian-list class
	$('.accordian-list h4').nextUntil('h4, h3, h2, h1').hide(); 
	$('.accordian-list h4').click(function(){
		$(this).siblings('h4').removeClass('open').nextUntil('h4, h3, h2, h1').hide(200);
		if ($(this).nextUntil('h4').is(':hidden')) {
			$(this).addClass('open').nextUntil('h4, h3, h2, h1').show('blind', 200);
		} else {
			$(this).removeClass('open').nextUntil('h4, h3, h2, h1').hide('blind', 200);
		}
	});
});
