//VARS
navPath = []; // see getNavPath below
initialPageTracked = false;  // used for GA tracking.  see setNavLocation below

// add pointer to all elements with a click event on them
jQuery.event.special.click = {
    setup: function() {
        $(this).css('cursor','pointer');
        return false;
    },
    teardown: function() {
        $(this).css('cursor','');
        return false;
    }
};

// video player functionality
var isInitialSetup = true;
function setupVideo(element, videoName, _autostart, _width, _height) {	
	if(isInitialSetup) { 
		 isInitialSetup = false;
	} else {
		jwplayer().remove();
	}
	var width = 800;
	var height = 450;
	if(_width) { width = _width; }
	if(_height) { height = _height }
			
	jwplayer(element).setup({
		autostart: _autostart,
		skin: "/jwplayer/skins/glow.zip",
        width: width,
        height: height,
        image: "/images/video-still-"+videoName+"-full.jpg",
        modes: [
	        { type: 'flash', src: '/jwplayer/player.swf' },
	        { type: 'html5' }
	        
	    ],
        levels: [
            { file: "/video/"+videoName+".mp4" },    // H.264 version
            { file: "/video/"+videoName+".webm" },    // WebM version
            { file: "/video/"+videoName+".ogv" }     // Ogg Theora version
        ],
        plugins: {
	      "gapro-2": {}
	 	}  
    });
    
}

function setupAudio(element, fileName, _autostart, _width, _height) {	
	if(isInitialSetup) { 
		 isInitialSetup = false;
	} else {
		jwplayer().remove();
	}
			
	jwplayer(element).setup({
		autostart: _autostart,
		flashplayer: "/jwplayer/player.swf",
        width: _width,
        height: _height,
        file: "/audio/" + fileName + ".mp3",
        controlbar:"bottom"
    });
    
    $("#work-showcase-video").css("background-image", "/images/tmi_90x47_photo_contest.jpg");
}

// turns a path like /about/leadership/hughkennedy in to an array like ["about", "leadership", "hughkennedy"]
function getNavPath(path) {
	// strip hashes and periods
	path = path.replace(".","");
	path = path.replace("#","");
	if(path.charAt(0) == "/") {
		path = path.slice(1);	
	}
	
	// convert to an array
	var arr = path.split("/");
	
	// remove any empty items in the array
	for (var i = 0; i < arr.length; i++) {
	    if (arr[i] == "") {         
	      arr.splice(i, 1);
	      i--;
	    }
	  }
	
	return arr;
}





