/* 
 * Javascript
 * This file utilizes Jquery.
*/
$(document).ready(function(){
	
	/*
	 * Fn: Hide objects on page load
	 *     The idea behind this is that we would hide an object only if user has JS enabled.
	 * Usage: <element class="anyclass hide">
	*/
	$(".hide").hide(); // Maybe this is confusing, but .hide() is a jQuery event.
	
	/*
	 * Fn: Quick Show/Hide
	 * Usage: <a class="showHide" rel="pair"></a> hides <div id="pair"></div>
	*/
	$("a.showHide").click(function() {
		$("#" + $(this).attr('rel')).toggle('fast');
		return false;
	});
	
	/*
	 * Fn: Submit Parent Form of state select box (form id independent)
	 * Usage: see /assets/ssi/form-stateselect.inc
	*/
	$("select#kitNumber").change(function() {
		if((this).value != "") {
			$(this).parents('form:first').submit();
		}
	});
	$("input#buttonStart").click(function() {
		if($("select#kitNumber").val() == "") {
			alert("Please select a state first.");
			kitflag = "set";
			return false;
		}
	});
	
	/*
	 * Fn: Submit Form of state select box on Law Library pages
	 * Usage: see /assets/ssi/law-lib-content-footer.inc
	*/
	$("form#divorcePackage select").change(function() {
		if((this).value != "") {
			$(this).parents('form:first').submit();
		}
	});
	$("form#divorcePackage input").click(function() {
		if($("form#divorcePackage select").val() == "") {
			return false;
		}
	});
	
	
	/*
	 * Fn: Smooth Scrolling
	 * Usage: N/A
	*/
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
	
	
});