//XML -> JSON FUNCTION. REMOVE FOR DEV/PROD.
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(10.M)(w($){$.N({11:w(j,k){5(!j)t{};w B(d,e){5(!d)t y;6 f=\'\',2=y,E=y;6 g=d.x,12=l(d.O||d.P);6 h=d.v||d.F||\'\';5(d.G){5(d.G.7>0){$.Q(d.G,w(n,a){6 b=a.x,u=l(a.O||a.P);6 c=a.v||a.F||\'\';5(b==8){t}z 5(b==3||b==4||!u){5(c.13(/^\\s+$/)){t};f+=c.H(/^\\s+/,\'\').H(/\\s+$/,\'\')}z{2=2||{};5(2[u]){5(!2[u].7)2[u]=p(2[u]);2[u][2[u].7]=B(a,R);2[u].7=2[u].7}z{2[u]=B(a)}}})}};5(d.I){5(d.I.7>0){E={};2=2||{};$.Q(d.I,w(a,b){6 c=l(b.14),C=b.15;E[c]=C;5(2[c]){5(!2[c].7)2[c]=p(2[c]);2[c][2[c].7]=C;2[c].7=2[c].7}z{2[c]=C}})}};5(2){2=$.N((f!=\'\'?A J(f):{}),2||{});f=(2.v)?(D(2.v)==\'16\'?2.v:[2.v||\'\']).17([f]):f;5(f)2.v=f;f=\'\'};6 i=2||f;5(k){5(f)i={};f=i.v||f||\'\';5(f)i.v=f;5(!e)i=p(i)};t i};6 l=w(s){t J(s||\'\').H(/-/g,"18")};6 m=w(s){t(D s=="19")||J((s&&D s=="K")?s:\'\').1a(/^((-)?([0-9]*)((\\.{0,1})([0-9]+))?$)/)};6 p=w(o){5(!o.7)o=[o];o.7=o.7;t o};5(D j==\'K\')j=$.S(j);5(!j.x)t;5(j.x==3||j.x==4)t j.F;6 q=(j.x==9)?j.1b:j;6 r=B(q,R);j=y;q=y;t r},S:w(a){6 b;T{6 c=($.U.V)?A 1c("1d.1e"):A 1f();c.1g=W}X(e){Y A L("Z 1h 1i 1j 1k 1l")};T{5($.U.V)b=(c.1m(a))?c:W;z b=c.1n(a,"v/1o")}X(e){Y A L("L 1p Z K")};t b}})})(M);',62,88,'||obj|||if|var|length||||||||||||||||||||||return|cnn|text|function|nodeType|null|else|new|parseXML|atv|typeof|att|nodeValue|childNodes|replace|attributes|String|string|Error|jQuery|extend|localName|nodeName|each|true|text2xml|try|browser|msie|false|catch|throw|XML|window|xml2json|nn|match|name|value|object|concat|_|number|test|documentElement|ActiveXObject|Microsoft|XMLDOM|DOMParser|async|Parser|could|not|be|instantiated|loadXML|parseFromString|xml|parsing'.split('|'),0,{}))


//Detect Support for Touch Events, or Lack Thereof.
var supportsTouch = ('createTouch' in document);
var downEventVar = supportsTouch ? 'touchstart' : 'mousedown';
var dragEventVar = supportsTouch ? 'touchmove' : 'mousemove';
var dropEventVar = supportsTouch ? 'touchend' : 'mouseup';

//Detect iPhone + iPod Touch
function isAnIPhone() { if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { return true } else { return false } };
function isAnIPad() { if((navigator.userAgent.match(/iPad/i))) { return true } else { return false } };

var BK = BK || {};

BK.tlVs = {

	//Timeline Constants

	'animSpeed': isAnIPad() ? 0 : 100,
	'cssTranSpeed' : isAnIPad() ? 0 : .225,
	'zoomLevel' : 0.6,
	'cID' : 'timelineModule',
	
	//Timeline Variables
	
	'currentTile' : 1,
	'currentZoomLevel' : '',
	'mousePct' : '',
	'inThePast' : false, 
	'inTheFuture' : false,
	'returnPoint' : '',
	'isTracking' : false,
	'scrubberWidth' : '',
	'sliderLeft' : '',
	'sliderWidth' : '',
	'theActivePos' : '',
	'timelineXML' : '',
	'timelineJSON' : '',
	'totalLength' : 0,
	'timelineObjectsLength' : 0,
	'trackingObject' : '',
	'timelinePositions' : [],
	'videoBoxes' : [],
	'width' : '',
	'parentwidth' : '',
	'containerboxwidth' : ''	
}

BK.corpTL = {

	init : function() {
		//if browser supports HTML5, show the JS timeline. Else show error image.
		if ( testFor.htmlvideo() ) {
			BK.corpTL.setupTimelineDOM();
			$( '#' + BK.tlVs.cID ).show();
			BK.corpTL.setupTimeline();
		} else {
			$('.timelineNoFlash').show();
		}
	},

	//Build out timeline DOM structure
	setupTimelineDOM : function() {

		var timelineDOMStructure = '';
		timelineDOMStructure += '<div class="slideContainer">';
		timelineDOMStructure += '<div class="slideContainerBackdrop"></div>';
		timelineDOMStructure += '<div class="slideContainerBackdrop backDrop-scrubbing"></div>';
		timelineDOMStructure += '<div class="slideContainerBackdrop backDrop-past"></div>';
		timelineDOMStructure += '<div class="slideContainerBackdrop backDrop-future"></div>';
		timelineDOMStructure += '<ul class="list"></ul>';
		timelineDOMStructure += '</div>';
		timelineDOMStructure += '<!-- End Timeline Carousel. -->';
		timelineDOMStructure += '<div class="timelineDashesWrapper">';
		timelineDOMStructure += '<div class="timelineDashes"></div>';
		timelineDOMStructure += '</div>';
		timelineDOMStructure += '<!-- End Timeline Dashes Container. -->';
		timelineDOMStructure += '<div class="controls roundBottomLeft4px roundBottomRight4px">';
		timelineDOMStructure += '<div class="leftButton roundBottomLeft4px"><span></span></div>';
		timelineDOMStructure += '<div class="rightButton roundBottomRight4px"><span></span></div>';
		timelineDOMStructure += '<div class="scrubbingArea">';
		timelineDOMStructure += '<span class="yearMark markPast">10,000 BC</span>';
		timelineDOMStructure += '<span class="yearMark mark1">1950</span>';
		timelineDOMStructure += '<span class="yearMark mark2">1965</span>';
		timelineDOMStructure += '<span class="yearMark mark3">1980</span>';
		timelineDOMStructure += '<span class="yearMark mark4">1995</span>';
		timelineDOMStructure += '<span class="yearMark mark5">Now</span>';
		timelineDOMStructure += '<span class="yearMark markFuture">2054</span>';
		timelineDOMStructure += '<div class="scrubberContainer">';
		timelineDOMStructure += '<div class="scrubberHolder">';
		timelineDOMStructure += '<div class="scrubberInternal"></div>';
		timelineDOMStructure += '</div></div></div></div>';
		timelineDOMStructure += '<!-- End Controls -->';
		
		$( '#' + BK.tlVs.cID ).addClass('roundBottomLeft6px roundBottomRight6px').hide().html(timelineDOMStructure);

	},

	//Build out content of the timeline carousel.
	setupTimeline : function() {
		
		BK.corpTL.dots('past'); BK.corpTL.dots('future');
	
		$.ajax({
			
			url: '/page_templates/cultures'+CulturePrefix+'flash/xml/bk_timeline_config.xml',
			//url: 'xml/bk_timeline_config.xml',
			dataType: "xml",
			success: function(data) { 
			
				BK.tlVs.timelineXML = $(data);
				BK.tlVs.timelineJSON = $.xml2json(data);
				BK.tlVs.timelineJSON = BK.tlVs.timelineJSON.commondata
				var yearArray = [];
				
				var jsonHolder = BK.tlVs.timelineJSON;
				
				//add Past and Future easter-egg tiles.
				var futureTile = '';
				futureTile += '<div class="itemSpecial tileSpecial tile-future"><div class="leftBlock"><div class="tileVideo tileVideo-0"></div>';
				futureTile += '<img src="/cms_prep/en/us/cms_out/digital_assets/graphics/company_timeline/2054.jpg">';
				futureTile += '</div>';
				futureTile += '<div class="rightBlock blue">';
				futureTile += '<span class="date">2054</span>';
				futureTile += '<span class="title">BKC* saves the world</span>';
				futureTile += '<span class="description">BK&reg; appeases alien race with WHOPPER&reg; Sandwiches to avert intergalactic war.</span>';
				futureTile += '<span class="fineprint">*BKC - Burger King Corporation</span>';
				futureTile += '</div></div>';
		
				var pastTile = '';
				pastTile += '<div class="itemSpecial tileSpecial tile-past"><div class="leftBlock"><div class="tileVideo tileVideo-0"></div>';
				pastTile += '<img src="/cms_prep/en/us/cms_out/digital_assets/graphics/company_timeline/10000bc.jpg">';
				pastTile += '</div>';
				pastTile += '<div class="rightBlock orange">';
				pastTile += '<span class="date">pre-10,000 BC</span>';
				pastTile += '<span class="title">Man discovers <br/>fire</span><span class="description">Instinct tells him to <br/>flame-broil meat.</span>';
				pastTile += '</div></div>';

				$(futureTile).insertBefore('ul.list');
				$(pastTile).insertBefore('ul.list');

				for (var i = 0; i < jsonHolder.item.length; i ++)
				{
					yearArray.push(jsonHolder.item[i].date * 1);
					
					var imgPath = '/cms_prep/en/us/cms_out/digital_assets/graphics/company_timeline/';
					
					var leftTile = '<img src="' + imgPath + jsonHolder.item[i].image + '" />';
				
			        var tileVidHTML = '';
			        
			        if (typeof jsonHolder.item[i].video != 'undefined') {
					        
				        var vidPath = "/cms_prep/en/us/cms_out/digital_assets/video/company_timeline/"			        
				        var tileVidURL = jsonHolder.item[i].video;
				        var oggLink = vidPath + tileVidURL.replace('flv','ogg');
				        var mp4Link = vidPath + tileVidURL.replace('flv','mp4');
		        	
				        tileVidHTML += '<div class="video-js-box" style="height:100%">';
				        tileVidHTML += '<video class="video-js" width="287px" height=100%" poster="'+imgPath+jsonHolder.item[i].image+'" >';
			            tileVidHTML += '<source src="' + mp4Link + '" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\'>';
			            tileVidHTML += '<source src="' + oggLink + '" type=\'video/ogg; codecs="theora, vorbis"\'>';
			            tileVidHTML += '</object>';
			            tileVidHTML += '</video>';
			            tileVidHTML += '<div class="replay"><span class="replayArrow"></span></div>';
			            tileVidHTML += '</div>';
			
						//leftTile = '';
			 
	                };
	                
	                BK.tlVs.videoBoxes.push(tileVidHTML);
	                		
					var timelineTileBuild = '';
					timelineTileBuild += '<li class="item tile-'+i+'">';
					timelineTileBuild += '<div class="tileBlackout"></div>';
					timelineTileBuild += '<div class="slideOverlay '+jsonHolder.item[i].bgcolor+'">';
					timelineTileBuild += '<span class="date">'+Math.floor(jsonHolder.item[i].date * 1)+'</span><h3>'+jsonHolder.item[i].title+'</h3></div>';
					timelineTileBuild += '<div class="leftBlock"><div class="tileVideo tileVideo-'+i+'"></div>'+leftTile+'</div>';
					timelineTileBuild += '<div class="rightBlock '+jsonHolder.item[i].bgcolor+'">';
					timelineTileBuild += '<span class="date">'+Math.floor(jsonHolder.item[i].date * 1)+'</span>';
					timelineTileBuild += '<span class="title">'+jsonHolder.item[i].title+'</span>';
					timelineTileBuild += '<span class="description">'+jsonHolder.item[i].copy+'</span>';
					
					if ( jsonHolder.item[i].disclaimer ) timelineTileBuild += '<span class="fineprint">*BKC - Burger King Corporation</span>';
					
					timelineTileBuild += '</div>';
					timelineTileBuild += '</li>';
					
					$('ul.list').append(timelineTileBuild)
					
					if (!isAnIPad()) {
						$('.tile-'+i+', .itemSpecial').addClass('hasShadow');
					}
					$('.tile-'+i+' .rightBlock, .itemSpecial .rightBlock').addClass('hasGrad');
				}
				
				BK.tlVs.totalLength = $('ul.list li.item').length;
				
				//Add 'high end' features to non-ipad devices.
				if (!isAnIPad() || isAnIPad()) { $('.slideContainerBackdrop, .backDrop-past, .backDrop-future').addClass('highEnd'); };
				
				BK.corpTL.setupTimelinePositions(yearArray)
				BK.corpTL.attachTimelineListeners();
				
				BK.tlVs.width = $('ul.list li.item:first').width() + 30;
				BK.tlVs.parentwidth = $('ul.list li.item:first').parent().width();
				BK.tlVs.containerboxwidth = $('ul.list li.item:first').parent().parent().width();
				
				BK.corpTL.repositionCarousel(1,1);		
			}
		});
	
	},
	
	//Add 'dashes' above the timeline to denote where the tiles are placed chronologically.
	setupTimelinePositions : function(yearArray) {
	
		var theMax = Math.max.apply( Math, yearArray );
		var theMin = 1950;
		var theRange = theMax - theMin;
		
		function sortNumber(a,b) { return a - b; };
		
		for (var i = 0; i < yearArray.length; i++) {
		
			var position = 100*((yearArray[i] - theMin) / theRange);
			var alikeArray = [];
			
			for (var j = 0; j < yearArray.length; j ++) {
				if (yearArray[j] == yearArray[i]) { 
					alikeArray.push(j); 
				};
			}
		
			if (alikeArray.length > 1) { 
				theMaxAlike = Math.max.apply(Math,alikeArray);
				position -= ((theMaxAlike - i) * 0.5); 
			};
			
			var dash = '<span class="dashes dash-'+i+1+'"></span>';
			$('.timelineDashes').append(dash);
			$('.dash-'+i+1).css('left',position+'%');
			
			BK.tlVs.timelinePositions.push(position);
			BK.tlVs.timelinePositions.sort(sortNumber);
			BK.tlVs.timelineObjectsLength = BK.tlVs.timelinePositions.length;
		}
	},
	
	attachTimelineListeners : function() {
	
		$('.scrubberInternal').bind(downEventVar, function(e){
		
			if (BK.tlVs.inThePast) { BK.corpTL.repositionCarousel(1, 1) };
			if (BK.tlVs.inTheFuture) { BK.corpTL.repositionCarousel(BK.tlVs.totalLength, 1) };
			if (BK.tlVs.inThePast || BK.tlVs.inTheFuture) BK.corpTL.goToPresent();
	
		    if (e.preventDefault) e.preventDefault();
			$(this).focus();
	  		BK.tlVs.trackingObject = $(this);
	
	  		BK.tlVs.scrubberWidth = $(this).width() / 2;
	  		BK.tlVs.sliderLeft = $(this).parents('.scrubberContainer').offset()['left'];
			BK.tlVs.sliderWidth = $(this).parents('.scrubberContainer').outerWidth();
			
		    BK.tlVs.isTracking = true;
		});
		
		
		$('.leftButton').bind(dropEventVar, function(e){
		    if (e.preventDefault) e.preventDefault();
	   		$(this).focus();
	   		
			if (BK.tlVs.currentTile == 1 && !BK.tlVs.isTracking) {
				BK.corpTL.goToPast();
			} else if (BK.tlVs.currentTile > 1) {
				BK.tlVs.mousePct = (BK.tlVs.currentTile - 2) / (BK.tlVs.totalLength - 1);
				if (BK.tlVs.inTheFuture) { BK.corpTL.repositionCarousel(BK.tlVs.totalLength, 1); BK.corpTL.goToPresent(); } else { BK.corpTL.repositionCarousel(BK.tlVs.currentTile - 1, 1) };
			}
		});
		
		$('.rightButton').bind(dropEventVar, function(e){
		   	if (e.preventDefault) e.preventDefault();
			$(this).focus();
	
			if (BK.tlVs.currentTile == BK.tlVs.totalLength && !BK.tlVs.isTracking) {
				BK.corpTL.goToFuture()
			} else if (BK.tlVs.currentTile < BK.tlVs.totalLength) {
				BK.tlVs.mousePct = (BK.tlVs.currentTile) / (BK.tlVs.totalLength -1);
				if (BK.tlVs.inThePast) { BK.corpTL.repositionCarousel(1, 1); BK.corpTL.goToPresent(); } else { BK.corpTL.repositionCarousel(BK.tlVs.currentTile + 1, 1) };
			}
		});
		
		BK.corpTL.AttachEvent(document,dropEventVar,droppingIt,false);
		function droppingIt (e){
			BK.tlVs.isTracking = false;
			if (BK.tlVs.currentZoomLevel != 1) {BK.corpTL.repositionCarousel(BK.tlVs.currentTile, 1);};	
		};
	
		BK.corpTL.AttachEvent(document,dragEventVar,movingIt,false);
		function movingIt (e){ 
	
			if (BK.tlVs.isTracking == true) {
	
		  		BK.tlVs.theActivePos = e.touches ? e.touches[0].pageX : e.clientX;
				BK.tlVs.mousePct  = (( BK.tlVs.theActivePos - BK.tlVs.sliderLeft - BK.tlVs.scrubberWidth ) / ( BK.tlVs.sliderWidth ));
		
				BK.corpTL.calculateCarouselPos();
				BK.corpTL.scrubberRePos();
			};
		};
	},
	
	//Depending on the mouse position percentage, where to throw the carousel.
	//Extra conditionals to detect + redirect vals outside the slider.
	calculateCarouselPos : function() {
		for ( var ia = 1 ; ia <= BK.tlVs.totalLength; ia++ ) {
			if ( BK.tlVs.mousePct >= 0 && BK.tlVs.mousePct <= 1 ) {
				
				for (var h = 0; h < BK.tlVs.timelineObjectsLength; h++) {
					if (BK.tlVs.timelinePositions[h] <= BK.tlVs.mousePct*100 && BK.tlVs.timelinePositions[h+1] >= BK.tlVs.mousePct*100) {
						if (Math.abs(BK.tlVs.timelinePositions[h] - BK.tlVs.mousePct*100) < Math.abs(BK.tlVs.timelinePositions[h+1] - BK.tlVs.mousePct*100)) {
							BK.corpTL.repositionCarousel(h+1, BK.tlVs.zoomLevel);
							BK.tlVs.currentTile = h+1;
							break;
						} else {
							BK.corpTL.repositionCarousel(h+2, BK.tlVs.zoomLevel);
							BK.tlVs.currentTile = h+2;
							break;
						}					
					}
				}
				break;
			}
			else if ( BK.tlVs.mousePct < 0 ) {
				BK.corpTL.repositionCarousel(1, BK.tlVs.zoomLevel);
				BK.tlVs.currentTile = 1;
				break;
			}
			else if ( BK.tlVs.mousePct > 1 ) {
				BK.corpTL.repositionCarousel(BK.tlVs.totalLength, BK.tlVs.zoomLevel);
				BK.tlVs.currentTile = BK.tlVs.totalLength;
				break;
			}
		}			
	},
	
	//Function for repositioning the scrubber.
	scrubberRePos : function(){
		function scrubSwitch (full,notFull) {
			if (BK.tlVs.currentZoomLevel == 1){
				$('.scrubberHolder').css('left',full);
			} else {
				$('.scrubberHolder').css('left',notFull);
			}
		}
		if ( BK.tlVs.mousePct >=0 && BK.tlVs.mousePct <= 1 ) { scrubSwitch(BK.tlVs.timelinePositions[BK.tlVs.currentTile - 1]+"%", BK.tlVs.mousePct*100+"%") } 
		else if ( BK.tlVs.mousePct > 1 ) { scrubSwitch(BK.tlVs.timelinePositions[BK.tlVs.timelineObjectsLength - 1]+"%", 100+"%") } 
		else if ( BK.tlVs.mousePct < 0 || BK.tlVs.mousePct == undefined ) { scrubSwitch(BK.tlVs.timelinePositions[0]+"%", 0+"%") };
	},
	
	//Throw the timeline ... to the past!
	goToPast : function() {
	
		if (!BK.tlVs.inThePast){
		
			BK.tlVs.returnPoint = $('ul.list').css('left');
			
			BK.tlVs.inThePast = true;
			$('.timelineDashes .dashes').hide();
			$('.scrubbingArea, .timelineDashes').removeClass('future').addClass('past');
		 	$('.scrubberHolder').css('left','0%');
		 	
			//Animate, depending on CSS Transition Compatibility.
			if (testFor.csstransitions()) {
			
				BK.corpTL.addCSSTransitions($('ul.list'), BK.tlVs.cssTranSpeed, 'ease-in');
				$('ul.list').css('left', 2000);
				
				BK.corpTL.addCSSTransitions($('.tile-past'), BK.tlVs.cssTranSpeed * 1.25, 'ease-out');
				$('.tile-past').css('left',50);
				
				BK.corpTL.addCSSTransitions($('.backDrop-past'), BK.tlVs.cssTranSpeed * 1.25, 'ease-out');
				$('.backDrop-past').css('opacity',1);
				
			} 
			else {
				$('ul.list').stop().animate( { 'left':1000 } , BK.tlVs.cssTranSpeed * 1000 , function(){  } );
				$('.tile-past').stop().animate( { 'left':50 } , BK.tlVs.cssTranSpeed * 1.25 * 1000 , function(){  } );
				$('.backDrop-past').fadeTo(400,1);
			}
			
			$('.markPast').fadeOut(0).fadeIn(250);
		}
	},
	
	//Throw the timeline ... to the future!
	goToFuture : function() {
	
		if (!BK.tlVs.inTheFuture) {
		
			BK.tlVs.returnPoint = $('ul.list').css('left');
		
			BK.tlVs.inTheFuture = true;
			$('.timelineDashes .dashes').hide();
			$('.scrubbingArea, .timelineDashes').removeClass('past').addClass('future');
		 	$('.scrubberHolder').css('left','100%');
		 	
			//Animate, depending on CSS Transition Compatibility.
			if ( testFor.csstransitions() ) {
			
				BK.corpTL.addCSSTransitions($('ul.list'), BK.tlVs.cssTranSpeed, 'ease-in');
			 	$('ul.list').css('left',(BK.tlVs.totalLength*-525 - 2000));
			 	
				BK.corpTL.addCSSTransitions($('.tile-future'), BK.tlVs.cssTranSpeed * 1.25 , 'ease-out');
				$('.tile-future').css('left',50);
				
				BK.corpTL.addCSSTransitions($('.backDrop-future'), BK.tlVs.cssTranSpeed * 1.25 , 'ease-out');
				$('.backDrop-future').css('opacity',1);
				
			} else {
				$('ul.list').stop().animate( { 'left':(BK.tlVs.totalLength*-525 - 525) } , BK.tlVs.cssTranSpeed * 1000 , function(){  } );
				$('.tile-future').stop().animate( { 'left':50 } , BK.tlVs.cssTranSpeed * 1.25 * 1000 , function(){  } );
				$('.backDrop-future').fadeTo(400,1);
			}
		
			$('.markFuture').fadeOut(0).fadeIn(250);
		};
	}, 
	
	//Throw the timeline ... to the present!
	goToPresent : function() {
		
		if (BK.tlVs.inThePast || BK.tlVs.inTheFuture){
		
			$('.timelineDashes .dashes').show();
			$('.scrubbingArea, .timelineDashes').removeClass('past').removeClass('future');
			
			//Animate, depending on CSS Transition Compatibility.
			if (testFor.csstransitions()) {
			
				BK.corpTL.addCSSTransitions($('.tile-past'), BK.tlVs.cssTranSpeed / 2 , 'ease-in');
				$('.tile-past').css('left',-2000);

				BK.corpTL.addCSSTransitions($('.tile-future'), BK.tlVs.cssTranSpeed / 2 , 'ease-in');
				$('.tile-future').css('left',2000);
				
				$('.backDrop-past, .backDrop-future').css('opacity',0);
			} 
			else {
				$('.tile-past').stop().animate( { 'left':-2000 } , BK.tlVs.cssTranSpeed / 2 * 1000 , function(){  } );
				$('.tile-future').stop().animate( { 'left':2000 } , BK.tlVs.cssTranSpeed / 2 * 1000 , function(){  } );
				$('.backDrop-past, .backDrop-future').fadeTo(400,0);
			}
			
			$('.markFuture').hide();
			$('.markPast').hide();
		}
		BK.tlVs.inThePast = BK.tlVs.inTheFuture = false;
	},
	
	
	//Reposition carousel to a certain child, at a certain scale.
	repositionCarousel : function( whichChild, reScale ){
	
		//Kill any videos if the user attempts to move the timeline.
		$('video').parent().remove();
		
		//Set variable for the current child.
		var theCurrentTile = $('ul.list li.item:nth-child('+whichChild+')');
		
		//Detect if zoom level has changed. Important for browsers that don't support CSS transitions
		var changedZoom = false;
		if (reScale != BK.tlVs.currentZoomLevel) {
			changedZoom = true;
			BK.tlVs.currentZoomLevel = reScale;
		}
	
		//Detect if tile has changed.
		var changedTile = false;
		if (whichChild != BK.tlVs.currentTile) { 
			changedTile = true 
		};
			
		//If the current tile or zoom level has changed, perform repositioning functions.
		if ( changedTile || changedZoom || BK.tlVs.inThePast || BK.tlVs.inTheFuture ) {
		
			// Reset the overlays / tile blackouts.
			$('ul.list li.item .slideOverlay').stop().show().animate({'opacity':0}, BK.tlVs.animSpeed);
			$('ul.list li.item .tileBlackout').stop().show().animate({'opacity':1}, BK.tlVs.animSpeed);
			$('ul.list li.item:nth-child('+whichChild+') .slideOverlay').stop().show().animate({'opacity':1}, BK.tlVs.animSpeed);
			$('ul.list li.item:nth-child('+whichChild+') .tileBlackout').stop().show().animate({'opacity':0}, BK.tlVs.animSpeed);
			
			BK.tlVs.currentTile = whichChild;
	
			BK.corpTL.scrubberRePos();
	
			//If we're zooming in on a single item, fade both overlays out.
			if ( reScale == 1 ) {
				$(theCurrentTile).find('.slideOverlay').stop().animate({'opacity':0}, BK.tlVs.animSpeed).hide();
				$(theCurrentTile).find('.tileBlackout').stop().animate({'opacity':0}, BK.tlVs.animSpeed).hide();
				
				//Animate, depending on CSS Transition Compatibility.
				if ( testFor.csstransitions() ) {
					BK.corpTL.addCSSTransitions($('.backDrop-scrubbing'), BK.tlVs.cssTranSpeed * 1.25, 'ease-out');
					$('.backDrop-scrubbing').css('opacity',0);
				} else {
					$('.backDrop-scrubbing').stop().fadeTo(400,0);
				}
			} else if ( reScale == BK.tlVs.zoomLevel ) {
				//Animate, depending on CSS Transition Compatibility.
				if ( testFor.csstransitions() ) {
					BK.corpTL.addCSSTransitions($('.backDrop-scrubbing'), BK.tlVs.cssTranSpeed * 1.25, 'ease-out');
					$('.backDrop-scrubbing').css('opacity',1);
				} else {
					$('.backDrop-scrubbing').stop().fadeTo(400,1);
				}
			}
			
			//Setup variables to be used for the rePos variable (used for left positioning in the carousel).
			var left = $(theCurrentTile).position().left;
				
			var rePos = testFor.csstransforms() 
				? ((BK.tlVs.parentwidth*(1-reScale)*-1)/2) + ((whichChild - 1) * BK.tlVs.width * -1 * (reScale)) + ((BK.tlVs.containerboxwidth - (BK.tlVs.width * reScale))/2) 
				: ((whichChild - 1) * BK.tlVs.width * -1) + ((BK.tlVs.containerboxwidth - (BK.tlVs.width))/2) ;
		
			//Assign scale transforms for supporting browsers
			if (changedZoom){
				$(theCurrentTile).parent().css('-moz-transform','scale('+reScale+')');
				$(theCurrentTile).parent().css('-webkit-transform','scale('+reScale+')');
				$(theCurrentTile).parent().css('transform','scale('+reScale+')');
			}
			
			/*
			!!! START CAROUSEL REPOSITIONING CONDITIONALS. 
			!!! Depreciates for browsers without css transitions as a jquery animation.
			*/
			
				//Browser supports transitions, transitioning within same level of zoom
				if (testFor.csstransitions()) {
					BK.corpTL.addCSSTransitions($(theCurrentTile).parent(), (changedZoom ? 0 : BK.tlVs.cssTranSpeed), 'ease-out');
					$(theCurrentTile).parent().css('left',rePos)
				} 
				//jQuery fallback animation for users without transitioning.
				else if (!testFor.csstransitions() && !changedZoom){	
					$(theCurrentTile).parent().stop().animate( { 'left':rePos } , BK.tlVs.cssTranSpeed * 1000 , function(){  } );
				} 
				//Just change the zoom level.
				else {
					$(theCurrentTile).parent().stop().css('left',rePos);
				}
			
			/*
			!!! END CAROUSEL REPOSITIONING CONDITIONALS. 
			*/
			
			//If focusing on a single tile, set up and play the video.
			if ( reScale == 1 && BK.tlVs.videoBoxes[(whichChild-1)].length > 0) {
				$('.tileVideo-'+(whichChild-1)).html('').html(BK.tlVs.videoBoxes[(whichChild-1)]);
				VideoJS.setup();
				$('video')[0].play();
				$('.replay').mouseover(function(){$('.vjs-controls').stop().css('bottom','0px')});
				$('.replay').click(function(){videoElement.play();});	
			};
		}
	}, 
	
	//add dots to easter egg slides in timeline
	dots : function(ws) {
	
		var futurebool = false;
		if (ws == 'future') futurebool = true;
		
		var sRGB = futurebool ? [87,171,208] : [248,157,65];
		var eRGB = [81,81,81];
		var initSpace = 5;
		var finalSpace = 12;
		var glowUnits = 4;
		var glowMax = 5;
		var numberOfUnits = 12;
		
		for (var mi = 1; mi <= numberOfUnits; mi++) {
			
			function avgCol(n) { return Math.floor(sRGB[n] - (((sRGB[n] - eRGB[n])/numberOfUnits)*mi)); };
			var newR = avgCol(0);
			var newG = avgCol(1);
			var newB = avgCol(2);
			
			var spacing = initSpace + ((finalSpace - initSpace) / numberOfUnits * mi);
			var appendUnit = $('<span class="dots">.</span>');
			appendUnit.css('display','inline-block').css(futurebool ? 'marginRight' : 'marginLeft', spacing);
			appendUnit.css('color','rgb('+newR+','+newG+','+newB+')');
	
			if (mi <= glowUnits) {
				var theAmt =  glowMax * (glowUnits + 1 - mi) / glowUnits;
				appendUnit.css('text-shadow','rgb('+sRGB[0]+','+sRGB[1]+','+sRGB[2]+') 0 0 '+theAmt+'px')
			}	
			futurebool ? $('.markFuture').prepend(appendUnit) : $('.markPast').append(appendUnit);
		}
	},
	
	addCSSTransitions : function( theObject, transTime, theEasing ) {
		theObject
			.css('-webkit-transition', transTime + 's ' + theEasing )
			.css('-moz-transition', transTime + 's ' + theEasing )
			.css('-o-transition', transTime + 's ' + theEasing )
			.css('transition', transTime + 's ' + theEasing );
	},
	
	AttachEvent : function( obj, evt, fnc, useCapture ){
		if (!useCapture) useCapture=false;
		if (obj.addEventListener){
			obj.addEventListener(evt,fnc,useCapture);
			return true;
		} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	}
}
