//////////////////////////////////////////
//
//  High Note Musical Services 2.0
//	Date:             June 2011
//	Comment Author:   Courtney Fantinato
//
//////////////////////////////////////////


jQuery(function ($) { // required to be able to use $ shortcut with built-in WordPress jQuery file

	// document ready
	$(function() {
	
		//------ Search Input ------//
	
		// Get the attribute Value of the input #s and store it in a variable
		var inputValueText = $('#s').attr('value');
	
		// On focus
		$('#s').focus(
			function() {
				// If the attribute value matches the text in the variable
				if( $('#s').attr('value') == inputValueText ){
					// The input value will be changed to empty
					$('#s').attr('value', '');
				}
			}
		);
		
		
		
		
		
		//------ Search Widget Input ------//
	
		// Get the attribute Value of the input #s and store it in a variable
		var widgetInputValueText = $('#s-widget').attr('value');
	
		// On focus
		$('#s-widget').focus(
			function() {
				// If the attribute value matches the text in the variable
				if( $('#s-widget').attr('value') == widgetInputValueText ){
					// The input value will be changed to empty
					$('#s-widget').attr('value', '');
				}
			}
		);
		
		
		
		
		
		//------ Suckerfish drop-down animation ------//
		
		// When hovering over the list item of the parent UL in the nav
		$('nav ul li').hoverIntent(function() {
			$(this)
				.find('ul:first') // Find the first UL
				.stop(true, true)
				.slideDown('fast'); // Slide down menu on hover
		}, function() {
			$(this)
				.find('ul:first') // Find the first UL
				.stop(true, true)
				.fadeOut('fast'); // Fade menu off hover
		});
		
		
		
		
		
		//------ Back to top auto scrolling ------//
		
		// On link click
		$('.totop a').click(function () {
			// Scroll to 0px
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
		
		
		
		
		
		//----- Removes inline height and width from images inserted through WP media (and all other images) ------//
		
		$('img').each(function(){
			$(this).removeAttr('width')
			$(this).removeAttr('height');
		});
		
		
		
		
		
		//------ Dynamically create select drop-down menu for small screens (Thanks to css-tricks.com!) ------//
		
		// Create the dropdown base
		$("<select />").appendTo("nav");
		
		// Create default option "Go to..."
		$("<option />", {
		   "selected": "selected",
		   "value"   : "",
		   "text"    : "Select a page..."
		}).appendTo("nav select");
		
		// Populate dropdown with menu items
		$("nav a").each(function() {
		 var el = $(this);
		 $("<option />", {
		     "value"   : el.attr("href"),
		     "text"    : el.text()
		 }).appendTo("nav select");
		});
		
		$("nav select").change(function() {
			window.location = $(this).find("option:selected").val();
		});
	
	});

});
