$(document).ready(resizeWindow);
$(window).bind("resize", resizeWindow);
function resizeWindow() {
	var body_width = $('body').width()
	$("div#eye_candy_container").css({'width' : body_width });
	
var twitter_left =  $("body").width()/2-500; 
$("#twitter").css("left", twitter_left);

}	 

// NORMAL RULES

$(document).ready(function() {
	
	if($("#container_8").hasClass("home")){
			$("#header").append('<img class="click_to_learn_more the_firm_tt" src="/images/misc_elements/click_to_learn_more.png" /><img class="click_to_learn_more client_resources_tt" src="/images/misc_elements/click_to_learn_more.png" /><img class="click_to_learn_more candidates_tt" src="/images/misc_elements/click_to_learn_more.png" />');
	}
	
	// NAVIGATION RULES
	
	speedOut = 150;
	speedIn = 900;
	directionOut = "down";
	directionIn = "down";
	easingOut = "swing";
	easingIn = "swing";
	waitOut = 100;
	waitIn = 450;

	$("#navigation").data("current_nav_id", "the_firm");
	
	function home_content_slide (primary_content_name, secondary_content_name, speedOut, speedIn, directionOut, directionIn, easingOut, easingIn, waitOut, waitIn){
		
		/* CACULATED WAIT VARS */ 
		
		primary_waitOut = waitOut * 2;
		tertiary_waitIn = waitIn * 2;
		
		/* SHOW and HIDE FUNCTIONS  */
		
		function primary_show() {$("#primary_content_block"+secondary_content_name).show("slide", { direction: directionIn, easing: easingIn }, speedIn);}
		function secondary_show() {$("#secondary_content_block"+secondary_content_name).animate({"opacity":"1"},waitIn).show("slide", { direction: directionIn, easing: easingIn }, speedIn);}
		function tertiary_show() {$("#tertiary_content_block"+secondary_content_name).animate({"opacity":"1"},tertiary_waitIn).show("slide", { direction: directionIn, easing: easingIn }, speedIn, function(){
			$("#navigation").removeClass("sliding");
			$("#navigation").removeClass("was_sliding");		
		});}
		
		function tertiary_hide(){$("#tertiary_content_block"+primary_content_name).hide("slide", { direction: directionOut,  easing: easingOut}, speedOut);}
		function secondary_hide(){$("#secondary_content_block"+primary_content_name).animate({"opacity":"1"},waitOut).hide("slide", { direction: directionOut,  easing: easingOut}, speedOut);}
		function primary_hide(){$("#primary_content_block"+primary_content_name).animate({"opacity":"1"},primary_waitOut).hide("slide", { direction: directionOut,  easing: easingOut }, 500, function(){		
			$("#eye_candy"+primary_content_name).css("z-index","1");
			$("#eye_candy"+secondary_content_name).css("z-index","3").show("clip", 800, function(){
				$("#eye_candy"+primary_content_name).css("display","none");
				$("#tagline"+secondary_content_name).show("clip", 700);
				primary_show();
				secondary_show();
				tertiary_show();
			});				
		});}
		
		/* THE MEAT */
	
		if(	$("#navigation").hasClass("sliding")){
			$("#navigation").addClass("was_sliding");
			$(".the_firm").stop(true,true).hide();
			$(".candidates").stop(true,true).hide();
			$(".client_resources").stop(true,true).hide();
		}
		$("#navigation").addClass("sliding");
		
		$("#eye_candy div").stop(false,true);
		if($("#navigation").hasClass("was_sliding")){
			$("#eye_candy"+primary_content_name).css("z-index","1");
			$("#eye_candy"+secondary_content_name).css("z-index","3").show("clip", 800, function(){
				$("#eye_candy"+primary_content_name).css("display","none");
				$("#tagline"+secondary_content_name).show("clip", 700);
				primary_show();
				secondary_show();
				tertiary_show();
			});				
		}
		else{
			$("#tagline"+primary_content_name).hide("slide", { direction: "left",  easing: easingOut}, 500);
			tertiary_hide();
			secondary_hide();			
			primary_hide();
		}
		
	}
	
	function navigation_animate (left_pos){
		$("#navigation").addClass("navigation_animating");
		nav_css_str = left_pos+"px -40px";
		nav_animatate_str = left_pos+"px 0px";
		if (!$("#navigation").hasClass("set")){
		$("#navigation").css({backgroundPosition: nav_css_str});
		}
		$("#navigation").stop(false,true).animate({backgroundPosition: nav_animatate_str});
		$("#navigation").addClass("set")
		$("#navigation").removeClass("navigation_animating");
	}
	
	$("#navigation a").hoverIntent(function(){
		nav_id = $(this).attr("id");
		if ($("#container_8").hasClass("home")){
			if($("#navigation").data("current_nav_id") !== nav_id.replace("_link", "")){
				old_nav_id = $("#navigation").data("current_nav_id"); 
				$("#navigation").data("current_nav_id", nav_id.replace("_link", ""));
				primary_content_name = " ."+(old_nav_id.replace("_link", ""));
				secondary_content_name = " ."+(nav_id.replace("_link", ""));
				home_content_slide(primary_content_name, secondary_content_name, speedOut, speedIn, directionOut, directionIn, easingOut, easingIn, waitOut, waitIn);
			}
		}
		if (nav_id == "the_firm_link"){
			navigation_animate("-90");
		}
		if (nav_id == "client_resources_link"){
			navigation_animate("290");
		}
		if (nav_id == "candidates_link"){
			navigation_animate("670");
		}
	
		tt_class = '.'+(nav_id.replace("_link", "_tt"))
		$(tt_class).show("slide", { direction: "down" }, 200)
		
		$("#navigation li a").css("background-position","0px 0px");
		$(this).css("background-position","0px -40px");
		if (!$("#container_8").hasClass("home")){
			$('.drop_down').hide();
			dd_name = nav_id;
			dd_selector = "div#"+(nav_id.replace("_link","_dd"));
			$(dd_selector).show();
			$("#navigation a").removeClass("active");
			$(this).addClass("active");
		}
	}, function(){
		tt_class = '.'+(nav_id.replace("_link", "_tt"))
		$(tt_class).hide("slide", { direction: "down" }, 200)	
	});
	
	$("#navigation_container").hover(
		function (){
		}, function (){
		$("#navigation").removeClass("set");
			if($("#the_firm_link").hasClass("active")){
				$("#navigation").animate({backgroundPosition: "-90px -40px"});
			}
			if($("#client_resources_link").hasClass("active")){
				$("#navigation").animate({backgroundPosition: "290px -40px"});
			}
			if($("#candidates_link").hasClass("active")){
				$("#navigation").animate({backgroundPosition: "670px -40px"});
			}
			if (!$("#container_8").hasClass("home")){
				$("#navigation li a").css("background-position","0px 0px");
				$('.drop_down').hide();
			}
		}
	);
	
	// JOB BOARD HOVER FUNCTIONS
	$(".job_board_item_container a").hover(function(){
			$(this).parents(".job_board_item_container").animate({backgroundPosition: '0px -50px'});
		},function(){
			$(this).parents(".job_board_item_container").animate({backgroundPosition: '0px 0px'});	
	});
		
	// INDUSTRY SELECTION HOVER FUNCTIONALITY
	
	$("#industry_selection li a").hover( function(){
			$(this).find("img.industry_caption").show("slide", { direction: "down" }, 200);
		},function (){
			$(this).find("img.industry_caption").hide("slide", { direction: "down" }, 200);
	});
	
	// INTERIOR SUBNAVIGATION 
	
	subnav_height = $("#sub_navigation ul").height();
	if (subnav_height > 240){
		$("#container_2").addClass("container_2_3");
	}
		
		
	
	// DIV SHOW/HIDE TOGGLE
		
	$("#ask_dave").hide();
	$("h3.ask_dave_trigger").click(function(){
		$(this).toggleClass("active")
		$("#ask_dave").slideToggle("slow");
		return false;
	});
	
	
	$(".qu_answer").hide();
	$("h3.qu_question").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});	
		

	// RESUME SUBMITAL FORM RULES							 
	if ($("form").hasClass("body_form")){
		//$.getScript('/scripts/validate_rules.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;
		});
	}	
	
});
