// NORMAL RULES

$(document).ready(function() {
	
// CONSOLE UNDEFINED  FIX

	if(typeof console === "undefined") {
		console = { log: function() { } };
	}


	
// NAVIGATION
	
	$("ul#navigation li a span").fadeOut(1);
	$("h2#navigation_title").css({"top": "-50px"}, "fast");
	$("#navigation li a").hover(function () {
		$("#navigation li a span").stop(false, true);										  
		$(this).children('span').fadeIn('slow');
	},
	function () {
		$("#navigation li a span").stop(false, true);		
		$(this).children('span').fadeOut('slow');
	});
	
	$("#navigation").hover(function () {
		$("h2#navigation_title").animate({"top": "0px"}, "fast");
	},
	function () {
		$("h2#navigation_title").animate({"top": "-50px"}, "fast");
	});
	
	$("a#about_link").mouseover(function(){
		$("h2#navigation_title").stop().animate({"left": "370px"}, "fast");
	});

	$("a#industries_link").mouseover(function(){	
		$("h2#navigation_title").stop().animate({"left": "508px"}, "fast");
	});
	
	$("a#solutions_link").mouseover(function(){
		$("h2#navigation_title").stop().animate({"left": "665px"}, "fast");
	});
	
	$("a#careers_link").mouseover(function(){
		$("h2#navigation_title").stop().animate({"left": "808px"}, "fast");
	});
	
	$("a#contact_link").mouseover(function(){
		$("h2#navigation_title").stop().animate({"left": "943px"}, "fast");
	});

// EYE CANDY
/*
	function eye_candy_loop () {
		$("#eye_candy ul li:first").clone().appendTo("#eye_candy ul");
		$("#eye_candy ul").css("width", "4900px");
		$("#eye_candy ul").delay(6000).animate({"left": "-=980px"}, 500).delay(6000).animate({"left": "-=980px"}, 500).delay(6000).animate({"left": "-=980px"}, "fast").delay(6000).animate({"left": "-=980px"},500, function () {
			$("#eye_candy ul").css("left", "0px");
		});
	}
	eye_candy_loop ();
	setInterval(eye_candy_loop, 24010);
*/


	$("#gmr_digital a, #gmr_venture a, #gmr_strategies a").hover(function(){
		$("#gmr_digital a, #gmr_venture a, #gmr_strategies a").stop(false, true);
		$(this).animate({backgroundPosition: '-250px bottom'})
	},
	function() {
		$(this).animate({backgroundPosition: '0px bottom'})
	});

	$("#social_networking li a").hover(function () {	
		$("#social_networking li a").stop(false, true);
		$("#social_networking li a").not(this).animate({opacity: .3}, "slow");
		$(this).stop().animate({opacity: 1}, "slow");
	},
	function () {});

	$("#social_networking").mouseleave(function () {
		$("#social_networking li a").animate({opacity: 1}, "slow");
	});

// FORM RULES
	
	// FORM CHECK 
	
	if($("#entire_whole_site_container").hasClass("form_page") || $("#body_text").hasClass("newsletter_signup")){

		
	// BUTTON GENERATOR
	if(typeof document.body.style.maxHeight === "undefined") {
		var is_ie6 = true;
		$.getScript('/scripts/validate_rules_ie6.js');
	}
	else {
		var is_ie6 = false;
		$.getScript('/scripts/validate_rules.js');
	}

	
		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();
				$("#sumbmit_container").html('<input class="submit_button" type="image" src="/images/misc_elements/submit_btn.gif" name="submit" />');
				$(".submit_button").fadeIn('slow');
			}
			count--;
			}, 1000);
		}
		
	// FORM CHECK END
	
	}


	// CONTENT ACCORDIAN

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


// 2 COLUMN ULS
	if(typeof document.body.style.maxHeight === "undefined") {
	}
	else {
	$(".2_column").prev("h3").wrap('<div class="column" />');
	$('.column').each(function (){
		$(this).append($(this).next("ul"));
	});
	$('.column:odd').addClass("even");
	$('.column:last').addClass("last");
	if($('.column:last').hasClass("even")){
		$('.column:last').removeClass("last");
	}
	$('<a class="back_to_top"><span>Back to Top</span></a>').insertAfter('.even, .last');
	}
	
	
// LANDING PAGE BIT

	
	if ($("#body_text").hasClass("information")){
		console.log("oh yeah");
	$(".subject_wrapper").hover(
		function(){
			console.log("working");
			$(this).find("h3").css('background-position','0px -40px');
		}, 
		function() {
			$(this).find("h3").css('background-position','0px 0px');
		}
	);
	
		$(".subject_wrapper").each(function() {
			if ($(this).hasClass("closed")){
				shrink_height = "40px";
			}
			else {
				shrink_height = "112px";
			}
			subject_wrapper_height = $(this).height();
			if ($(this).hasClass("open")){
				if (subject_wrapper_height == 112) {
					$(this).parent("div").find(".view_more_button").remove();
				}
			}
			$(this).data("subject_wrapper_height",subject_wrapper_height);
			$(this).css("height",shrink_height);
		});
		$(".view_more_button").toggle(
			function (){
				if ($(this).parent("div").hasClass("closed")){
					shrink_height = "40px";
				}
				else {
					shrink_height = "112px";
				}
				full_height = $(this).parent("div").data("subject_wrapper_height");
				$(this).parent("div").animate({"height":full_height},500);
				$(this).empty();
				$(this).html("&#8855; Collapse");
				return false;
			},
			function (){
				$(this).parent("div").animate({"height":shrink_height},500);
				$(this).empty();
				$(this).html("&#187; Read More");
				return false;
			}
		);
	}

});
