$(function() {
	$("#gonav").click(function() {
		var slideFunc = function() {
			var slideId = '#nav_reveal';
			if( $(slideId).length ) {
				$(".reveal_class", "#reveal").hide();
				$(slideId).show();
				$("#reveal").toggle("blind", { direction: "vertical" }, 500, function() {
					setTimeout(function() {
									if( $("#reveal").css("display") == "block" ) {
										$("input[@name='query']").focus();
									}
								}, 250
					);
				} );
			}
		}
		if( $("#reveal").css("display") == "block" ) {
			var slide = $(".reveal_class").filter(function() {
				return $(this).css("display") == "block";
			} );
			$("#reveal").toggle("blind", { direction: "vertical" }, 500);
			if( slide.attr('id') != 'nav_reveal' ) {
				setTimeout(slideFunc, 500);
			}
		} else {
			slideFunc();
		}
	} );
	
	
	$.ajaxSetup( {
		error: function(xmlhttp, msg, e) {
			console.log("Ajax Error: " + msg);
			console.log("Ajax Exception: " + e.message);
			switch( xmlhttp.status ) {
				case 403:
					window.location = window.location.pathname;
					break;
				case 404:
					window.location = "/Error/NotFound";
					break;
				case 500:
					window.location = "/Error/Server";
					break;
				default:
					//console.log( xmlhttp.responseText );
					alert("An error occurred while processing your request.\nPlease try again in a few moments.\n\nIf the error persists, please contact customer service for help.");
			}
		},
		complete: function(xmlhttp, result) {
			if( result == "success" ) {
				eval("var response = " + xmlhttp.responseText);
				if( response.redirect ) {
					window.location = response.redirect;
				}
			}
		}
	} );
} );
