// INTERFACE RULES

// RESIZE WINDOW FUNCTIONS

function resizeWindow() {
	body_height = $(window).height();
	body_width = $("body").width();
	$("#eye_candy img").css({"height": body_height, "width": "auto"});
	eye_candy_img_width = $("#eye_candy img").width();
	if (body_width > eye_candy_img_width){
	$("#eye_candy img").css({"height": "auto", "width": body_width});
	}
	control_pos = ((body_width - 1160)/2)+"px"; 
	$("#panel_control_left").css("left",control_pos);
	$("#panel_control_right").css("right",control_pos);
	subnav_position(body_height);
}	 


// SUB NAVIGATION PADDING AND CANDIDATE PREP BUTTON POSITION ADJUSTMENT

function subnav_position (body_height) {
	if (!$("body").hasClass('home')){
		if (body_height < 800){
			body_difference = (800 - body_height);
			if (body_difference > 365){
				body_difference = 365;
			}
			sub_nav_offset = (385 - body_difference) + "px";
			
			prep_guide_offset = (260 - body_difference)	;
			
			if(prep_guide_offset < 145) {
				prep_guide_offset = 145;
			}
			
			prep_guide_difference = (prep_guide_offset) + "px";
			
			$("#sub_navigation").css({'padding-top': sub_nav_offset});
			$("#candidate_prep_ad").css({'top': prep_guide_difference});
		}
		else {
			$("#sub_navigation").css({'padding-top': '385px'});
			$("#candidate_prep_ad").css({'top': '260px'});
		}
	}
}


// RESIZE FOOTER IF VIEWPOINT IS LARGER THAN SITE HEIGHT

function resizeFooter() {
	body_height = $(window).height();
	container_height = $("#container").height();
	footer_gap = body_height - container_height;
	
	body_width = $("body").width();
	if (footer_gap <= 140){
		footer_gap = 140		 
	}
	$("#footer_container img, #footer_container").css({"height": footer_gap});
	eye_candy_img_width = $("#eye_candy img").width();
	if (body_width > eye_candy_img_width){
		if (body_width <= 1000){
			body_width = 1000;
		}
		$("#footer_container img, #footer_container").css({"height": "140", "width": body_width});
	}
}	 

$(window).bind("resize", resizeWindow);
$(window).bind("resize", resizeFooter);
$(window).load(function() {
	resizeWindow();						
	resizeFooter();	
	$("#eye_candy img").fadeIn(1200);
	$("#panel_control_left, #panel_control_right").fadeIn(1200);
});

$(document).ready(function() {

	// NAVIGATION 
	
	$("#navigation li").each(function(){
		nav_li_this = $(this);
		nav_li_this_a = nav_li_this.find("a");
		nav_li_this_a.addClass('nav_no_bg');
		nav_li_this.append('<span class="nav_preface">Link: </span>');
	});
	
	$("ul#navigation").data({"animating": 0, "this_left_position":"unset", "this_top_position":"unset"});
	$("#navigation").prepend('<img src="/images/navigation/nav_mag_glass.png" id="nav_hover" />');	
	

	$("#navigation li a").hover(
		function(){
			
			// DEFINE THIS
			nav_this = $(this);

			// ANNIMATE TEXT
			nav_this.find("strong").stop(true,true).addClass("active_nav", 300);
			nav_this.find("em").stop(true,true).addClass("active_nav", 300);
			
			//FADE
			nav_this.parent("li").find(".nav_preface").stop(true, true).fadeIn(600);
			
			// SLIDER 
			old_left_position = $("#navigation").data("this_left_position");
			old_top_position = $("#navigation").data("this_top_position");
			this_position = $(this).parent("li").position();
			this_width = $(this).width();
			this_left_position = this_position.left + ((this_width - 142) / 2);	
			this_top_position = this_position.top;
			if (this_top_position == "0"){
				this_top_position = 10;
			}
			hover_top = this_top_position+90;
			if ($("#navigation").data("this_left_position") == "unset"){
				$("#nav_hover").css({"top":hover_top,"left":this_left_position}).stop(true, true).fadeIn(800);
			}
			else {
				$("#nav_hover").css({"top":hover_top}).stop(true, true).show(100).animate({"left":this_left_position}, 500);
			}
			$("#navigation").data({"this_left_position":this_left_position, "this_top_position":this_top_position});
			
		},
		function(){
			// DEFINE THIS
			nav_this = $(this);	

			// ANNIMATE TEXT
			nav_this.find("strong").stop(true,true).removeClass("active_nav", 300);
			nav_this.find("em").stop(true,true).removeClass("active_nav", 300);
							
			// FADE
			nav_this.parent("li").find(".nav_preface").stop(true, true).fadeOut(400);		
			
			// SLIDER
			$("#nav_hover").stop(true, true);		
		}
	);
	
	$('#navigation').hover(
		function(){},
		function(){
			$("#nav_hover").css("display", "none");	
		}
	),
	
	$("#navigation").mouseleave(function(){
		$("#nav_hover").stop(true, true).fadeOut(100);		
		$("#navigation").data({"this_left_position":"unset", "this_top_position":"unset"});
	});	
	
	if($("body").hasClass("home")){
		$.getScript('/scripts/sticky_slider.js');
	}
	else{
		
		$("#sub_navigation li a").mouseenter(
			function(){
				subnavthis = $(this);
				$(this).stop(true, true).animate({"color":"#0088a0"},250).fadeTo(300, 1);
				$("#sub_navigation li a").not(subnavthis).stop(true,true).fadeTo(500, .3).animate({"color":"#1a1a1b"},100);
			 }
		);
		
		$("#sub_navigation").mouseleave(function(){
			$("#sub_navigation li a").stop(true,true).fadeTo(800, 1).animate({"color":"#1a1a1b"},100);
		});
		
	}


// MAP REGIONAL HOVER FUNCTIONALITY

$("#pacific").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -2480px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#east_central").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -620px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#west_central").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -310px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#south_east").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -1860px");		
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#north_east").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -1550px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#south_west").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -2170px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#eastern_canada").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -1240px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);

$("#western_canada").hover(
	function(){
		$("#career_map_container").css("backgroundPosition", "0px -930px");
	},
	function(){
		$("#career_map_container").css("backgroundPosition", "0px 0px");
	}
);


/* GLOBAL MAP */

$("#north_america").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -1550px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


$("#south_america").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -1860px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


$("#africa").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -310px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


$("#europe").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -620px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


$("#asia").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -930px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


$("#australia").hover(
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px -1240px");
	},
	function(){
		$("#global_career_map_container").css("backgroundPosition", "0px 0px");
	}
);


	
$(".toggle_container").css('display', 'none');
$("h4.trigger").click(function(){
	$(this).toggleClass("active").next().slideToggle("slow");
	$('h4.trigger').not(this).next('div').slideUp("slow");
	$('h4.trigger').not(this).removeClass("active");
	$('html, body').animate({scrollTop: 210}, 'slow');
});


	// GENERAL 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;
		});
	}
});
