// Background Postion Fix

// NORMAL RULES

$(document).ready(function() {

	// GET URL VARS
	
	function getUrlVars()
	{
		var urlvars = [], urlhash;
		var urlhashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
		for(var i = 0; i < urlhashes.length; i++)
		{
			urlhash = urlhashes[i].split('=');
			urlvars.push(urlhash[0]);
			urlvars[urlhash[0]] = urlhash[1];
		}
	
		return urlvars;
	}

	url_hash = getUrlVars(); 	
	
	// EYE CANDY RULES
	
	$(".eye_candy_container").each(function(){
		eye_candy_name = $(this).attr("id");
		eye_candy_container_bg_str = 'transparent url("/images/eye_candy/interior/'+eye_candy_name+'_repeat.jpg") center top';
		eye_candy_bg_str = 'transparent url("/images/eye_candy/home/'+eye_candy_name+'.jpg") center top no-repeat';
		$(this).css('background',eye_candy_container_bg_str).find('div').css('background',eye_candy_bg_str);
	});
	
	$('#eye_candy_container_2').cycle({ 
		timeout: 8000,
		speed: 500
	});
	
	// NAVIGATION RULES
	$("#navigation li a").hover(
		function () {
			$("#navigation li a").css("background-position","0px 0px");
			$(this).css("background-position","0px -180px");
			$('.dropdown').hide();
			dd_name = $(this).attr("id");
			dd_name = dd_name.replace("_link","_dropdown");
			dd_selector = "div#"+dd_name;
			$(dd_selector).show();
		}, 
		function () {}
	);

	$("#navigation_container").hover(
		function (){
		}, function (){
			$("#navigation li a").css("background-position","0px 0px");
			$('.dropdown').hide();
		}
	);
							 
	// 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").append('<a class="submit_button" hrf="#"><span>Submit Button</span></a>');
	
			if(typeof document.body.style.maxHeight === "undefined") {
				var is_ie6 = true;
				DD_belatedPNG.fix('.submit_button');
			}

			$(".submit_button").fadeIn('slow');
		}
		$("a.submit_button").live('click', function() {
			$("#request_info_form").submit();
		});	
		count--;
		}, 1000);
	}

	if($("body").hasClass("careers")){
		$(".job_item").each(function(){
			orig_job_description_height = $(this).find(".job_description").height();
			$(this).find(".job_description").data("orig_job_description_height", orig_job_description_height);
			$(this).find(".job_description").animate({"height" : 0}, 0);
		});
		
		// HOME PAGE LINK OPEN BIT
		
		current_job_selector = "#"+url_hash['item_name'];
		if(current_job_selector != "#undefined"){
		open_item_height = $(current_job_selector).next('.job_item').find(".job_description").data("orig_job_description_height");
		$(current_job_selector).next('.job_item').find(".job_description").css("height",open_item_height);		
		$(current_job_selector).next('.job_item').find(".job_title").addClass("active");		
		}
		
		$(".job_title").click(function(){
			if(!$(this).hasClass('active')){
				orig_job_description_height = $(this).next(".job_description").data("orig_job_description_height");
				$(this).next(".job_description").animate({"height" : orig_job_description_height}, 600);
				$(this).css("background-position","0px -120px");
				$(this).addClass("active");
			}
			else{
				$(this).next(".job_description").animate({"height" : 0}, 600);
				$(this).css("background-position","0px 0px");
				$(this).removeClass("active");
			}
			
		});
		
		$(".job_title").hover(
			function (){
				if ($(this).hasClass("active")) {	}
				else {
					$(this).css("background-position","0px -60px");			
				}
			},
			function (){
				if ($(this).hasClass("active")) {}
				else {
					$(this).css("background-position","0px 0px");			
				}
			}
		);
		$(".close_this_postion").click(function () {
			$(this).parents(".job_description").animate({"height" : 0}, 600);
			$(this).parents(".job_item").find(".job_title").removeClass("active");
			$(this).parents(".job_item").find(".job_title").css("background-position","0px 0px");
		});
		
		function goToByScroll(id){
     		$('html,body').animate({scrollTop: $("#"+id).offset().top},600);
		}

		goToByScroll(url_hash['item_name']);
	}

	
	// CONTENT ACCORDIAN

	$("#accordion div").hide()
	$("#accordion h3").live("click",function() {
		$(this).toggleClass("on");
			if($(this).hasClass("on")) {
				$(this).next().slideDown();
			} 
			else {
				$(this).next().slideUp();
			}
	});

});
