// jQuery (javascript) functions for use on all pages. 
$(document).ready(function(){

	// Show buttons differently when hovering 			   
	$(':submit').hover(
			function(event) {$(event.target).css('opacity',.7);}, 		// mouse over 
			function(event) {$(event.target).css('opacity',1.0);}		// mouse out 
	);

	// Allow user to click on label link to select the checkbox (when using labels won't work) 		   
	$('div#category a').click( function(event) { 
		$(this).prev().attr('checked', !$(this).prev().attr('checked')); 
		return false; 
	}); 			   
			
	// Resumit/refresh page when choosing a search option. Only use with option forms at top of pages			
	$('input.options').click(function() {	
		$('form.options').submit(); 
	});	
	$('select.options').change(function() {	
		$('form.options').submit(); 
	});
	
	// Populate Instructor name fields with ajax 
	$("#instruct").autocomplete("include/searchins.php", {
		autoFill:true, 
		multiple: true, 
		mustMatch: false, 
		matchContains: false, 
		selectFirst: false, 		
		scroll: true
	});
	$("#fname").autocomplete("include/srchname.php", {
		autoFill:true, 
		mustMatch: false, 
		matchContains: false, 
		scroll: true, 
		selectFirst: false, 		
		extraParams: {type: "fname" }
	});
	$("#lname").autocomplete("include/srchname.php", {
		autoFill:true, 
		mustMatch: false, 
		matchContains: false, 
		scroll: true,
		selectFirst: false, 		
		extraParams: {type: "lname" }		
	});
	$("#title").autocomplete("include/srchtitle.php", {
		autoFill:false, 
		mustMatch: false, 
		matchContains: true, 
		selectFirst: false, 
		scroll: true	
	});	

	// Validate Reviews 
	$('#rev_text').blur(function() { 
		var review = $.trim($('#rev_text').val()); 
		if (review.length <= 40) { 
			$('div#errorDiv').addClass("error"); 
			$('div#errorDiv').html(' You must enter at least a few sentences of text in your review.');						
		} else { 
			$('div#errorDiv').removeClass("error"); 
			$('div#errorDiv').html("");			
		} 		
	}); 

	//	Give focus to first input element on each page 
	// Add this back in later, when I can figure out how to only show it on pages that I want
	// $("input:visible:enabled:first") .focus();
	
	// Make header clickable 
	/*	- Possibly too annoying 
	$('#header').click(function() { 
		window.location="http://www.videofitness.com"; return false;
	}); 
	*/	
	// Prevent Double Submissions of forms 
	/* This is not working completely correctly yet 
	$(":submit").click(function() {
	  $(this).clone().insertAfter($(this)).attr("disabled","true");
  	  $(this).hide();
	});
	*/ 


});
