function onTemplateLoaded(experienceID) {
	
    var bcExp = brightcove.getExperience(experienceID);
     
    var modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
    var modExp = bcExp.getModule(APIModules.EXPERIENCE);
    var modCon = bcExp.getModule(APIModules.CONTENT);

	if (!Modernizr.touch) {
		modExp.addEventListener(BCExperienceEvent.CONTENT_LOAD, 
			function onContentLoad(evt) {
			  	contentLoad(modVP,modCon);
			}
		);
	}
}
function contentLoad(modVP,modCon) {

	var currentVideo = modVP.getCurrentVideo();
	modVP.pause();
	
    var $video = $("#video-" + currentVideo.id).parent();
	
	$video.children('.play').hide();
	
	if($video.children('img').length) {
		$video.children('img').fadeOut(500,function(){
			modVP.play();
			$video.children('.close').show();
			if(! $video.hasClass('video')) $video.addClass('video');
			$video.removeClass('loading').addClass("loaded");
		});
	} else {
		modVP.play();
		$video.children('.close').show();
		if(! $video.hasClass('video')) $video.addClass('video');
		$video.removeClass('loading').addClass("loaded");
	}

	modCon.getMediaAsynch(1488633950);
	
	$video.children('.close').click(function(){
		$video.removeClass('loaded');
		$(this).fadeOut(500).remove();
		$("#video-" + currentVideo.id).remove();
		$video.children('.play').show();
		$video.children('img').fadeIn(500);
		
		if($video.parents("#banners").length) { 
			$('#banners').cycle('resume');
		}
	});
	
}


