(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

function selectSheriff(x) {
	for (var i=0; i<x; i++) {
		var a="div#county"+i;
		var y="div#image"+i;
		$(a).hide();$(y).hide();
	} // end for
	var b=$('#sheriffs').val();
	if (b.length > 0) { $('div#county'+b).toggle(); $('div#image'+b).toggle(); }
} // end function

function showAns(x) {
	for (var i=0; i<14; i++) {
		var a="div#answers"+i;
		$(a).hide();
	} // end for
	var a="div#answers"+x;
	$(a).toggle();
	var height = $(a).css("height");
	if (height == 0) height = "auto";
	$('div.answers').css("height",height);
	updateBkGnd();
} // end function

function updateBkGnd() {
	var height = $('div.main').height();
	if (height > 1000) $('div.main').css("background", "url(images/bkgndlg.jpg) center repeat-x");
	else $('div.main').css("background", "url(images/modonebkgnd.jpg) top center repeat-x");
}

$(document).ready( function() { 

	$("#submitBtn").click(function(){ 
		var error = "";
		$(".required:input[name!='']").each(function(i){	
			if ((this.value  == "") || ((this.checked == 0) && (this.type=='checkbox')))
				error += "Missing Information: " + this.name.substring(1) +"\n";
		});
		if (error.length > 0) {
			alert(error);
			return false;
		}	else { return true; }
	});
	
	$('DT').has('A').bind('click', function() {
		$var = $('DIV.faq DD').filter(':not(:hidden)').index();
		$('DIV.faq DD').slideUp();
		if ($var != $(this).next('DD').index()) $(this).next('DD').slideDown();
	});
	
	$.preLoadImages('images/home_f2.png','images/about_f2.png','images/service_f2.png','images/contact_f2.png','images/printcoupon.jpg', 'images/bkgndlg.jpg', 'images/modonebkgnd.jpg', '/images/line.png');
	updateBkGnd();
	
	$('#fla_soapdrop').flash(
			{ src: 'SoapDrops2.swf',
				width: 360,
				height:328,
				wmode: 'transparent'}, 
			{ expressInstall: true }
	);
	
	$('#fla_slideshow').flash(
			{ src: 'slideshow.swf',
				width: 450,
				height:450,
				wmode: 'transparent'}, 
			{ expressInstall: true }
	);
	
	$('#fla_counties').flash(
			{ src: 'counties.swf',
				width: 550,
				height:600,
				wmode: 'transparent'}, 
			{ expressInstall: true }
	);
	
	$("IMG[src$='png'], DIV.h_menu, DIV#images, DIV.titleBar").supersleight();
	
	$('.h_menu UL LI').find('A IMG').bind({
		mouseenter: function() { $(this).attr('src',this.src.replace(/\.png/,'_f2.png')); },
		mouseleave: function() { $(this).attr('src',this.src.replace(/_f2/,'')); }
	});
	
	$('.required').parent().prev('li:has("label")').prepend('<span class="hl">*</span>');

});