
	$(document).ready(function() {
	
	// Webkit padding is lame
	var isSafari = navigator.userAgent.indexOf("Safari") != -1;
	var isChrome = navigator.userAgent.indexOf("Chrome") != -1;
	var isIE7 = navigator.appVersion.indexOf("MSIE 7.") != -1;
	
	if (isSafari || isChrome) {
		$("#menu a").each(function(i,v) {
			if($(this).parent().parent().hasClass("dropDown")) {} else {
			
				$(this).css("padding", "5px 11.6px");
				
			}
		});
	} 
	
	if(isIE7) {
		$(function() {  
			var zIndexNumber = 1000;  
			$('div').each(function() { 
				if($(this).attr("id") != "featureContent") {
					$(this).css('zIndex', zIndexNumber);  
					zIndexNumber -= 10;  
				}
				if($(this).attr("id") == "errorMsg") {
					$(this).css('zIndex', "10000000000");  
				}
			});  
		});
	}	
	
	
	if(iPhone) {
	

	
	}
	
	function reportError(msg) {
	
		var errorDiv = $("#errorMsg");
		errorDiv.html(msg + '<div class="close">x</div>').slideDown();
	
	}
	
	function clearInvalid(obj) {
	
			$("#errorMsg ."+obj).slideUp();
			
			var ec = 0;
			$(".invalid").each(function(i,v) {					
				ec++;
			});
			
			if(ec == 0) {
				$("#errorMsg").slideUp();
			}

			
	}
	
	$(".invalid").live('keyup', function() {
		$(this).removeClass("invalid");
		clearInvalid($(this).attr("name"));
	});
	
	$(".close").live('click', function() {
	
		$("#errorMsg").slideUp();
	
	});
					
	
	// SubMenu Controls
	if(menuSelect == 1 || menuSelect == 3|| menuSelect == 5) {
	
		// This will allow us to go directly to a sub page
		// if requested, without the need to click the link

		if(subPage != "false") {
		
			var selectEQ = 0;
			
			// About Us
			if(subPage == 'about-our-practice') { selectEQ = 1; }
			if(subPage == 'our-facilities') { selectEQ = 2; }
			if(subPage == 'FAQ') { selectEQ = 3; }
			
			
			// Surgical Services
			if(subPage == 'pre-op-info') { selectEQ = 1; }
			if(subPage == 'post-op-info') { selectEQ = 2; }
			
			// Office / Appointment Info
			if(subPage == 'insurance') { selectEQ = 1; }
			if(subPage == 'billing') { selectEQ = 2; }
			if(subPage == 'patient-registration-form') { selectEQ = 3; }
			
				$(".subMenu .selected").removeClass("selected");
				$(".page").eq(selectEQ).show();
				$(".subMenu a").eq(selectEQ).addClass("selected");
		
		} else {
			$(".page").eq(0).show();
		}
		
		$(".subMenu a").each(function(i,v) {
			$(this).click(function() {
				$(".page").hide();
				$(".page").eq(i).fadeIn();
			});
		});
	
	
	}
	
	

	
	function dropOpen() {
		
		$(".dropDown", this).fadeIn();
			
	}
	
	function dropClose() {
	
		$(".dropDown").fadeOut();
	
	}
	
	var hoverConfig = {    
		 over: dropOpen,    
		 timeout: 100,  
		 out: dropClose 
	};

	$("#menu ul li").hoverIntent(hoverConfig);	
		$("#menu ul li").click(function() {
			dropOpen(this);
		});	
	
	
	
		$("#menu ul li").eq(menuSelect).addClass("selected");
			
			// provides the inner shadow on the menu items
			$("#menu .selected a:first").addClass("innerShadow"); 
			
			$("#menu ul li").hover(function() {
			
				$("a:first", this).addClass("innerShadow");

				
			}, function() {
				if($(this).hasClass("selected")) {} else {
					$("a:first", this).removeClass("innerShadow");
				}
				
			
			});
			

			
			
			// Set selected menu item on click
			$("#menu ul li").click(function() {
				
				if($(this).find("a:first").attr("href") != "javascript:void(0)") {
				
				$("#menu .selected a:first").removeClass("innerShadow");
				$("#menu .selected").removeClass("selected");
				
				$(this).addClass("selected");
				$("a:first", this).addClass("innerShadow");
				
				}
				
			});
			
			// Set selected menu item on click
			$(".subMenu ul li").click(function() {
				
				$(".subMenu .selected").removeClass("selected");
				
				$(this).addClass("selected");
				
			});
			
			
			// Drop Down Menus
			$(".dropDown a").hover(function() {
				$(this).append('<span class="raquo"> &raquo;</span>');
			}, function() {
				$(".raquo").remove();
			});
			
			
			
			// Search Submit Button Hover Animation
			$(".submit").hover(function() {
				$(this).attr("src", baseURL + "/assets/img/btnGo-hover.png");
			}, function() {
				$(this).attr("src", baseURL + "/assets/img/btnGo.png");
			});
			
			// ReadMore Hover Animation
			$(".readMore").hover(function() {
				$(this).attr("src", baseURL + "/assets/img/iconReadMore-hover.png");
			}, function() {
				$(this).attr("src", baseURL + "/assets/img/iconReadMore.png");
			});
					
			

			// Contact Form Submit //
			
			$("[name='phone']").mask("(999) 999-9999");
			
			
			$("#contactSubmit").click(function() {
				
				var FORM = $("#contactUs form");
				
				$("input, textarea", FORM).each(function(i,v) {
					if($(this).val() == $(this).attr("default")) {
						$(this).val("");
					}
					if($(this).val() == "") {
						$(this).addClass("invalid");
					}		
				});
				
				var invalidCnt = 0,
				    invalidString = "";
					
				$(".invalid").each(function(i,v) {
					invalidCnt++;
					invalidString = invalidString + '<div class="' + $(this).attr("name") +'">' + $(this).attr("default") + "</div>";
				});
				

				if(invalidCnt > 0) {
					
					reportError("<h1>The following fields must be filled in to submit the contact form:</h1><div class='hr'></div>" + invalidString);
					
					$("input, textarea", FORM).each(function(i,v) {
						if($(this).val() == "") {
							$(this).val($(this).attr("default"));
						}
					});
				
				} else {	
				
					$.post("/inc/inc-contact-submit.php", FORM.serialize(), function(data) {
					   
	
							$(".sendMessage h1").hide();
							$("#contactUs").hide();
							$("#contactThanks").fadeIn();

					   
					});
				
				}
				
			});
			
				
				
			// End Cybernautic Form Input Labeler //
			
			
			
			// Cybernautic Design Image Slider v1.0 //
			
			
				// Config
				
				var cndSlider = $("#cndSlider"), // DIV that contains slider Images
					delay = 10000; // Delay between automatic advancement
					cndCnt = 0, // Initialize Counter
					cndVisible = 0; // Default visible image (index)
					
					
					function onChange() {
						
					}
					
						
						function nextPic() {
						
								$("img", cndSlider).eq(cndVisible).hide(); // Hide current image before advancing
									
									// If we've reached the end, wrap back to the beginning
									if((cndVisible+1) == cndCnt) { var feq = 0; } else { var feq = (cndVisible+1); }
								
									$("img", cndSlider).eq(feq).fadeIn(); // Fade in the next image
									cndVisible = feq; // Set index of current visible image
									
						}	
						
						
						// Count Slider Images
						$("img", cndSlider).each(function(i,v) {
							
							cndCnt++;
						
							// Show default image
							if(i == cndVisible) {
								$(this).show();
							}
							
						});
						
						
						// Go to next image on click
						$("img", cndSlider).click(function() {
								
								if(cndCnt > 1) {
									nextPic();
								}
						
						});
						
						if(cndCnt > 1) {
							setInterval(nextPic, delay); // Set timer
						}
				

			// End Cybernautic Design Image Slider //
			
			
			
			// Cybernautic Form Input Labeler v1.0 //
			
			
			$(".inField").each(function(i,v) {
			
						
			var theInput = $(this).attr("default");  // Default search input text
			$(this).val(theInput);			
			
				// When search input is focused, clear default value
				$(this).focus(function() {
				
					if($(this).val() == theInput) {
					
						theInput = $(this).val();
						$(this).val("");
					
					}
				
				});
				
				// When search input is unfocused and blank, return to default state
				$(this).focusout(function() {
				
					if($(this).val() == "") {
						$(this).val(theInput);
					}
				
				});
			
			
			
			});
			
	
	});
