$(function() {
	// initialize Superfish dropdowns for the primary nav
	$('#header-nav').superfish({autoArrows: false});
	
	// side nav rollovers 
	$('#side-nav ul a').hover(
		function() {
			$(this).animate({backgroundColor: '#efefef'}, 'fast');
		},
		function() {
			$(this).animate({backgroundColor: '#fff'}, 'fast');
		}
	);
	
	// If form inputs have a default value, clear on focus
	$('.default-text').focus(function() {
		this.value = "";
		$(this).removeClass('default-text');
	})
	// Restore default text
	.blur(function() {
		if(!this.value.length) {
			this.value = this.defaultValue;
			$(this).addClass("default-text");
		}
	});

	// open/close form divs based on selection. input has class "opennext"
	function switchyswitch() {
		var thediv =  $(this).parent().next("div");
		switch ($(this).val()) {
			case "Friend/Referral": // how did you find us
			case "Other": // how did you find us
			case "Redesign of Existing Site": // project type
			case "Updates/Changes to Existing Site": // project type
			case "Yes": // radio buttons and checkboxes
			thediv.slideDown();
			break;
			default: thediv.slideUp();
		}
	}
	// ie will not trigger change() until the radio button or checkbox loses focus. must use click()
	$(":radio.open-next, :checkbox.open-next").click(switchyswitch);
	
	// safari doesn't do click() on a select element. must use change()
	$("select.open-next").change(switchyswitch); 
	
// when the social button is clicked, we check to see if it's being displayed or not
	// because it could have been hidden via the close button
	// also changing hover background position based on open/close
	$('#social-button-anchor').click(
		function() {
			if($('#social-panel').css('display') == 'none') {
				$('#social-panel').show();
				$('#social-button-anchor').css('background-position', 'bottom');
			} else {
				$('#social-panel').hide();
				$('#social-button-anchor').css('background-position', '');
			}
		}
	);
	
	// close the social panel and reposition the anchor
	$('#social-panel-close').click(
		function() {
			$('#social-panel').hide();
			$('#social-button-anchor').css('background-position', '');
		}
	);
});
