/* Author: Adrian Rodriguez - @oGLOWo

 */
(function() {

	function checkUrl() {
		console.log("checking the url ...%o", location);
		// remove all forward slashes
		var path = location.pathname.replace(/\//g, "");
		if(path !== "") {
			$(".nav-image").removeClass("active");
			console.log("The PATH is %s", path);
			if(path === "case-studies") {
				console.log("path is case studies");
				$("#case-studies-link > div > div.nav-image").addClass("active");
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "clients-and-talent") {
				$("#talent-link > div > div.nav-image").addClass("active");
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "team") {
				$("#team-link > div > div.nav-image").addClass("active");
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "contact") {
				$("#contact-link > div > div.nav-image").addClass("active");
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-baron-davis-li-ning") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-ibeatyou-featured-extra") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-ibeatyou-ncis") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-jessica-alba-staring-competition") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-kevjumba-vs-globetrotters") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-nick-swisher-mercedes") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "case-studies-step-brothers-campaign") {
				window.location = window.location.protocol + "//" + window.location.hostname + "/#!" + window.location.pathname;
			} else if(path === "") {
				$("#home-link > div > div.nav-image").addClass("active");
			}
		} else {
			// remove all forward slashes and hash bang
			var hash = location.hash.replace(/[#,!,\/]/g, "");
			$(".nav-image").removeClass("active");

			if(hash === "case-studies") {
				$("#case-studies-link > div > div.nav-image").addClass("active");
				$("#case-studies-link").click();
			} else if(hash === "clients-and-talent") {
				$("#talent-link > div > div.nav-image").addClass("active");
				$("#talent-link").click();
			} else if(hash === "team") {
				$("#team-link > div > div.nav-image").addClass("active");
				$("#team-link").click();
			} else if(hash === "contact") {
				$("#contact-link > div > div.nav-image").addClass("active");
				$("#contact-link").click();
			} else if(hash === "case-studies-baron-davis-li-ning") {
				$("#case-studies-link > div > div.nav-image").addClass("active");
				$("#case-studies-baron-link").click();
			} else if(hash === "") {
				$("#home-link > div > div.nav-image").addClass("active");
				$("#home-link").click();
			}
		}
	}

	$(window).hashchange(function() {
		console.log("Hash is now %o", location.hash);
		checkUrl();
	});
	function updateHashForLink(linkUrl) {
		if(linkUrl) {
			// remove all forward slashes
			linkUrl = linkUrl.replace(/\//g, "");
			if(linkUrl === "case-studies") {
				location.hash = "#!/" + linkUrl;
			} else if(linkUrl === "clients-and-talent") {
				location.hash = "#!/" + linkUrl;
			} else if(linkUrl === "team") {
				location.hash = "#!/" + linkUrl;
			} else if(linkUrl === "contact") {
				location.hash = "#!/" + linkUrl;
			} else if(linkUrl === "case-studies-baron-davis-li-ning") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "case-studies-ibeatyou-featured-extra") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "case-studies-ibeatyou-ncis") {
				location.hash = "#!/" + linkUrl;
			} 
			else if(linkUrl === "case-studies-jessica-alba-staring-competition") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "case-studies-kevjumba-vs-globetrotters") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "case-studies-nick-swisher-mercedes") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "case-studies-step-brothers-campaign") {
				location.hash = "#!/" + linkUrl;
			}
			else if(linkUrl === "") {
				location.hash = new Date().getTime();
			}
		}
		else {
			location.hash = new Date().getTime();
		}
	}

	function initializeCaseStudyListeners() {
		$("div.thumbnail").hover(function(e) {
			$("div.gradient-cover", this).fadeOut();
		}, function(e) {
			$("div.gradient-cover", this).fadeIn();
		});
		$(".case-study-link").click(function(e) {
			e.stopPropagation();
			e.preventDefault();
			var linkUrl = $(this).attr("href");
			updateHashForLink(linkUrl);
			var pageFragment = linkUrl + " #main>*";
			console.log("link is %s", pageFragment);
			$.colorbox({
				href : pageFragment,
				scrolling:false,
				onComplete : function() {
					if ($("#slider")) {
						$("#slider").bxSlider({mode:"fade", pagerType:"short"});
						linkUrl = linkUrl.replace(/\//g, "");
						if (linkUrl === "case-studies-nick-swisher-mercedes") {
							$.colorbox.resize({width:$(".case-study-nick").width() + 170, scrolling:false});
						}
					}
					addthis.toolbox($(".addthis_toolbox")[0]);
				},
				onCleanup : function() {
					console.log("updating hash for link");
					updateHashForLink("");
				}
			});
		});
	}

	function initializeTalentListeners() {
		$("div.talent-profile").hover(function(e) {
			$("div.social-stats-container", this).animate({
				top : -100
			});
		}, function(e) {
			$("div.social-stats-container", this).animate({
				top : 0
			});
		});
	}

	function initializeConnectListeners() {
		$('#contact-form input[name="name"]').val("");
		$('#contact-form input[name="inquiry-type"]').val("");
		$('#contact-form input[name="email"]').val("");
		$('#contact-form textarea[name="message"]').val("");

		$("#contact-form").submit(function(e) {
			console.log("asdfasdf");
			e.stopPropagation();
			e.preventDefault();
			var form = this;

			var url = $(this).attr("action");
			var name = $('input[name="name"]', this).val();
			var inquiryType = $('input[name="inquiry-type"]', this).val();
			var email = $('input[name="email"]', this).val();
			var message = $('textarea[name="message"]', this).val();

			$.ajax(url, {
				type : "post",
				data : {
					name : name,
					inquiryType : inquiryType,
					email : email,
					message : message
				},
				headers : {
					Accept : "application/json"
				},
				success : function(response) {
					$("<div></div>").html("Thank You for your interest in Apoko Group. Someone will be in touch shortly.").dialog({
						autoOpen : true,
						title : "Thank You"
					});
					$('input[name="name"]', form).val("").blur();
					$('input[name="inquiry-type"]', form).val("").blur();
					$('input[name="email"]', form).val("").blur();
					$('textarea[name="message"]', form).val("").blur();
				}
			});
		});
		$("input#name").focus(function(e) {
		$('label[for="name"]').fadeOut();
		}).blur(function(e) {
			var inputText = $(this).attr("value");
			if(!inputText || inputText.length === 0) {
				$('label[for="name"]').fadeIn();
			}
		});
		$("input#email").focus(function(e) {
		$('label[for="email"]').fadeOut();
		}).blur(function(e) {
			var inputText = $(this).attr("value");
			if(!inputText || inputText.length === 0) {
				$('label[for="email"]').fadeIn();
			}
		});
		$("textarea#message").focus(function(e) {
		$('label[for="message"]').fadeOut();
		}).blur(function(e) {
			var inputText = $(this).attr("value");
			if(!inputText || inputText.length === 0) {
				$('label[for="message"]').fadeIn();
			}
		});
		$("input#inquiry-type").focus(function(e) {
		$('label[for="inquiry-type"]').fadeOut();
		}).blur(function(e) {
			var inputText = $(this).attr("value");
			if(!inputText || inputText.length === 0) {
				$('label[for="inquiry-type"]').fadeIn();
			}
		});
	}

	function initializeTeamListeners() {
		$("#team-container > div.member-container:nth-child(1)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : -35,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").attr("src", "/img/abdul-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -60
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0.0
			});
		}, function(e) {
			$(this).animate({
				top : 0,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/abdul-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(2)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : -35,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").attr("src", "/img/cash-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -60
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 0,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/cash-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(3)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : -35,
				left : 240,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("img.member-picture").attr("src", "/img/kate-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -60
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 0,
				left : 480,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/kate-220x165.png")
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(4)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : -35,
				left : 480,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("img.member-picture").attr("src", "/img/brad-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -60
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 0,
				left : 720,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/brad-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(5)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : 30,
				left : 0,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("img.member-picture").attr("src", "/img/chad-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -125
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 205,
				left : 0,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/chad-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(6)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : 30,
				left : 240,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").attr("src", "/img/adrian-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -125
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 205,
				left : 240,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/adrian-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(7)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : 30,
				left : 240,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").attr("src", "/img/christine-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -125
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 205,
				left : 480,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/christine-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
		$("#team-container > div.member-container:nth-child(8)").hover(function(e) {
			$(this).addClass("active");
			$(this).css("z-index", 10);
			$(this).animate({
				top : 30,
				left : 480,
				width : 460,
				height : 408
			}, function(e) {
			});
			$(this).find("div.member-name").animate({
				height : 65,
				fontSize : "32px",
				lineHeight : "65px"
			});
			$(this).find("img.member-picture").attr("src", "/img/alan-460x345.gif");
			$(this).find("img.member-picture").animate({
				height : 345,
				width : 460,
			});
			$(this).find("div.member-info").animate({
				top : -125
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 0.5
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 0
			});
		}, function(e) {
			$(this).animate({
				top : 205,
				left : 720,
				width : 220,
				height : 195
			}, function(e) {
				$(this).css("z-index", 1);
			});
			$(this).find("div.member-name").animate({
				height : 30,
				fontSize : "14px",
				lineHeight : "30px"
			});
			$(this).find("img.member-picture").animate({
				height : 165,
				width : 220,
			}, function(e) {
				$(this).attr("src", "/img/alan-220x165.png");
			});
			$(this).find("div.member-info").animate({
				top : 0
			});
			$("div#team-container div.member-container:not(.active)").animate({
				opacity : 1
			});
			$("div#team-container div.member-container:not(.active) > div.member-name").animate({
				opacity : 1
			});
			$(this).removeClass("active");
		});
	}

	function scrollToCaseStudies(onScrollEnd) {
		$("body,html").animate({
			scrollTop : $("#case-studies-section").offset().top - 125
		}, 1000, onScrollEnd);
	}

	$(document).bind("apoko:caseStudiesLoaded", function(e, p1, p2) {
		e.stopPropagation();
		e.preventDefault();
		console.log("CAse studies loaded");
		initializeCaseStudyListeners();
	});
	$(document).bind("apoko:contactLoaded", function(e, p1, p2) {
		e.stopPropagation();
		e.preventDefault();
		initializeConnectListeners();
	});
	$(document).bind("apoko:teamLoaded", function(e, p1, p2) {
		e.stopPropagation();
		e.preventDefault();
		console.log("Team was loaded");
		initializeTeamListeners();
	});
	$(document).bind("apoko:talentLoaded", function(e, p1, p2) {
		e.stopPropagation();
		e.preventDefault();
		initializeTalentListeners();
	});
	$(document).ready(function() {
		var viewportHeight = $(window).height();
		console.log("The Viewport height is %d", viewportHeight);
		//$(".lots-of-space").css("height", viewportHeight);
		checkUrl();

		$(window).resize(function(e) {	
			var viewportHeight = $(window).height();
			console.log("The Viewport height is %d", viewportHeight);
			//$(".lots-of-space").css("height", viewportHeight);
		});
		$("#case-studies-section").load("/case-studies/ #main>*", function() {
			console.log("loaded-case-studies");
			initializeCaseStudyListeners();
			// remove all forward slashes and hash bang
			var hash = location.hash.replace(/[#,!,\/]/g, "");
			if(hash === "case-studies") {
				$("#case-studies-link").click();
			} else if(hash === "case-studies-baron-davis-li-ning") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-baron-link").click();
					}
				});
			} else if (hash === "case-studies-ibeatyou-featured-extra") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-ibeatyou-extra-link").click();
					}
				});
			}
			else if (hash === "case-studies-ibeatyou-ncis") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-ibeatyou-ncis-link").click();
					}
				});
			}
			else if (hash === "case-studies-jessica-alba-staring-competition") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-jessica-link").click();
					}
				});
			}
			else if (hash === "case-studies-kevjumba-vs-globetrotters") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-kevjumba-link").click();
					}
				});
			}
			else if (hash === "case-studies-nick-swisher-mercedes") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-swisher-link").click();
					}
				});
			}
			else if (hash === "case-studies-step-brothers-campaign") {
				scrollToCaseStudies(function() {
					if($("#colorbox").css("display") !== "block") {
						$("#case-studies-stepbrothers-link").click();
					}
				});
			}
		});
		$("#talent-section").load("/clients-and-talent/ #main>*", function() {
			console.log("loaded talent");
			var hash = location.hash.replace(/[#,!,\/]/g, "");
			if(hash === "clients-and-talent") {
				$("#talent-link").click();
			}
			initializeTalentListeners();
		});
		$("#team-section").load("/team/ #main>*", function() {
			console.log("loaded TEAM");
			var hash = location.hash.replace(/[#,!,\/]/g, "");
			if(hash === "team") {
				$("#team-link").click();
			}
			initializeTeamListeners();
		});
		$("#contact-section").load("/contact/ #main>*", function() {
			console.log("loaded connect");
			var hash = location.hash.replace(/[#,!,\/]/g, "");
			if(hash === "contact") {
				$("#contact-link").click();
			}
			initializeConnectListeners();
		});
		$("nav > a").click(function(e) {
			e.stopPropagation();
			e.preventDefault();
			updateHashForLink($(this).attr("href"));
			var pageFragment = $(this).attr("href") + " #main>*";
			var elementId = $(this).attr("id");
			console.log("link is %s with id %s", pageFragment, elementId);
			if(elementId && elementId === "case-studies-link") {
				//console.log("triggering");
				//$(document).trigger("apoko:caseStudiesLoaded");
				$("body,html").animate({
					scrollTop : $("#case-studies-section").offset().top - 125
				}, 1000);
			} else if(elementId && elementId === "team-link") {
				//$(document).trigger("apoko:teamLoaded");
				$("body,html").animate({
					scrollTop : $("#team-section").offset().top - 125
				}, 1000);
			} else if(elementId && elementId === "talent-link") {
				//$(document).trigger("apoko:talentLoaded");
				$("body,html").animate({
					scrollTop : $("#talent-section").offset().top - 125
				}, 1000);
			} else if(elementId && elementId === "contact-link") {
				//$(document).trigger("apoko:contactLoaded");
				$("body,html").animate({
					scrollTop : $("#contact-section").offset().top - 125
				}, 1000);
			} else if(elementId && elementId === "home-link") {
				$("body,html").animate({
					scrollTop : $("#what-we-do-copy").offset().top - 125
				}, 1000);
			}

			$("nav img.active").removeClass("active");
			$("img", this).toggleClass("active");
		});
		initializeCaseStudyListeners();
		initializeTeamListeners();
		initializeTalentListeners();
		initializeConnectListeners();
	})
})();

