// NORMAL RULES

$(document).ready(function() {
$('#navigation_container').prepend('<img src="/images/misc_elements/hover_circle.png" id="nav_hover" />');
function home_cartoon() {
	$("#header img").animate({
		top: '0px', 
		width: '234px'
		},{
		duration: 1900,
		specialEasing: {
		width: 'linear',
		top: 'easeOutBounce'
		},
		complete: function() {
			$("#cartoon_mask").css("top","0px");
			$("#cartoon").animate({top: "18px"},300,'linear');		
		}
	});
}

if(typeof document.body.style.maxHeight === "undefined") {
	var is_ie6 = true;
	$("#container_4").css({display: 'block'});
	$("body").css({background: '#031521'});
}
else if ($("#container_4").hasClass("home_set")){
	if (is_ie6 != true){
		$("#container_4").css({display: 'block'});
		$("body").css({background: '#031521'});
		$("#container").append('<a href="/"><div id="cartoon_mask">&nbsp;</div><img id="cartoon" src="/images/misc_elements/tooth_cartoon.png"></a>');
		home_cartoon();
	}
}
else{
	if ($("#container_4").hasClass("home")){
		$("body").prepend('<div id="white_overlay"><div id="overlay_content"><img id="white_overlay_img" src="/images/misc_elements/white_overlay.png"/><img id="white_overlay_icon" src="/images/misc_elements/overlay_icon.png"/><img id="white_overlay_text" src="/images/misc_elements/overlay_text.gif"/></div></div>');
		$("#container").append('<a href="/"><div id="cartoon_mask">&nbsp;</div><img id="cartoon" src="/images/misc_elements/tooth_cartoon.png"></a>');
		$("#header img").css({top: '-600px', width: '50px'});
		$("#white_overlay_img").animate({top: '0px'},800, function () {
			$("#white_overlay_icon").animate({top: '50px'},800, function () {
			$("#white_overlay_text").fadeIn(1000);	
			$("#container_4").css({display: 'block'});
			$("body").css({background: '#031521'});
			$("#white_overlay_text").delay(1000).fadeOut(200, function(){
				$("#white_overlay_icon").animate({top: '-1000px', right: '-420px'},1200);
				$("#white_overlay_img").animate({top: '-1500px', left:'-420px'},1600);
				$("#white_overlay").animate({top: '-4000px'},1500);
				home_cartoon();
			});
			});
		});
	}	
}	
	$('#navigation_container').hoverIntent(function (){}, 
		function(){
			$("#navigation_container").removeClass("nav_active");
			$("#nav_hover").stop().animate({top:"180"}, 200, function (){
				$(this).css({zIndex:10});			
				$(this).animate({top:"-50"}, 600);
			});
		}
	);
	
	
	$("#navigation li a").click(function(){
		this_id = $(this).attr("id");
		if(this_id == "about_link" || this_id == "our_office_link" || this_id == "patient_information_link" || this_id == "press_link" || this_id == "faqs_link" ){
		return false
		}
	});
	
	$("#navigation li a").hoverIntent(function(){
		this_id = $(this).attr("id");
		if(this_id == "about_link"){
			left_hover_val = "250px";
			top_hover_val = "120";
		}
		if(this_id == "our_office_link"){
			left_hover_val = "370px";
			top_hover_val = "125px";
		}
		if(this_id == "patient_information_link"){
			left_hover_val = "520px";
			top_hover_val = "120px";
		}
		if(this_id == "press_link"){
			left_hover_val = "695px";
			top_hover_val = "110px";
		}
		if(this_id == "faqs_link"){
			left_hover_val = "815px";
			top_hover_val = "100px";
		}
		if(this_id == "contact_link"){
			left_hover_val = "915px";
			top_hover_val = "95px";
		}
		if(	!$("#navigation_container").hasClass("nav_active")){
			$("#nav_hover").css({left:left_hover_val});		
			$("#nav_hover").stop().animate({top:180},300, function(){														 
				$("#nav_hover").css({zIndex: 220});			
			}).animate({left:left_hover_val, top:top_hover_val}, 800, "easeOutBounce");
			$("#navigation_container").addClass("nav_active");
			}else{
			$("#nav_hover").stop().animate({left:left_hover_val, top:top_hover_val}, 800, "easeOutBounce");
			}
			dd_name = $(this).attr("id");
			dd_name = dd_name.replace("_link","_dd");
			dd_selector = "ul#"+dd_name;
			$('.drop_down').not(dd_selector).hide(5, function(){
				$(dd_selector).show(500); 
			});
		
		}, function (){});
	
	
		$("#navigation_container").hover(
			function (){},
			function (){
				$('.drop_down').hide(500);
			}
		);

		// IMAGE TAG REPLACEMENT FOR ROUDNING CORNERS
		
		function img_p_replace (selector, width_override, height_override){
			selector_name = '.'+selector;
			$(selector_name).each(function() {
				if(width_override > 1){
					item_width =  width_override;
				}
				else {
					item_width = $(this).width(); 
				}
				if(height_override > 1){
					item_height = height_override;
				}
				else {
					item_height = $(this).height(); 
				}
				item_src= $(this).attr('src');
				background_image_str = 'url("'+item_src+'") center center';
				item_class= selector+'_container'; 
				$(this).wrap('<p/>');
				$(this).parent().css({width:item_width, height:item_height, background: background_image_str, overflow:"hidden"}).addClass(item_class);
				$(this).hide();
			});
		}
		
  		img_p_replace("staff_photo_thumbs", 0, 146);
  		img_p_replace("staff_photo", 0, 0);		
  		img_p_replace("gallery_image", 200, 200);		
		
	// FORM RULES 
	
	/*
	$(".footer_buttons").hover(
		function(){
			$(this).css('background-position','0px 0px');
		},
		function(){
			$(this).css('background-position','-100px 0px');
		}
	);
	*/
	
	// GENERAL FORM RULES							 	
	if ($("#request_info_form").hasClass("body_form") || $("#resume_submittal_form").hasClass("body_form")){
		var count = 10;
		countdown = setInterval(function(){
		$("#timer").html("Please wait " + count + " seconds before you submit!");
		if (count == 0) {
			$('#timer').remove();
			$("#submit_container").html('<a href="#" class="submit_button "><span>Submit</span></a>');
			$(".submit_button").fadeIn('slow');
		}
		count--;
		}, 1000);
		$("a.submit_button").live('click', function() {
				$(this).parents("form").submit();
		});
	}
		
		
	// TABBED FIRST VISIT RULES
	$("#for_your_baby").css('background-color', '#705ebd');
	$("#for_your_baby").css('color', '#fff');
	$("#for_your_baby").click(function(){
		$(this).css('background-color', '#705ebd');
		$(this).css('color', '#fff');
		$("#for_your_child_older_than_24_months").css('background-color', '#fff');
		$("#for_your_child_older_than_24_months").css('color', '#705ebd');								   
		$("#for_your_child_older_than_24_months_link").fadeOut(500, function() {
			$("#for_your_baby_link").fadeIn(500);
		});
			return false;
	});
	
	$("#for_your_child_older_than_24_months").click(function(){
		$(this).css('background-color', '#705ebd');
		$(this).css('color', '#fff');
		$("#for_your_baby").css('background-color', '#fff');
		$("#for_your_baby").css('color', '#705ebd');	
		$("#for_your_baby_link").fadeOut(500, function () {
			$("#for_your_child_older_than_24_months_link").fadeIn(500);
		});
			return false;
	});
		
});

