﻿// GLOBAL FUNCTIONS HERE
$(function () {
    $('html').removeClass('no-js');
});

var scriptsLibrary = {
	home: {
		init: function () {
			$('#home-carousel p.extra').hide();
			$('#home-carousel a').hover(function () {
				$(this).stop().animate({ 'top': '-75px' }, 250).css({ 'background': '#fff none', 'color': '#495259' });
				$(this).find("p.extra").stop(true, true).fadeIn(100);
			}, function () {
				$(this).stop().animate({ 'top': '0px' }, 250).css({ 'background': 'url(./images/home/background-carousel.png) repeat-y', 'color': '#fff' });
				$(this).find("p.extra").stop(true, true).fadeOut(100);
			});
			// select a random image on homepage
			var r = Math.ceil(Math.random() * 5);
			var lookfor = r;
			// loop through images until it finds one (some may be empty), if not found, default to 0
			while ($('#io_' + r).length == 0) {
				r--;
				if (r == 0)
					r = 5;
				if (lookfor == r) {
					r = 0;
					break;
				}
			}
			if (r != 0) {
				var src = $('#io_' + r).val();
				$('.hero-image').attr('src', src);
			}
		}
	},
	ourExpertise: {
		init: function () {
			$('#our-expertise #expertise-sections section:first').css('background', 'url(./images/our-expertise/background-solid.png) no-repeat');
		}
	},
	contactUs: {
		init: function () {
			$('.jqtransform').jqTransform().css('visibility', 'visible');
		}
	},
	careersHome: {
		init: function () {
			$('a.learn-more').live('click', function () {
				$('#slide-wrap').animate({ 'margin-top': '-4000px' }, 1000);
			});
			$('.nav-links a').live('click', function () {
				var pageAnchor = $(this).attr('rel');
				var pageId = String('#' + pageAnchor);
				var divPosition = parseInt($(pageId).position().top);
				if (!$(this).hasClass('active')) {
					$('#slide-wrap').animate({ 'margin-top': -divPosition }, 1000);
				}
				return false;
			});
			$('a.moving-up').live('click', function () {
				var currentPage = $(this).parent().attr('id');
				var pageId = String('#' + currentPage);
				var divPosition = parseInt($(pageId).position().top);
				$('#slide-wrap').animate({ 'margin-top': -divPosition + 1000 }, 1000);
			});



			var config = {
				over: open,
				timeout: 150,
				out: close
			};

			$('.info-box').hoverIntent(config);

			function open() {
				obj = $(this);
				var contentLength = obj.find('.text-box').width();
				obj.find('h2').css({ 'width': contentLength + 2 });
				obj.find('.text-box, img').delay(750).stop('true', 'true').fadeIn();
				obj.find('.hotspot').addClass('active');
			}

			function close() {
				obj.find('h2').css('width', 'auto');
				obj.find('.text-box, img').fadeOut(100);
				obj.find('.hotspot').removeClass('active');
			}
			$(document).ready(function () {
				$('#loading').delay(2000).fadeOut(1000);
				$("p.intro-quote").delay(750).fadeIn(1000);
			});
		}
	},
	careersCaseStudy: {
		init: function () {
			$(".answer-wrap").hide();
			$("#study-tabs").find("a[rel=q5]").css("background", "none");

			$("#case-study").find("section:first").show();

			$(".answer-trigger").click(function () {
				var obj = $(this);
				obj.toggleClass("active");
				obj.next("div").stop("yes", "yes").slideToggle();
			});

			$(".continue").live("click", function () {
				var obj = $(this);
				obj.text("CONTINUE");
				if (!$("#study-tabs li:last a").hasClass("active")) {
					$("section:visible").hide().next("section").show();
					$("#study-tabs").find(".active").removeClass().parent("li").next().find("a").addClass("active");
				}
				if ($("#study-tabs a:last").hasClass("active")) {
					obj.hide();
				}
				return false;
			});

			$("#study-tabs a").click(function () {
				var rel = $(this).attr("rel");
				$("#study-tabs a").removeClass("active");
				$(this).addClass("active");
				$("#case-study section").hide()
				$("#case-study").find("#" + rel).show();
				if ($(this).attr("rel") === "q0") {
					$(".continue").text("GET STARTED");
				}
				else {
					$(".continue").text("CONTINUE");
				}
				if ($("#study-tabs a:last").hasClass("active")) {
					$(".continue").hide();
				}
				else {
					$(".continue").show();
				}
				return false;
			});
		}
	},
	careersListing: {
		init: function () {
			$('.jqtransform').jqTransform().css('visibility', 'visible');
			$("#people-listing span.overlay").append("<img class=\"hover\" src=\"/images/careers/people-overlay.png\" />");
			$("#people-listing span.overlay").hover(function () {
				$(this).find(".hover").stop("true", "true").fadeIn(250);
			}, function () {
				$(this).find(".hover").stop("true", "true").fadeOut(1000);
			});
		}
	},
	applyNow: {
		init: function () {
			$('.jqtransform').jqTransform();
			$("#degree2, #degree3").hide();
			SI.Files.stylizeAll();
			$(".resume-cover input").change(function () {
				var fileTarget = $(this).val();
				$(this).siblings("span").text(fileTarget);
			});
			$("a.add-education").click(function () {
				$(".education").find("fieldset:hidden:first").slideDown(450);
				if ($("fieldset:hidden").length === 0) {
					$(this).delay(500).slideUp(450);
				}
			});
		}
	},
	careersProgression: {
		init: function () {
			$("#progress-tabs li:first, #progress-box section:first").addClass("active");
			$("#progress-tabs a").click(function () {
				var selected = $(this).attr("rel");
				$("#progress-tabs li").removeClass("active");
				$(this).parent().addClass("active");
				$("#progress-box section").hide();
				$("#progress-box").find("." + selected).fadeIn();
				return false;
			});
		}
	}
}
