// NORMAL RULES

$(window).load(function() {

	
	//EYECANDY CAPTION
	
	$('div#body_text').delay(200).fadeIn('slow');
	$('li#first_showcase_item').delay(400).fadeIn('slow');
	$('li#second_showcase_item').delay(600).fadeIn('slow');
	$('li#third_showcase_item').delay(800).fadeIn('slow');
});



$(document).ready(function() {


	// NAVIGATION DROPDOWNS
	
	$('#navigation li a').hover(
	function() {
		if ($(this).hasClass('about')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '24px 0px'}, 'fast');
		}
		else if ($(this).hasClass('specialties')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '32px 0px'}, 'fast');
		}
		else if ($(this).hasClass('candidates')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '37px 0px'}, 'fast');
		}
		else if ($(this).hasClass('employers')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '34px 0px'}, 'fast');
		}
		else if ($(this).hasClass('careers')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '22px 0px'}, 'fast');
		}
		else if ($(this).hasClass('contact')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '23px 0px'}, 'fast');
		}
		$('#navigation li a').css({backgroundPosition: '0px 0px'});
		$(this).css({backgroundPosition: '0px -120px'});	
		$('.drop_down').stop(true, true).slideUp(200);
		dd_name = $(this).attr("id");
		dd_name = dd_name.replace("_link","_dd");
		dd_selector = "div#"+dd_name;
		$(dd_selector).stop().slideDown(400);
		$('.nested_dd').stop(true, true).fadeOut(200);
		$('a').removeClass('active');
	}, function() {
		if ($(this).hasClass('about')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '24px -40px'}, 'fast');
		}
		else if ($(this).hasClass('specialties')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '32px -40px'}, 'fast');
		}
		else if ($(this).hasClass('candidates')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '37px -40px'}, 'fast');
		}
		else if ($(this).hasClass('employers')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '34px -40px'}, 'fast');
		}
		else if ($(this).hasClass('careers')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '22px -40px'}, 'fast');
		}
		else if ($(this).hasClass('contact')){
			$(this).parent('li').stop(true, false).animate({backgroundPosition: '23px -40px'}, 'fast');
		}
		});	
	
	
	$('a#candidate_services_nested').hover(
		function() {
			$('.nested_dd').stop(true, true).fadeOut(200);
			$('div#candidate_services_nested_dd').stop().fadeIn(400);
			$('a').removeClass('active');
			$('a#candidate_services_nested').addClass('active');
		}, function(){}
	);	
	
	$("div#body_text").hover(
	function (){
		$('.nested_dd').stop(true, true).fadeOut(200);
			$('a').removeClass('active');
		}, function(){}
	);
	
	$("#navigation_container").hover(
	function (){
		}, function(){}
	);
	
	$("#navigation_container").hover(
		function (){
		$('.nested_dd').stop(true, true).fadeOut(200);
		$('a').removeClass('active');
		},
		function (){
			$('.nested_dd').stop(true, true).fadeOut(200);
			$('a').removeClass('active');
			$('.drop_down').stop(true, true).slideUp(200);
			$('#navigation li a').css({backgroundPosition: '0px 0px'});			
		}
	);

	$("a.clear_nested").hover(
	function (){
		$('.nested_dd').stop(true, true).fadeOut(200);
			$('a').removeClass('active');
		}, function(){}
	);
	
	// EYE CANDY FADE FUNCTION
	function eye_candy_fade() {
		if ($('div.eye_candy_container:last').hasClass('active_eye_candy')) {
			$('.active_eye_candy').fadeToggle("normal", "linear", function() {
			$(this).removeClass('active_eye_candy');
			$('.eye_candy_container:first').addClass('active_eye_candy');
			$('.eye_candy_container:first').fadeIn("normal", "linear");
		   });
		}
		else {
		$('.active_eye_candy').fadeToggle("normal", "linear", function() {
			$(this).removeClass('active_eye_candy');
			$(this).next('.eye_candy_container').addClass('active_eye_candy');
			$(this).next('.eye_candy_container').fadeIn("normal", "linear");
		   });
		}
	};
	
	
	$('.eye_candy_container:first').css('display', 'block').addClass('active_eye_candy');
	setInterval(eye_candy_fade, 5000);
	
	// GENERAL FORM RULES							 	
	
	if ($("#request_info_form").hasClass("body_form") || $("#resume_submittal_form").hasClass("body_form")){
		$.getScript('/scripts/validate_rules.js');
		$.getScript('/scripts/jquery_placify.js');
		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();
			return false;
		});
	}
});
