
jQuery(function(){
	
	$("#nav_table").load("../templates/nav_table.html");
	
	if ( typeof ( $("#listing").accordion) == 'function' ) {
			$("#listing").accordion( {
		autoHeight: false
	});
	}


	$('#listing p').click( function(){
		$(document.body).fadeOut('slow');
		document.location.href = $(this).attr('data');
	});

	$("#footer-here").hide().load('templates/footer.html').fadeIn("slow").mouseover(function(){
				
	}).mouseout( function(){
	
	});
	
	
	$("form input").blur( function(){
		
		if ( $(this).val() == ''){
			$(this).attr('style', "border:2px solid red;");
		}

	});
	
	$("form input[type='button']").click( function(_evt){
		
		if (formInError() ){
			_evt.preventDefault();
			return false;
		}			
		else {
			$("form").submit();
		}
		
	} );
	
	if ( $("#dyn-title").length == 1){
		
		var from = document.location.href.match( /from=[\w_]*/ )
		
		if (from.length ==1)
			from = from[0].split('=')[1];
		
		if ( from=='blocked')		
			$("#dyn-title").html('Contact Fluid H2O  to clear your drain');
		else if ( from == 'hot_water')
			$("#dyn-title").html('Contact Fluid H2O about our hot water services');
		else if ( from == 'reline')
			$("#dyn-title").html('Contact Fluid H2O about Pipe Relining');
	
	}
	
	if (typeof(preloadImages) == 'function')
		preloadImages();

});

function reload(_url){
	document.location.href = _url ;
}

function formInError(){
	
	var error = false;
	
	$("form input").each( function(_index, _item ){
	
		if ( $(_item).val()==""){
			$(this).addClass('form-error');
			error = true;
		}
		else
			$(this).removeClass('form-error');		
	});
	
	return error;

}
