﻿var Timeline={Timepoint:function(a,b){this.handle=a;this.index=b},timepoints:null,nextButton:null,prevButton:null,handle:null,activeIndex:-1,hashPrefix:"tline_",onMove:null,getTimepointByElement:function(b){if(Timeline.timepoints!=null){var a=0;while(a<Timeline.timepoints.length){if(Timeline.timepoints[a]==b){return Timeline.timepoints[a]}a++}}return null},getTimepointByIndex:function(a){if(Timeline.timepoints!=null&&Timeline.timepoints[a]!=undefined){return Timeline.timepoints[a]}return null},doJump:function(b){var c=$(b);var a=c.position();var e=(a.left+((c.width()-Timeline.handle.width())/2));Timeline.handle.css("left",e);c.css("background-position","0 0");if(Timeline.timepoints[Timeline.activeIndex]!=undefined){var f=$(Timeline.timepoints[Timeline.activeIndex]);var d=f.width();f.css("background-position","-"+d+"px 0")}Timeline.moved(b)},doJumpToIndex:function(a){if(typeof(Timeline.timepoints[a])!="undefined"&&Timeline.timepoints[a]!=null){Timeline.doJump(Timeline.timepoints[a])}},doSlide:function(b){var c=$(b);var a=c.position();var e=(a.left+(Math.floor((c.width()-Timeline.handle.width())/2)));Timeline.handle.animate({left:e},600,"quartEaseInOut",function(){c.css("background-position","0 0");document.location.hash=(Timeline.hashPrefix+b.TimelineLink.index)});var f=$(Timeline.timepoints[Timeline.activeIndex]);var d=f.width();f.css("background-position","-"+d+"px 0");$("#learnmoredialog").dialog("destroy");$("#learnmoredialog").remove();Timeline.doLoadTimepointContent(b.TimelineLink.index);Timeline.moved(b)},doLoadTimepointContent:function(a){$.ajax({type:"GET",url:"Timeline.aspx?target="+a,dataType:"html",success:function(b){Timeline.contentLoaded(b)}})},doSlideToIndex:function(a){if(typeof(Timeline.timepoints[a])!="undefined"&&Timeline.timepoints[a]!=null){Timeline.doSlide(Timeline.timepoints[a])}},doSlideNext:function(){var a=(Timeline.activeIndex+1);if(a<Timeline.timepoints.length&&a>-1){Timeline.doSlide(Timeline.timepoints[a])}},doSlidePrevious:function(){var a=(Timeline.activeIndex-1);if(a<Timeline.timepoints.length&&a>-1){Timeline.doSlide(Timeline.timepoints[a])}},contentLoaded:function(a){var b=$(".timepoint-content");if(a!=null){b.html(a)}Timeline.bindDialog();Timeline.bindAnchors(b)},moved:function(a){Timeline.activeIndex=a.TimelineLink.index;if(Timeline.prevButton!=null){Timeline.prevButton.toggleClass("disabled-prev",(Timeline.activeIndex==0))}if(Timeline.nextButton!=null){Timeline.nextButton.toggleClass("disabled-next",(Timeline.activeIndex==(Timeline.timepoints.length-1)))}if($.isFunction(Timeline.onMove)){Timeline.onMove(a)}},showDialog:function(){$("#learnmoredialog").dialog("open")},dialogOpened:function(a){Timeline.bindAnchors(a.target)},bindDialog:function(){$("#learnmoredialog").dialog({modal:true,alterTabFocus:false,height:530,width:707,autoOpen:false,open:Timeline.dialogOpened});$(".whatyouneedtoknow .content-wrap").bind("click",function(a){a.preventDefault();Timeline.showDialog()})},bindAnchors:function(a){if(a==null||a==undefined){a=document}$("a[href^='#"+Timeline.hashPrefix+"']",a).bind("click",function(c){c.preventDefault();var b=$(this).attr("href").substr(Timeline.hashPrefix.length+1);if(b>-1&&b<Timeline.timepoints.length){Timeline.doSlideToIndex(b)}});if(typeof(NicoretteApp)!="undefined"){NicoretteApp.BindTracking(NicoretteApp.trackingElement,a)}},init:function(){if(typeof(TriggerTips)!="undefined"&&TriggerTips!=null){Timeline.onMove=TriggerTips.cleanDom}Timeline.handle=$(".timeline-wrapper .indicator");Timeline.timepoints=new Array();$(".timeline-wrapper .timepoint").each(function(d){this.TimelineLink=new Timeline.Timepoint(this,d);Timeline.timepoints[d]=this});$(".timeline-wrapper .timepoint").bind("click",function(d){Timeline.doSlide(this)});Timeline.nextButton=$(".timeline-wrapper .nav.right");if(Timeline.nextButton!=null){Timeline.nextButton.bind("click",function(d){d.preventDefault();Timeline.doSlideNext()})}Timeline.prevButton=$(".timeline-wrapper .nav.left");if(Timeline.prevButton!=null){Timeline.prevButton.bind("click",function(d){d.preventDefault();Timeline.doSlidePrevious()})}var a=0;var b=new Querystring();if(document.location.hash&&document.location.hash.indexOf("#"+Timeline.hashPrefix)>-1){a=document.location.hash.substr(Timeline.hashPrefix.length+1);Timeline.doJumpToIndex(a);Timeline.doLoadTimepointContent(a)}else{if(b.contains(Timeline.hashPrefix+"target")){var c=parseInt(b.get(Timeline.hashPrefix+"target"));if(c>-1&&c<Timeline.timepoints.length){a=b.get(Timeline.hashPrefix+"target")}Timeline.doJumpToIndex(a);Timeline.contentLoaded()}else{Timeline.doJumpToIndex(a);Timeline.contentLoaded()}}}};$(document).ready(function(){Timeline.init()});