$(document).ready(function() {
	
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	var scrollElem = scrollableElement('html', 'body');
	
	if(!$.browser.msie) {
	setTimeout(function() {
		if (location.hash) {
			window.scrollTo(0, 0);
			
			var target = $(location.hash);
			if (target.length) {
				var targetOffset = $(target).offset().top - $("header").height();
				
				$(scrollElem).animate({scrollTop: targetOffset}, 400);
			}
		}
	}, 1);
	}

	$('a[href*=#]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if ( locationPath == thisPath
 		&& (location.hostname == this.hostname || !this.hostname)
		&& this.hash.replace(/#/,'') ) {
			var $target = $(this.hash), target = this.hash;
			if ($target.length) {
				var targetOffset = $target.offset().top - $("header").height();
				$(this).click(function(event) {
					event.preventDefault();
					$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
						location.hash = target;
					});
				});
			}
		}
	});

	function scrollableElement(els) {
		for (var i = 0, argLength = arguments.length; i <argLength; i++) {
			var el = arguments[i],
			$scrollElement = $(el);
			if ($scrollElement.scrollTop()> 0) {
				return el;
			} else {
				$scrollElement.scrollTop(1);
				var isScrollable = $scrollElement.scrollTop()> 0;
				$scrollElement.scrollTop(0);
				if (isScrollable) {
 					return el;
				}
			}
		}
		return [];
	}
	
	$(".play").live("click",function(e){
		e.preventDefault();

		var $video = $(this).parent();
		
		if($(this).parents("#banners").length) { 
			$('#banners').cycle('pause');
		}
		
		if($video.hasClass('loading') || $video.hasClass('loaded')) {
			return false;
		} else {
			$video.addClass('loading');
		}
		
		$video.append('<div class="video-player"></div>');
		
		var videoPlayer = $video.children('.video-player');
		
		var width = $(this).data('width');
		var height = $(this).data('height');
		var id = $(this).data('video');
		$video.prepend('<div class="close">Close</div>');
		
		$.getJSON("/videos/json?w=" + width + "&h=" + height + "&id=" + id , function(data){

			var player = brightcove.createElement("object");
			player.id = "video-" + data.videoId;

			videoPlayer.attr('id','video-' + data.videoId);
			
			var parameter;
			for (var i in data) {
				if(i != "videoId") {
					parameter = brightcove.createElement("param");
					parameter.name = i;
					parameter.value = data[i];
					player.appendChild(parameter);
				}
			}
			
			brightcove.createExperience(player, videoPlayer[0], true);
			
			if (Modernizr.touch) {
				$video.children('.play').hide();
				$video.children('img').hide();
			}
		});
	});
	
	
	var currentW = $('header nav ul li.current').width(),
		currentP = $('header nav ul li.current').position();
	
	$('header nav .border span').css({'left': currentP.left-1, 'width': currentW});
	$('header nav ul li').mouseenter(function(){
		var hoverW = $(this).width(),
			hoverP = $(this).position();
			
		$('header nav .border span').stop(true,true).animate({'left': hoverP.left-1, 'width': hoverW},100);
	});
	$('header nav ul').mouseleave(function(){
		$('header nav .border span').stop(true,true).delay(500).animate({'left': currentP.left-1, 'width': currentW},200);
	});
	
	$("#work-slideshow #show-hide").click(function(e){
		//e.preventDefault();
		var $parent = $(this).parent(),
			$slideshow = $(this).parent().find(".slideshow");
			
		if(!$parent.hasClass("open")) {
			$(this).text("Hide Screenshots & Videos")
			$parent.addClass("open");
			$slideshow.show();
		} else {
			$(this).text("Show Screenshots & Videos")
			$parent.removeClass("open");
			$slideshow.hide();
		}
		
	});
	
	$('#work-slideshow .slides').after('<ul id="slideshow-nav">').cycle({ 
	    fx:     'fade', 
	    speed:  500, 
	    timeout: 0,
		next: '.slideshow-next',
		prev: '.slideshow-prev',
		pager:  '#slideshow-nav',
		pagerAnchorBuilder: function(i) {
			return '<li><a href="#">' + parseInt(i+1) + '</a></li>';
		}
	});
	
	$('#work-list article a').each(function(){
		var $span = $(this).children('span');
		$span.css('bottom', "-"+$span.outerHeight()+'px');
	});
	
	var bottom = 0;
	
	$('#work-list article a').hover(function(){
		var $span = $(this).children('span');
		if(!$span.data('bottom')) $span.data('bottom',$span.css('bottom'));
		$span.stop().animate({'bottom':0},250);
	},function(){
		var $span = $(this).children('span');
		$span.stop().animate({'bottom':$span.data('bottom')},250);
	});
	
	$('#clients #see-all').toggle(function(e){
		e.preventDefault();
		
		$(this).text("See Less");
		$('#clients .client-list').animate({'height': $('#clients ul').height()},500);
	},function(e){
		e.preventDefault();
		
		$(this).text("See All");
		$('#clients .client-list').animate({'height': '280px'},500);
	});
	
	if ($.browser.msie) {
		$('#banners').cycle({ 
		    speed:  500, 
		    timeout: 7000, 
		    next:   '#banner-nav .next', 
		    prev:   '#banner-nav .prev' 
		});
	} else {
		$('#banners').cycle({ 
		    fx:     'fade', 
		    speed:  500, 
		    timeout: 7000, 
		    next:   '#banner-nav .next', 
		    prev:   '#banner-nav .prev'
		});
	}

	// What We Do
	$('.video-container:gt(0)').hide();
	
	$('.video-container:first').addClass('current');
	$('#videos ul li:first').addClass('current');
	
	// About Us
	$('#about #news ul').equalHeights();
	
	$('.people-container:not(#' + $('.people-container.current').attr('id') + ')').hide();
	
	//$('.people-container:first').addClass('current');
	//$('#about #people > ul li:first').addClass('current');
	
	if($('body').attr('id') == "about") {
	
	$.address.init(function(e) {
		
		$('#about #people > ul li a').address();
		
	}).change(function(e) {
		
		var value = $.address.state().replace(/^\/$/, '') + e.value;
		var id = value.split("/")[2];
		if(id == "") {
			id = $('.people-container:first').attr('id');
			value = value + id;
		}
		
		$('#people > ul li a').each(function() {
			if ($(this).attr('href') == value) {
				$(this).parent().addClass('current');
			} else {
				$(this).parent().removeClass('current');
			}
		});
		
		$('.people-container').each(function() {
			$(this).hide();
			
			$(' > ul li.current', this).removeClass('current');
			$(this).find('.bio').hide();
		});
		
		$('#' + id + '.people-container').addClass('current').fadeIn(500);
    });

	}


	
	$('.people-container > ul li a').click(function(e){
		e.preventDefault();
		
		var path = $(this).attr('href');
		var $parent = $(this).parent();
		var $siblings = $parent.siblings();
		var $bio = $parent.children('.bio');
		var h = 0;
		
		if($parent.hasClass('current')) {
			
			$parent.removeClass('current');
			$bio.slideUp(500);
			
		} else {
			
			$siblings.filter('.current').find('.bio').slideUp(500);
			$siblings.removeClass('current');
			$parent.addClass('current');
			
			if($bio.hasClass('loaded')) {
			
				$bio.slideDown(500,function() {
					$(this).addClass('open');
				});
			
			} else {
			
				var person = path.split("/")[5];
				
				$.ajax({ url: "/about-us/bio/" + person, dataType: 'html', context: $bio, success: function(data){
					$(this).append(data);
				
					$(this).addClass('loaded');
				
					$(this).slideDown(500,function(){
						$(this).addClass('open');
					});
				}});

			}
		
			$('.close', $parent).click(function(){
				$parent.removeClass('current');
				$bio.slideUp(500,function(){
					$(this).removeClass('open');
				});
			});
		}
	});
	
	// News
	var newsHeight = $('#news #entries, #news #entry').height();
	$('#news #sidebar').height(newsHeight + 35);
	
	
	$('#bloggers #select a').toggle(function(){
		$('#bloggers ul').fadeIn(250);
	},function(){
		$('#bloggers ul').fadeOut(250);
	});
	
	$('#mindshare #features').slider();
	
	// CONTACT FORM VALIDATION
	var returnVal = $("input[name='return']").val();
	
	$("input[name='return']").val(returnVal + '/ajax');
	
	$("#contact-form form").validate({
		rules: {
			"name": "required",
			"email": {
				required: true,
				email: true
	 		},
			"message": "required",
			"captcha": "required"
		},
		errorElement: "em",
		onkeyup: false,
		onfocusout: false,
		highlight: function(element, errorClass, validClass) {
			//$(element).siblings("label").addClass(errorClass);
			$(element).addClass(errorClass);
		},
		  unhighlight: function(element, errorClass, validClass) {
			//$(element).siblings("label").removeClass(errorClass);
			$(element).removeClass(errorClass);
		},
		submitHandler: function(form) {
		   	$(form).ajaxSubmit({
				target: '#thanks', 
				success: function() {
					$('#contact-form form').fadeOut('fast',function(){
						$('#thanks').fadeIn('slow'); 
					});
				}
			});
		}
	});
	
	if($('body').attr('id') == "mindshare" && !$('body').hasClass('entry')) {
	
	$.address.init(function(e) {
		
		$('#mindshare-nav li a').address();
		
		
	}).change(function(e) {
		
		var value = $.address.state().replace(/^\/$/, '') + e.value;
		var id = value.split("/")[2];
		
		$('#mindshare-nav li a').each(function() {
			var href = $(this).attr('href');
			if (href == value || (value == '/mindshare/' && href == '/mindshare/blog')) {
				$(this).parent().addClass('current');
			} else {
				$(this).parent().removeClass('current');
			}
		});
		
		$.ajax({
			cache: false,
			dataType: 'html',
			url: '/mindshare/entries/' + id,
			success: function(data) {
				$('#entries').html(data);
			}
		});

    });

	$('#entries #page-nav a').live("click",function(e){
		e.preventDefault();
		
		var path = $(this).attr("href"),
		cat = path.split("/")[5],
		page = path.split("/")[6];
		
		$.ajax({
			cache: false,
			dataType: 'html',
			url: '/mindshare/entries/' + cat + '/' + page,
			success: function(data) {
				var targetOffset = $('#mindshare-nav').offset().top;
				$(scrollElem).animate({scrollTop: targetOffset-20}, 400,function(){
					$('#entries').html(data);
				});
				
				
			}
		});
	});

	}

	$('#technologies').tinycarousel({
		duration: 500
	});
	//$('#technologies .tech').hide();
	
	
	/*$('#technologies h3 a').click(function(e){
		e.preventDefault();
		$parent = $(this).parent();
		
		$('.tech').slideToggle(250,function(){
			if($parent.hasClass('open')) {
				$('#technologies').tinycarousel();
			}

			$('.description').hide().css({'height':'0'});
			$('#technologies ul li.current').removeClass('current');
		});
		
		$parent.toggleClass('open');
	});*/
	
	$('#technologies ul li a').click(function(e){
		e.preventDefault();
		
		var $tech = $(this).parents('.tech'),
			$li = $(this).parent();
			
		$tech.find('.current').removeClass('current');
		
		var text = $li.find('p').outerHtml();
		
		$li.addClass('current');
				
		$tech.children('.description').html(text);
		$tech.children('.description').show().animate({'height':'67px'},250);
	});
	
	
	// WHAT WE DO FRAMEWORK
	
	var $framework = $("#framework-module"),
		$steps = $framework.children("#steps"),
		$links = $steps.find("li a"),
		$slideContainer = $("#slide-container"),
		$slideNav = $("#slide-nav"),
		$slideLinks = $("#slide-nav").find("li a");
	
	var slideWidth = $(".slide").outerWidth();
	
	var allPeople = [".solution-strategist",".delivery-manager",".hci-researcher",".ux-specialist",".ux-designer",".ux-technologist",".technical-architect",".software-engineer",".qa-engineer"]
		discoverPeople = [".solution-strategist",".delivery-manager",".ux-specialist",".technical-architect"],
		designPeople = [".solution-strategist",".delivery-manager",".hci-researcher",".ux-specialist",".ux-designer",".ux-technologist",".technical-architect",".qa-engineer"],
		developPeople = [".delivery-manager",".ux-designer",".ux-technologist",".technical-architect",".software-engineer",".qa-engineer"],
		deployPeople = [".delivery-manager",".technical-architect",".software-engineer",".qa-engineer"];
		
	var maxHeight = 0;
	$('.slide').each(function() {
		if (maxHeight < $(this).outerHeight(true)) {maxHeight = $(this).outerHeight(true)}
	});

	$slideContainer.height(maxHeight+15);
	
	$(".slide:first").addClass("current").css("left",0);
	$steps.children(":first").addClass("current");
	$slideNav.children(":first").addClass("current");
	
	var animating = false;
		
	$links.click(function(e){
		e.preventDefault();
		
		var link = $(this).parent().attr("class");
		var $span = $(this).parent().find('div'),
			$spans = $steps.find('div');
			
		if(animating == true || $(this).parent().hasClass("current")) {
			return false;
		}
		
		$steps.find("li.current").removeClass("current");
		$slideNav.find("li.current").removeClass("current");
		
		$(this).parent().addClass("current");
		
		if(link == "overview") {
			$(allPeople.join(",")).removeClass("selected");
			
			$steps.removeClass("all");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.fadeOut(500);
			} else {
				$spans.hide();
			}
			
		} else if(link == "flexibility") {
			$(allPeople.join(",")).addClass("selected");
			$steps.addClass("all");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.not(".current").fadeOut(500);
				$spans.addClass("current").fadeIn(500);
			} else {
				$spans.not(".current").hide();
				$spans.addClass("current").show();
			}
			
		} else {
			var people = eval(link + "People").join(",");
			$steps.removeClass("all");
			$(allPeople.join(",")).removeClass("selected");
			$(people).addClass("selected");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.not($span).fadeOut(500);
				$span.addClass("current").fadeIn(500);
			} else {
				$spans.not($span).hide();
				$span.addClass("current").show();
			}
			
		}
		
		$newSlide = $("#" + link + "-slide");
		$currentSlide = $(".slide.current");
		
		$currentSlide.removeClass("current");
		$newSlide.addClass("current");
		$slideNav.children("li[data-id='" + link + "']").addClass("current");
		
		$newSlide.insertAfter($currentSlide);
		
		animating = true;
		
		$currentSlide.animate({'left': '-' + slideWidth + 'px'},500,function(){
			$(this).css('left', '940px');
			animating = false;
		});
		$newSlide.animate({'left': '0'},500,function(){
			animating = false;
		});
	});
	
	$slideLinks.click(function(e){
		e.preventDefault();
		
		var link = $(this).parent().attr("data-id");
		var $span = $steps.children("li."+link).find('div'),
			$spans = $steps.find('div');
			
		if(animating == true || $(this).parent().hasClass("current")) {
			return false;
		}
		
		$steps.find("li.current").removeClass("current");
		$slideNav.find("li.current").removeClass("current");
		
		$(this).parent().addClass("current");
		
		if(link == "overview") {
			$(allPeople.join(",")).removeClass("selected");
			
			$steps.removeClass("all");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.fadeOut(500);
			} else {
				$spans.hide();
			}
			
		} else if(link == "flexibility") {
			$(allPeople.join(",")).addClass("selected");
			$steps.addClass("all");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.not(".current").fadeOut(500);
				$spans.addClass("current").fadeIn(500);
			} else {
				$spans.not(".current").hide();
				$spans.addClass("current").show();
			}
			
		} else {
			var people = eval(link + "People").join(",");
			$steps.removeClass("all");
			$(allPeople.join(",")).removeClass("selected");
			$(people).addClass("selected");
			
			if(!$.browser.msie && !Modernizr.touch) {
				$spans.not($span).fadeOut(500);
				$span.addClass("current").fadeIn(500);
			} else {
				$spans.not($span).hide();
				$span.addClass("current").show();
			}
			
		}
		
		$newSlide = $("#" + link + "-slide");
		$currentSlide = $(".slide.current");
		
		$currentSlide.removeClass("current");
		$newSlide.addClass("current");
		$slideNav.children("li[data-id='" + link + "']").addClass("current");
		
		$newSlide.insertAfter($currentSlide);
		
		animating = true;
		
		$currentSlide.animate({'left': '-' + slideWidth + 'px'},500,function(){
			$(this).css('left', '940px');
			animating = false;
		});
		$newSlide.animate({'left': '0'},500,function(){
			animating = false;
		});
	});
	
	var startcopy = $("#values .start").html();
	var animatingvalues = false;
	
	$('#values li a').hoverIntent({
	     over: startHover,
	     out: endHover,
	     timeout: 600
	});
	$('#values li a').click(function(e){
		e.preventDefault();
	});
	
	function startHover(){
		
		$parent = $(this).parent();
		$("#values li a.selected").removeClass("selected");
		$(this).addClass("selected");
		
		var copy = $parent.children("div").html();
		animatingvalues = true;
		$("#values .values div").slideUp(300,function(){
			$("#values .values").removeClass("start").addClass("selected");
			$(this).html(copy).slideDown(300,function(){
				animatingvalues = false;
			});
		});
	}
	function endHover(){
		if(animatingvalues) return false;
		
		$("#values li a.selected").removeClass("selected");
		animatingvalues = true;
		$("#values .values div").slideUp(300,function(){
			$("#values .values").removeClass("selected").addClass("start");
			$(this).html(startcopy).slideDown(300,function(){
				animatingvalues = false;
			});
		});
	}
	
	$("#work input").placeholder();

	$('.back-btn').click(function(){
		parent.history.back();
		return false;
	});
	
	// OPEN EXTERNAL LINKS IN A NEW WINDOW
	$('body').delegate('a','click',function() {
		var a = new RegExp('/' + window.location.host + '|javascript/');
		if(!a.test(this.href)) {
			event.preventDefault();
			event.stopPropagation();
			window.open(this.href, '_blank');
		}
	});
});