$(document).ready(function(){
	
	//console.log('DOM ready');
	
	// SETUP HISTORY, LOCATION CHANGE HANDLER
	(function(window,undefined){

	    // Prepare
	    var History = window.History; // Note: We are using a capital H instead of a lower h
	    if ( !History.enabled ) {
	         // History.js is disabled for this browser.
	         // This is because we can optionally choose to support HTML4 browsers or not.
	        return false;
	    }
	
	    // Bind to StateChange Event
	    History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
	        var State = History.getState(); // Note: We are using History.getState() instead of event.state
	        //console.log("getState: " + History.getState());
	    });

	
	})(window);
	
	
	// VIDEO PLAYERS
	// home, initial setup
	setupVideo("home-video-container", "home-sizzle", false);
	$("#home-video-container img").live('click', function(){ setupVideo("home-video-container", "home-sizzle", true); });	
	
	// Click Work Showcase Thumbnail
	function clickWorkShowcaseTn(tn){
		if($('#' + tn).parent().attr('id') != 'work-tns-container'){
			$('#' + tn).parent().parent().children().removeClass('active');
			$('#' + tn).parent().addClass('active');
		} else {
			$('#work-showcase #' + tn + '-content .work-showcase-nav').children().removeClass('active');
			$('#work-showcase #' + tn + '-content .work-showcase-nav div:last').addClass('active');			
		}
	}
	
	// work
	$("#brother1, #brother1-tn").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "brother-case-study", true);
	});
	$("#bri-30sec").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "bri-30sec", true);
	});
	$("#bri-boo-chuck").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "bri-boo-chuck", true);
	});
	$("#limelight1, #limelight1-tn").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "limelight-case-study", true);
	});
	$("#limelight-windmill").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "limelight-windmill", true);
	});
	$("#limelight-garage").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "limelight-garage", true);
	});
	$("#ironmountain1, #ironmountain1-tn").click(function(){
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "iron-mountain-case-study", true);
	});
	$("#imt-buried-file").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "imt-800x450-buried-file", true);
	});
	$("#imt-inactive-file").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "imt-800x450-inactive-file", true);
	});
	$("#imt-runaway-file").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "imt-800x450-runaway-file", true);
	});
	$("#imt-duplicated-file").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "imt-800x450-duplicated-file", true);
	});
	$("#novell1").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "novell-vibe-case-study", true);
	});
	$("#novell2").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "nov-800x450-workload-iq-case-study", true);
	});
	$("#te1, #te1-tn").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "te-case-study", true);
	});
	$("#te-anthem").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "tec-800x450-anthem", true);
	});
	$("#trend1, #trend1-tn").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "trend-no-face-case-study", true);
	});
	$("#trend-bigband").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "tmi-noface-bigband30", true);
	});
	/*$("#trend-radio").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupAudio("work-showcase-video-holder", "dont_be_like_albert_30_radio_spot", true, 800, 450);
	});
	*/
	$("#trend2, #trend2-tn").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "trend-titanium-case-study", true);
	});
	$("#tmi-escalator").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "tmi-escalator", true);
	});
	$("#trend-game").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "trend-game", true);
	});
	$("#extreme1").click(function(){ 
		clickWorkShowcaseTn($(this).attr('id'));
		setupVideo("work-showcase-video-holder", "extreme-case-study", true);
	});
	//careers
	$("#careers-culture-shakes").live('click', function(){ setupVideo("careers-culture-shakes-video-container", "careers-culture-shakes", true); });
	$("#careers-culture-justinbeaver").live('click', function(){ setupVideo("careers-culture-justinbeaver-video-container", "careers-culture-justinbeaver", true); });
	$("#careers-culture-bizbieber").live('click', function(){ setupVideo("careers-culture-bizbieber-video-container", "careers-culture-bizbieber", true); });
	$("#careers-culture-golfchamp").live('click', function(){ setupVideo("careers-culture-golfchamp-video-container", "careers-culture-golfchamp", true); });
	
	// approach
	$("#strategy1").click(function(){ setupVideo("strategy-video-container1", "business_to_buyer_550x310", true, 550, 310); });
	$("#strategy2").click(function(){ setupVideo("strategy-video-container2", "truth_over_imitation", true, 550, 310); });
	$("#strategy3").click(function(){ setupVideo("strategy-video-container3", "brand_and_demand", true, 550, 310); });
	$("#business, #approach-business-video").live('click', function(){ setupVideo("approach-business-video-container", "business_to_buyer_800x450", true); });
	
	// this manages the fullscreen view in the HTML5 player.
	// without this, many elements show on top of the video
	
	jwplayer().onReady(function(){
			  if(this.container.tagName.toLowerCase() == "object") {
				  // flash version of the player
			  } else {
				  // html5 player, manage the fullscreen issue
				  jwplayer().onFullscreen(function(e){ 
					  if(e.fullscreen) {
						  $("header, footer").hide();
						  $("#content").children().hide();
						  $("#home-section, #home-container").show();
						  $("#home-copy-container, #home-headline").hide();
					  } else {
						  $("header, footer").show();
						  $("#content").children().show();
						  $("#home-copy-container, #home-headline").show();
					  }
				  });
			}
		});
			


	// MAIN NAVIGATION ==========================================================================================================
    var $menuLinks = $('.main-nav a, #footer-col-left a.main');
    $menuLinks.click(scrollPageFromClick);

       
	function scrollPageFromClick(e) {
		$obj = $(e.currentTarget);
		scrollPage($obj, true);
		return false;
	}
    
	function scrollPage($obj, doAddState) {
		var whereTo = $obj.attr('href');
		var location = null;
		if(doAddState) {
			location = whereTo;
		}
		setNavLocation(whereTo, location);

		if ($('#' + whereTo +"-section").text() != '') {
			$.scrollTo($('#' + whereTo + "-section"), 1000, {
				axis: 'y', 
				easing: ''    
			});
		}
	}
	
	function setNavLocation(activeNavItem, location) {
		// set nav highlight
		$menuLinks.removeClass("active");
		$("#"+activeNavItem).addClass("active");
		
		// track pageview in GA, only if it's a new "page"
		if(document.location.pathname == "/" + location && initialPageTracked) {
			//console.log('skipping page track');
		} else {
			if(!initialPageTracked) {
				initialPageTracked = true;
			}
			//console.log('should push ga');
			try {
				_gaq.push(['_trackPageview', location]);
			} catch(err) {}	
		}
		
		// set history state, with location bar update
		if(location) {
			History.pushState(null, "", "/" + location);
		}
		
	}
	
	// PARAGRAPH VIEW MORE/LESS ==========================================================================================================
	$('.show-more').click(function(e){
		$(this).parent().children('.more').show('slow');
		$(this).hide();
		$(this).parent().children('.show-less').show();
		// get the section we're in
		section = $(e.currentTarget).parents("section").attr("id").replace("-section", "");
		setNavLocation(section, section);
		return false;
	});
	
	$('.show-less').click(function(e){
		$(this).parent().children('.more').hide('slow');
		$(this).hide();
		$(this).parent().children('.show-more').show();
		setNavLocation(section, section);
		return false;
	});
	
	// HOME SLICE CLICK ==========================================================================================================
	var homeTextVisible = false;
	$('#home-copy-btn').click(function(e){
		$('#home-copy-btn-img').rotateRight(180);
		if(homeTextVisible == false){
			$('#home-copy-container').animate({'left': '-=820px'}, 700, function() {
				homeTextVisible = true;
				if(jwplayer().getState() == "PLAYING" || jwplayer().getState() == "BUFFERING") {
					jwplayer().pause();
				}
			});
		} else {
			$('#home-copy-container').animate({'left': '+=820px'}, 600, function() {
				homeTextVisible = false;
				if(jwplayer().getState() == "PAUSED") {
					jwplayer().play();
				}
			});
		}
	});
	
	// open as default
	var navOpen = true;
	var navAnimating = false;
	$('#header-container').hover(		
		function(){
			// on ROLL OVER
			if((!navOpen)&&(!navAnimating)){
				// start animating
				navAnimating = true;
				// 'view nav' fades out
				$('#header-nav-closed').fadeOut(300, function(){
					// header and content down 70 pixels
					$('#header-container, #content').animate({marginTop: '+=70px'}, 300);
					// logo and tag up 55 pixels
					$('#header-logo, #header-tag').animate({marginTop: '-=48px'}, 300, function() {
						// navigation fade in
						$('nav').fadeIn(800, function(){
							// nav is now open
							navOpen = true;
							// done animating
							navAnimating = false;
						});
					});
				});
			}
		}, 
		function(){
			// on ROLL OUT
			if((navOpen)&&(!navAnimating)){
				// start animating
				navAnimating = true;
				// navigation fades out
				$('nav').fadeOut(200, function() {
					// header and content up 70 pixels
					$('#header-container, #content').animate({marginTop: '-=70px'}, 300);
					// logo and tag down 55 pixels
					$('#header-logo, #header-tag').animate({marginTop: '+=48px'}, 300, function(){
						// 'view nav' fade in
						$('#header-nav-closed').fadeIn(300, function(){
							// nav is now closed
							navOpen = false;
							// done animating
							navAnimating = false;
						});
					});
				});
			}
		}
	);
	
	// MAIN VIDEO =================================================================================
	
	
	
	
	// WORK =============================================================================================================================
	// ===================================================================================================================
	
	// work tn rollover
	$('.work-tn').hover(		
		function(){
			$('.work-tn-txt', this).animate({'top': '-=45px'}, 'fast');
		}, 
		function(){
			$('.work-tn-txt', this).animate({'top': '+=45px'}, 'fast');
		}
	);
	
	// work tn click
	$('.work-tn').click(function(e){
		// hide all the .work-showcase-info 
		$('.work-showcase-info').hide();
		// show the .showcase-info that has this same id as this tn
		var thisWorkShowcase = '#work-showcase ' + '#' + $(this).attr('id') + '-content';
		$(thisWorkShowcase).show();
		//
		$('#work-showcase').show();
		$('#work-showcase').animate({height:'475px'}, 500, function() {
			var whereTo = $('#work-section');
			$.scrollTo($('#work-section'), 500, {axis: 'y', easing: ''});
		});
		setNavLocation("work", "work/" + $(this).attr('id'));
	});	
	
	
	// work arrow click and sorter
	var tnPadding = 20;
	var tnWidth = $('.work-tn').width() + tnPadding;
	var moveLeft = '-=' + tnWidth;
	var moveRight = '+=' + tnWidth;
	var numTotalTns = $('#work-tns-container > div').size();
	var tnContainerWidth = numTotalTns * tnWidth;
	$('#work-tns-container').css('width', tnContainerWidth);
	$('#work-arrow-left').css('opacity', 0.3);
	
	function animateTnContainer(){
		$('#work-tns-container').css('left', 1000);
		$('#work-tns-container').animate({left:'0'}, 'fast');
	}
	function setTnContainerWidth(){
		var numHiddenTns = $('#work-tns-container > div:hidden').size();
		var numViewableTns = numTotalTns - numHiddenTns;
		var newTnContainerWidth = numViewableTns * tnWidth;
		$('#work-tns-container').css('width', newTnContainerWidth);
		$('#work-arrow-left').css('opacity', 0.3);
		if(newTnContainerWidth <= 748){
			$('#work-arrow-right').css('opacity', 0.3);
		} else {
			$('#work-arrow-right').css('opacity', 1);
		}
	}
	
	function workTnAnimation(direction){
		// disable while animating
		if (!$('#work-tns-container').is(':animated')){
			// work-tn-container left position			
			var tnContainerPos = $('#work-tns-container').css('left').replace('px', '');
			// work-tn-container's limit to moving left
			var curTnContainerWidth = $('#work-tns-container').css('width').replace('px', '');
			var tnContainerLimit = (curTnContainerWidth - (tnWidth*3))*-1;
			// right arrow click 
			if(direction == 'right'){				
				if(tnContainerPos > tnContainerLimit){
					$('#work-arrow-left').css('opacity', 1);
					// animate tns
					$('#work-tns-container').animate({left: moveLeft}, 500, function(){
						var tnContainerPos = $('#work-tns-container').css('left').replace('px', '');
						if(tnContainerPos <= tnContainerLimit){
							$('#work-arrow-right').css('opacity', 0.3);
						}
					});
				}
			// left arrow click 
			} else if(direction == 'left'){
				if(tnContainerPos < 0){
					$('#work-arrow-right').css('opacity', 1);
					// animate tns
					$('#work-tns-container').animate({left: moveRight}, 500, function(){
						// update tn container position
						var tnContainerPos = $('#work-tns-container').css('left').replace('px', '');
						if(tnContainerPos >= 0){
							$('#work-arrow-left').css('opacity', 0.3);
						}
					});
				} 
			}
		}
		return false;
	}
	
	$('#work-arrow-left').click(function(e){
		workTnAnimation('left');
	});
	$('#work-arrow-right').click(function(e){
		workTnAnimation('right');
	});
	$('#work-arrow-left, #work-arrow-right').hover(		
		function(){
			if($(this).css('opacity') == 1){
				$(this).addClass('work-arrow-over');
			}
		}, 
		function(){
			if($(this).css('opacity') == 1){
				$(this).removeClass('work-arrow-over');
			}
		}
	);
	$('#work-sorter .sort-east').click(function(e){
		$('.east').css('display', 'block');
		$('.west').css('display', 'none');
		$(this).addClass('active');
		$('#work-sorter .sort-west').removeClass('active');
		$('#work-sorter .sort-all').removeClass('active');
		animateTnContainer();
		setTnContainerWidth();
	});
	$('#work-sorter .sort-west').click(function(e){
		$('.west').css('display', 'block');
		$('.east').css('display', 'none');
		$(this).addClass('active');
		$('#work-sorter .sort-east').removeClass('active');
		$('#work-sorter .sort-all').removeClass('active');
		animateTnContainer();
		setTnContainerWidth();
	});
	$('#work-sorter .sort-all').click(function(e){
		$('.east').css('display', 'block');
		$('.west').css('display', 'block');
		$(this).addClass('active');
		$('#work-sorter .sort-east').removeClass('active');
		$('#work-sorter .sort-west').removeClass('active');
		animateTnContainer();
		setTnContainerWidth();
	});
	
	// work showcase close
	$('#work-showcase .close').click(function(e){
		if(!$('#work-sorter .sort-all').hasClass('active')){
			$('.east').css('display', 'block');
			$('.west').css('display', 'block');
			$('#work-sorter .sort-all').addClass('active');
			$('#work-sorter .sort-east').removeClass('active');
			$('#work-sorter .sort-west').removeClass('active');
			animateTnContainer();
			setTnContainerWidth();
		}
		$('#work-showcase').animate({height:'1px'}, 500, function() {
			var whereTo = $('#work-section');
			$('#work-showcase').hide();
			if(jwplayer().getState() == "PLAYING") {	
				jwplayer().pause(); //TODO fix JW player home bug
			}
			$.scrollTo($('#work-section'), 500, {axis: 'y', easing: ''});
		});
	});
	
	
	// APPROACH ==========================================================================================================
	// ===================================================================================================================

	// approach default arrow click
	var approachStratOpen = false;
	$('#approach-strategy-btn').click(function(e){
		$('#approach-strategy-btn-img').rotateRight(180);
		if(approachStratOpen){
			$('#approach-strategy').animate({'left': '+=1180px'}, 'slow');
			approachStratOpen = false;
		} else {
			$('#approach-strategy').animate({'left': '-=1180px'}, 'slow');
			approachStratOpen = true;
		}
		setNavLocation("approach", "approach");
	});
	// approach strategy 
	var curStrategy = '#video-strategy-default';
	$('.strategy-tn').click(function(e){	
		// show close btn if needed
		if(curStrategy == '#video-strategy-default'){
			$('#approach-showcase #approach-strategy-video .close').fadeIn();
		}
		// fadeout current video elements
		var newStrategy = '#video-' + $(this).attr('id');
		$(curStrategy).fadeOut('fast', function(){
			// fadein new video elements
			$(newStrategy).fadeIn('slow');
			curStrategy = newStrategy;
		});
		$('.strategy-tn').css({opacity: .3});
		$(this).css({opacity: 1});
		// pause the video player
		if(jwplayer().getState() === "PLAYING") {
			jwplayer().pause();
		}
		
	});
	$('#approach-showcase #approach-strategy-video .close').click(function(e){
		var newStrategy = '#video-strategy-default';
		$(curStrategy).fadeOut('fast', function() {
			$(newStrategy).fadeIn('slow');
			curStrategy = newStrategy;
		});	
		$('.strategy-tn').css({opacity: 1});
		$(this).fadeOut();
		// pause the video player
		if(jwplayer().getState() === "PLAYING") {
			jwplayer().pause();
		}
		
	});
	
	// approach tn click
	var approachSection = 0;
	$('.approach-tn').click(function(e){
		
		var approachSectionToShowcase = $(this).attr('id');
		if(approachSectionToShowcase == 'business'){
			if(approachSection == 0){
				$('#approach-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			if(approachSection == 2){
				$('#approach-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			if(approachSection == 3){
				$('#approach-showcase-container').animate({'left': '+=2440px'}, 'slow');
			}
			if(approachSection ==4){
				$('#approach-showcase-container').animate({'left': '+=3660px'}, 'slow');
			}
			approachSection = 1;
			setNavLocation("approach", "approach/business");
		} else if(approachSectionToShowcase == 'activating'){
			if(approachSection == 0){
				$('#approach-showcase-container').animate({'left': '-=2440px'}, 'slow');
			}
			if(approachSection == 1){
				$('#approach-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			if(approachSection == 3){
				$('#approach-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			if(approachSection == 4){
				$('#approach-showcase-container').animate({'left': '+=2440px'}, 'slow');
			}
			approachSection = 2;
			// pause the video player
			if(jwplayer().getState() === "PLAYING") {
				jwplayer().pause();
			}
			setNavLocation("approach", "approach/activating");
		} else if(approachSectionToShowcase == 'getting'){
			if(approachSection == 0){
				$('#approach-showcase-container').animate({'left': '-=3660px'}, 'slow');
			}
			if(approachSection == 1){
				$('#approach-showcase-container').animate({'left': '-=2440px'}, 'slow');
			}
			if(approachSection == 2){
				$('#approach-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			if(approachSection == 4){
				$('#approach-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			approachSection = 3;
			// pause the video player
			if(jwplayer().getState() === "PLAYING") {
				jwplayer().pause();
			}
			setNavLocation("approach", "approach/getting");
		} else if(approachSectionToShowcase == 'between'){
			if(approachSection == 0){
				$('#approach-showcase-container').animate({'left': '-=4880px'}, 'slow');
			}
			if(approachSection == 1){
				$('#approach-showcase-container').animate({'left': '-=3660px'}, 'slow');
			}
			if(approachSection == 2){
				$('#approach-showcase-container').animate({'left': '-=2440px'}, 'slow');
			}
			if(approachSection == 3){
				$('#approach-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			approachSection = 4;
			// pause the video player
			if(jwplayer().getState() === "PLAYING") {
				jwplayer().pause();
			}
			setNavLocation("approach", "approach/between");
		}
		
		$('#approach-showcase div:first.close').fadeIn();
		
		$('#approach-showcase-container').show();
		$('#approach-showcase').animate({height:'450px'}, 500, function() {
			var whereTo = $('#approach');
			$.scrollTo($('#approach-section'), 500, {axis: 'y', easing: ''});
		});
	});	
	
	// approach showcase close
	$('#approach-showcase .close').click(function(e){
		if(approachSection == 1){
			$('#approach-showcase-container').animate({'left': '+=1220px'}, 'slow');
		}
		if(approachSection == 2){
			$('#approach-showcase-container').animate({'left': '+=2440px'}, 'slow');
		}
		if(approachSection == 3){
			$('#approach-showcase-container').animate({'left': '+=3660px'}, 'slow');
		}
		if(approachSection == 4){
			$('#approach-showcase-container').animate({'left': '+=4880px'}, 'slow');
		}
		approachSection = 0;
		$(this).hide();
		if(jwplayer().getState() === "PLAYING") {
			jwplayer().pause();
		}
		
		setNavLocation("approach", "approach");
	});
	
	// approach tn rollover
	$('.approach-tn').hover(		
		function(){
			$('.approach-tn-txt', this).animate({'top': '-=42px'}, 'fast');
		}, 
		function(){
			$('.approach-tn-txt', this).animate({'top': '+=42px'}, 'fast');
		}
	);
		
	// APPROACH Validate And Submit Form
	function validateAndSubmitForm(formElement){
		$(formElement).validate({
			submitHandler: function(form){
		   		$.ajax({
		   			type: 'POST',
		   			url: $(form).attr('action'),
		   			dataType: 'json',
		   			data: $(form).serialize()
		   		}).done(function(data){
					//console.log();
		   			if(formElement == '#form3'){
						$('#approach-activating .approach-info-wide-thanks a').attr('href', data.file_url);
						$('#approach-activating .approach-info-wide').css('display', 'none');
						$('#approach-activating .approach-info-wide-thanks').css('display', 'block');
					} else if(formElement == '#form2'){
						$('#approach-getting .approach-info-wide-thanks a').attr('href', data.file_url);
						$('#approach-getting .approach-info-wide').css('display', 'none');
						$('#approach-getting .approach-info-wide-thanks').css('display', 'block');
					} else if(formElement == '#form1'){
						$('#approach-between .approach-info-thanks a').attr('href', data.file_url);
						$('#approach-between .approach-info').css('display', 'none');
						$('#approach-between .approach-info-thanks').css('display', 'block');
					}
		   		});
		   	},
		   	invalidHandler: function(e, validator){
				var errors = validator.numberOfInvalids();
				if (errors) {
					if(formElement == '#form3'){
						$('#approach-activating #error-msg').show();
					} else if(formElement == '#form2'){
						$('#approach-getting #error-msg').show();
					} else if(formElement == '#form1'){
						$('#approach-between #error-msg').show();
					}
				} else {
					if(formElement == '#form3'){
						$('#approach-activating #error-msg').hide();
					} else if(formElement == '#form2'){
						$('#approach-getting #error-msg').hide();
					} else if(formElement == '#form1'){
						$('#approach-between #error-msg').hide();
					}
				}
			},
			rules: {
				first_name: 'required',
				last_name: 'required',
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				first_name: '*',
				last_name: '*',
				email: '*'
			}
		});
	}	

	var myFirstName = '';
	var myLastName = '';
	var myTitle = '';
	var myEmail = '';
	
	function updateFormFields(){
		$('input#firstName').val(myFirstName);
		$('input#lastName').val(myLastName);
		$('input#jobTitle').val(myTitle);
		$('input#email').val(myEmail);
	}
	
	$('#activating-submit').click(function(e){
		myFirstName = $('#approach-activating input#firstName').val();
		myLastName = $('#approach-activating input#lastName').val();
		myTitle = $('#approach-activating input#jobTitle').val();
		myEmail = $('#approach-activating input#email').val();
		updateFormFields();
		validateAndSubmitForm('#form3');
	});
	$('#getting-submit').click(function(e){
		myFirstName = $('#approach-getting input#firstName').val();
		myLastName = $('#approach-getting input#lastName').val();
		myTitle = $('#approach-getting input#jobTitle').val();
		myEmail = $('#approach-getting input#email').val();
		updateFormFields();
		validateAndSubmitForm('#form2');
	});
	$('#between-submit').click(function(e){
		myFirstName = $('#approach-between input#firstName').val();
		myLastName = $('#approach-between input#lastName').val();
		myTitle = $('#approach-between input#jobTitle').val();
		myEmail = $('#approach-between input#email').val();
		updateFormFields();
		validateAndSubmitForm('#form1');
	});
	
		
	// ABOUT =============================================================================================================
	// ===================================================================================================================
	
	// about clients-tn Random Image.
	// array of about-client-tn images
	var clientsTnImgArray = [
		'/images/about-tn-clients-brother.gif',
		'/images/about-tn-clients-bs.gif',
		'/images/about-tn-clients-ca.gif',
		'/images/about-tn-clients-chase.gif',
		'/images/about-tn-clients-cog.gif',
		'/images/about-tn-clients-emc.gif',
		'/images/about-tn-clients-ge.gif',
		'/images/about-tn-clients-hit.gif',
		'/images/about-tn-clients-hp.gif',
		'/images/about-tn-clients-ibm.gif',
		'/images/about-tn-clients-infor.gif',
		'/images/about-tn-clients-jup.gif',
		'/images/about-tn-clients-lime.gif',
		'/images/about-tn-clients-lt.gif',
		'/images/about-tn-clients-mil.gif',
		'/images/about-tn-clients-nov.gif',
		'/images/about-tn-clients-nvt.gif',
		'/images/about-tn-clients-te.gif',
		'/images/about-tn-clients-tmi.gif',
		'/images/about-tn-clients-yahoo.gif'];
	function changeClientsTnImg(){
		//alert('change client TN');
		var clientsTnImg = clientsTnImgArray[Math.floor(Math.random() * clientsTnImgArray.length)];
		$('#about-tn-clients-img img').attr('src', clientsTnImg);
	}
	changeClientsTnImg();	
	
	
	// about tn click
	var aboutSection = 0;
	$('.about-tn').click(function(e){
		
		var aboutSectionToShowcase = $(this).attr('id');
		if(aboutSectionToShowcase == 'default'){
			if(aboutSection == 1){
				$('#about-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			if(aboutSection == 2){
				$('#about-showcase-container').animate({'left': '+=2440px'}, 'slow');
			}
			$('#about-showcase .close').fadeOut();
			aboutSection = 0;
		} else if(aboutSectionToShowcase == 'partners'){
			if(aboutSection == 0){
				$('#about-showcase-container').animate({'left': '-=2440px'}, 'slow');
			}
			if(aboutSection == 1){
				$('#about-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			$('#about-showcase .close').fadeIn();
			aboutSection = 2;
			setNavLocation("about", "about/partners");
		}
		$('#about-showcase').animate({height:'480px'}, 500, function() {
			var whereTo = $('#about-section');
			$.scrollTo($('#about-section'), 500, {axis: 'y', easing: ''});
		});
	});	
	// about showcase close
	$('#about-showcase .close').click(function(e){
		if(aboutSection == 1){
			$('#about-showcase-container').animate({'left': '+=1220px'}, 'slow');
		}
		if(aboutSection == 2){
			$('#about-showcase-container').animate({'left': '+=2440px'}, 'slow');
		}
		aboutSection = 0;
		$(this).hide();
		setNavLocation("about", "about");
	});
	
	// about-leadership tn click
	
	var curLeader = '';
	$('#about-leadership-tn div.active').click(function(){
		// move to the right showcase section
		if(aboutSection == 0){
			$('#about-showcase-container').animate({'left': '-=1220px'}, 'slow');
		}
		if(aboutSection == 2){
			$('#about-showcase-container').animate({'left': '+=1220px'}, 'slow');
		}
		$('#about-showcase .close').fadeIn();
		aboutSection = 1;
		// show the right leader
		var newLeader = '#' + $(this).attr('id') + "-content";
		if(curLeader != ''){
			$(curLeader).fadeOut('fast', function(){
				$(newLeader).fadeIn('slow');
			});	
		} else {
			$(newLeader).fadeIn('slow');
		}
		curLeader = newLeader;
		setNavLocation("about", "about/leadership/" + $(this).attr('id'));	
	});
	


	// NEWS & IDEAS ==========================================================================================================
	// =======================================================================================================================
	
	// twitter hrefs opens in new window
	$('#news-twitter a[href^="http://"]').attr('target', '_blank');
	
	// news and ideas arrow click
	var newsTnWidth = $('.news-tn-display').width();
	var moveNewsTnLeft = '-=' + newsTnWidth;
	var moveNewsTnRight = '+=' + newsTnWidth;
	var numNewsTns = $('.news-tn-display-container > div').size();
	var newsTnContainerWidth = numNewsTns * newsTnWidth;
	$('.news-tn-display-container').css('width', newsTnContainerWidth);
	$('#news-tn-arrow-left').css('opacity', 0.5);
	
	function newsTnAnimation(direction){
		if (!$('.news-tn-display-container').is(':animated')){
			var newsTnContainerPos = $('.news-tn-display-container').css('left').replace('px', '');
			var newsTnContainerLimit = (newsTnContainerWidth - newsTnWidth)*-1;
			if(direction == 'right'){
				if(newsTnContainerPos > newsTnContainerLimit){
					$('#news-tn-arrow-left').css('opacity', 1);
					$('.news-tn-display-container').animate({left: moveNewsTnLeft}, 500, function(){
						var newsTnContainerPos = $('.news-tn-display-container').css('left').replace('px', '');
						var newsTnContainerLimit = (newsTnContainerWidth - newsTnWidth)*-1;
						if(newsTnContainerPos <= newsTnContainerLimit){
							$('#news-tn-arrow-right').css('opacity', 0.5);
							$('#news-tn-arrow-right').removeClass('news-arrow-over');
						}
					});
				}
			} else if(direction == 'left'){
				if(newsTnContainerPos < 0){
					$('#news-tn-arrow-right').css('opacity', 1);
					$('.news-tn-display-container').animate({left: moveNewsTnRight}, 500, function(){
						var newsTnContainerPos = $('.news-tn-display-container').css('left').replace('px', '');
						if(newsTnContainerPos >= 0){
							$('#news-tn-arrow-left').css('opacity', 0.5);
							$('#news-tn-arrow-left').removeClass('news-arrow-over');
						}
					});
				}
			}
		}
		return false;
	}
	
	$('#news-tn-arrow-left').click(function(e){
		newsTnAnimation('left');
		$(this).parent().children().children().children().children('.more').hide('slow');
		$(this).parent().children().children().children().children('.show-less').hide();
		$(this).parent().children().children().children().children('.show-more').show();
		setNavLocation("news", "news");
	});
	$('#news-tn-arrow-right').click(function(e){
		newsTnAnimation('right');
		$(this).parent().children().children().children().children('.more').hide('slow');
		$(this).parent().children().children().children().children('.show-less').hide();
		$(this).parent().children().children().children().children('.show-more').show();
		setNavLocation("news", "news");
	});
	$('#news-tn-arrow-left, #news-tn-arrow-right').hover(		
		function(){
			if($(this).css('opacity') == 1){
				$(this).addClass('news-arrow-over');
			}
		}, 
		function(){
			if($(this).css('opacity') == 1){
				$(this).removeClass('news-arrow-over');
			}
		}
	);
	
	
	// CULTURE & CAREERS ==========================================================================================================
	// ============================================================================================================================
	
	// fix me | not an ideal solution.
	// fun facts scrollbar does not work correctly when careers-showcase is initial hidden.
	// this shows and hides it quickly.
	// 	
	$('#careers-showcase').animate({height:'1px'}, 3, function(){
		$('#careers-showcase').hide();
	});
	$('.overview').animate({left:'-2827'}, 3);
	$('.thumb').animate({left: '676px'}, 3);
	// fast facts slider
	$('#careers-facts').tinyscrollbar({ 
		axis: 'x',
		scroll: false,
		sizethumb: 120 
	});
	
	// careers position open/close
	$('.position-hdr').click(function(e){
		$(this).parent().children('.position-body').toggle();
	});

	// careers position sorter
	$('#position-sorter .sort-east').click(function(e){
		$('.pjaeast').css('display', 'block');
		$('.pjawest').css('display', 'none');
		$(this).addClass('active');
		$('#position-sorter .sort-west').removeClass('active');
		$('#position-sorter .sort-all').removeClass('active');
	});
	$('#position-sorter .sort-west').click(function(e){
		$('.pjawest').css('display', 'block');
		$('.pjaeast').css('display', 'none');
		$(this).addClass('active');
		$('#position-sorter .sort-east').removeClass('active');
		$('#position-sorter .sort-all').removeClass('active');
	});
	$('#position-sorter .sort-all').click(function(e){
		$('.pjaeast').css('display', 'block');
		$('.pjawest').css('display', 'block');
		$(this).addClass('active');
		$('#position-sorter .sort-east').removeClass('active');
		$('#position-sorter .sort-west').removeClass('active');
	});
	
	// careers culture arrows click
	var cultureTnWidth = $('#careers-culture-display').width();
	var moveCultureTnLeft = '-=' + cultureTnWidth;
	var moveCultureTnRight = '+=' + cultureTnWidth;
	var numCultureTns = $('#careers-culture-container > div').size();
	var cultureTnContainerWidth = numCultureTns * cultureTnWidth;
	$('#careers-culture-container').css('width', cultureTnContainerWidth);
	$('#careers-culture-left').css('opacity', 0.5);

		
	function cultureAnimation(direction){
		if(jwplayer().getState() == "PLAYING" || jwplayer().getState() == "BUFFERING") {
			jwplayer().pause();
		}
		if (!$('#careers-culture-container').is(':animated')){
			var cultureTnContainerPos = $('#careers-culture-container').css('left').replace('px', '');
			var cultureTnContainerLimit = (cultureTnContainerWidth - cultureTnWidth)*-1;
			if(direction == 'right'){
				if(cultureTnContainerPos > cultureTnContainerLimit){
					$('#careers-culture-left').css('opacity', 1);
					$('#careers-culture-container').animate({left: moveCultureTnLeft}, 500, function(){
						var cultureTnContainerPos = $('#careers-culture-container').css('left').replace('px', '');
						var cultureTnContainerLimit = (cultureTnContainerWidth - cultureTnWidth)*-1;
						if(cultureTnContainerPos <= cultureTnContainerLimit){
							$('#careers-culture-right').css('opacity', 0.5);
							$('#careers-culture-right').removeClass('culture-arrow-over');
						}
					});
				}
			} else if(direction == 'left'){
				if(cultureTnContainerPos < 0){
					$('#careers-culture-right').css('opacity', 1);
					$('#careers-culture-container').animate({left: moveCultureTnRight}, 500, function(){
						var cultureTnContainerPos = $('#careers-culture-container').css('left').replace('px', '');
						if(cultureTnContainerPos >= 0){
							$('#careers-culture-left').css('opacity', 0.5);
							$('#careers-culture-left').removeClass('culture-arrow-over');
						}
					});
				}
			}
		}
		return false;
	}
	//
	$('#careers-culture-left').click(function(e){
		cultureAnimation('left');
	});
	$('#careers-culture-right').click(function(e){
		cultureAnimation('right');
	});
	$('#careers-culture-left, #careers-culture-right').hover(		
		function(){
			if($(this).css('opacity') == 1){
				$(this).addClass('culture-arrow-over');
			}
		}, 
		function(){
			if($(this).css('opacity') == 1){
				$(this).removeClass('culture-arrow-over');
			}
		}
	);
	// careers tn click
	var careersSection = 0;
	$('.careers-tn').click(function(e){
		var careersSectionToShowcase = $(this).attr('id');
		if(careersSectionToShowcase == 'culture'){
			if(careersSection == 0){
				$('#careers-showcase-container').animate({'left': '-=2440px'}, 'slow');
			}
			if(careersSection == 1){
				$('#careers-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			careersSection = 2;
			setNavLocation("careers", "careers/culture");
		} else if(careersSectionToShowcase == 'jobs'){
			if(careersSection == 0){
				$('#careers-showcase-container').animate({'left': '-=1220px'}, 'slow');
			}
			if(careersSection == 2){
				$('#careers-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			careersSection = 1;
			setNavLocation("careers", "careers/jobs");
		} else if(careersSectionToShowcase == 'facts'){
			if(careersSection == 1){
				$('#careers-showcase-container').animate({'left': '+=1220px'}, 'slow');
			}
			if(careersSection == 2){
				$('#careers-showcase-container').animate({'left': '+=2440px'}, 'slow');
			}
			careersSection = 0;
			setNavLocation("careers", "careers/facts");
		}

		$('#careers-showcase').show();
		$('#careers-showcase').animate({height:'450px'}, 500, function() {
			$.scrollTo($('#careers-section'), 500, {axis: 'y', easing: ''});
		});
		
	});	

	// careers showcase close
	$('#careers-showcase .close').click(function(e){
		$('#careers-showcase').animate({height:'1px'}, 500, function() {
			var whereTo = $('#careers');
			$('#careers-showcase').hide();
			$.scrollTo($('#careers-section'), 500, {axis: 'y', easing: ''});
		});
		setNavLocation("careers", "careers");
	});
	
	// careers facts lazy load.
	var careersFactsLoaded = false;
	$('.careers-tn').click(function(e){
		if(!careersFactsLoaded){
			// change img src to larger image
			$('.overview img').attr('src', '/images/careers-fun-facts.jpg');
			// add id to larger image
			$('.overview img').attr('id', 'careers-fun-facts-jpg');
			// hide the loader div once the new image is loaded.
			$('#careers-fun-facts-jpg').load(function() {
				$('#careers-facts-loader').remove();
				careersFactsLoaded = true;
			});
		}
	});


	// CONTACT ==========================================================================================================
	// ==================================================================================================================
	
	var contactState = 'default';
	var westContactGoogleMapLoaded = false;

	function scrollToContact(){
		contactTargetLink = '#contact';
		$.scrollTo($('#contact-section'), 500, {axis: 'y', easing: ''});
	}
	
	// west click
	$('#contact-pja-west, #contact-pja-west-info').click(function(e){
		if(!westContactGoogleMapLoaded){
			$('#contact-pja-west-map').html('<iframe width="560" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?q=214+Grant+Avenue,+Suite+450+San+Francisco,+CA+94108-4628&amp;layer=c&amp;sll=37.788993,-122.405157&amp;cbp=11,96,,0,0&amp;cbll=37.789004,-122.405296&amp;gl=us&amp;sspn=0.006295,0.006295&amp;ie=UTF8&amp;hq=&amp;hnear=214+Grant+Ave,+San+Francisco,+California+94108&amp;t=h&amp;vpsrc=0&amp;panoid=GQdENfLUkj267x3Y1SMX5Q&amp;source=embed&amp;ll=37.765456,-122.405291&amp;spn=0.030533,0.048065&amp;z=14&amp;output=svembed"></iframe><br /><small><a href="http://maps.google.com/maps?q=214+Grant+Avenue,+Suite+450+San+Francisco,+CA+94108-4628&amp;layer=c&amp;sll=37.788993,-122.405157&amp;cbp=11,96,,0,0&amp;cbll=37.789004,-122.405296&amp;gl=us&amp;sspn=0.006295,0.006295&amp;ie=UTF8&amp;hq=&amp;hnear=214+Grant+Ave,+San+Francisco,+California+94108&amp;t=h&amp;vpsrc=0&amp;panoid=GQdENfLUkj267x3Y1SMX5Q&amp;source=embed&amp;ll=37.765456,-122.405291&amp;spn=0.030533,0.048065&amp;z=14" style="color:#0000FF;text-align:left">View Larger Map</a></small>');
			westContactGoogleMapLoaded = true;
		}
		if (!$('#contact-pja-west-info').is(':animated')){
			if(contactState == 'default'){
				//east
				$('#contact-pja-east').css({'z-index' : 1});
				$('#contact-pja-east-info').css({'z-index' : 0});
				
				// west
				$('#contact-pja-west').css({'z-index' : 3});
				$('#contact-pja-west-info').css({'z-index' : 2});
					
				// animate		
				$('#contact-pja-west-info').animate({'left': '+=620px'}, 500);
				
				contactState = 'west';
			} else if(contactState == 'west'){
				scrollToContact();
				$('#contact-pja-west-info').animate({'left': '-=620px'}, 700, function() {
					if(westContactView == 'map'){
						$('#contact-pja-west-container').animate({'left': '+=560px'}, 700);
						var viewMapCta = 'VIEW THE MAP';
						$('#view-west-map').html(viewMapCta);
						westContactView = 'img';
					}
				});
				contactState = 'default';
			}
			scrollToContact();
			$('#contact-west-btn-img').rotateRight(180);
			setNavLocation("contact", "contact");
		}
	});
	
	// west view map click
	var westContactView = 'img';
	$('#view-west-map').click(function(e){
		if (!$('#contact-pja-west-container').is(':animated')){
			if(westContactView == 'img'){
				$('#contact-pja-west-container').animate({'left': '-=560px'}, 700);
				var viewMapCta = 'CLOSE MAP';
				$(this).html(viewMapCta);	
				westContactView = 'map';
			} else if(westContactView == 'map'){
				$('#contact-pja-west-container').animate({'left': '+=560px'}, 700);
				var viewMapCta = 'VIEW THE MAP';
				$(this).html(viewMapCta);
				westContactView = 'img';
			}
		}		
		return false;
	});
	// east arrow click
	$('#contact-pja-east').click(function(e){
		if (!$('#contact-pja-east-info').is(':animated')){
			if(contactState == 'default'){
				scrollToContact();
				//east
				$('#contact-pja-east').css({'z-index' : 3});
				$('#contact-pja-east-info').css({'z-index' : 2});
				
				// west
				$('#contact-pja-west').css({'z-index' : 1});
				$('#contact-pja-west-info').css({'z-index' : 0});
					
				// animate		
				$('#contact-pja-east-info').animate({'left': '-=620px'}, 500);
				
				// rotate
				$('#contact-east-btn-img').rotateLeft(180);
				
				contactState = 'east';
			}
		}
		setNavLocation("contact", "contact");
	});
	$('#contact-pja-east-info').click(function(e){
		if(contactState == 'east'){
			scrollToContact();
			$('#contact-pja-east-info').animate({'left': '+=620px'}, 700, function() {
				if(eastContactView == 'map'){
					$('#contact-pja-east-container').animate({'left': '+=560px'}, 700);
					var viewMapCta = 'VIEW THE MAP';
					$('#view-east-map').html(viewMapCta);
					eastContactView = 'img';
				}
			});
			$('#contact-east-btn-img').rotateLeft(180);
			contactState = 'default';
		} else if(contactState == 'default'){
			scrollToContact();
			//east
			$('#contact-pja-east').css({'z-index' : 3});
			$('#contact-pja-east-info').css({'z-index' : 2});
			
			// west
			$('#contact-pja-west').css({'z-index' : 1});
			$('#contact-pja-west-info').css({'z-index' : 0});
				
			// animate		
			$('#contact-pja-east-info').animate({'left': '-=620px'}, 500);
			
			// rotate
			$('#contact-east-btn-img').rotateLeft(180);
			
			contactState = 'east';
		}
		setNavLocation("contact", "contact");
	});

	// east view map click
	var eastContactView = 'img';
	$('#view-east-map').click(function(e){
		if (!$('#contact-pja-east-container').is(':animated')){
			if(eastContactView == 'img'){
				$('#contact-pja-east-container').animate({'left': '-=560px'}, 700);
				var viewMapCta = 'CLOSE MAP';
				$(this).html(viewMapCta);	
				eastContactView = 'map';
			} else if(eastContactView == 'map'){
				$('#contact-pja-east-container').animate({'left': '+=560px'}, 700);
				var viewMapCta = 'VIEW THE MAP';
				$(this).html(viewMapCta);
				eastContactView = 'img';
			}
		}
		return false;
	});
	
	var eastContactGoogleMapLoaded = false;
	$('#contact-pja-east-info, #contact-pja-east').click(function(e){
		if(!eastContactGoogleMapLoaded){
			$('#contact-pja-east-map').html('<iframe width="560" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?client=safari&amp;q=12+arrow+st+cambridge+ma&amp;oe=UTF-8&amp;ie=UTF8&amp;hq=&amp;hnear=12+Arrow+St,+Cambridge,+Middlesex,+Massachusetts+02138&amp;gl=us&amp;t=h&amp;vpsrc=0&amp;layer=c&amp;cbll=42.371208,-71.114815&amp;panoid=z5PKsurSLZIZlwg_PE14Iw&amp;cbp=11,163.26,,0,-4.64&amp;source=embed&amp;ll=42.340561,-71.114845&amp;spn=0.028549,0.048065&amp;z=14&amp;output=svembed"></iframe><br /><small><a href="http://maps.google.com/maps?client=safari&amp;q=12+arrow+st+cambridge+ma&amp;oe=UTF-8&amp;ie=UTF8&amp;hq=&amp;hnear=12+Arrow+St,+Cambridge,+Middlesex,+Massachusetts+02138&amp;gl=us&amp;t=h&amp;vpsrc=0&amp;layer=c&amp;cbll=42.371208,-71.114815&amp;panoid=z5PKsurSLZIZlwg_PE14Iw&amp;cbp=11,163.26,,0,-4.64&amp;source=embed&amp;ll=42.340561,-71.114845&amp;spn=0.028549,0.048065&amp;z=14" style="color:#0000FF;text-align:left">View Larger Map</a></small>');
			eastContactGoogleMapLoaded = true;
		}
	});
	
	
	// HANDLE DEEP LINKS
	if(History.getState().hash != "/" && History.getState().hash != "./") { //html5 is / 4 is ./
		navPathRaw = History.getState().hash;
		navPath = getNavPath(navPathRaw);
		// here we're looping through all of the elements in the nav path
		// and checking to see if anything of them are clickable
		var event;
		for(i=navPath.length-1; i>=0; i--) {
			if($('#' + navPath[i]).data('events') != undefined) {
				event = $('#' + navPath[i]).data('events');
				if(event.click != undefined) {
					$("#" + navPath[i]).trigger("click");
					break;
				}
			}
		}
	} else {
		// we're on the initial page, track a page it
		_gaq.push(['_trackPageview']);
	}
	
	// ==========================================================================================================
});


