
var $header=$('#nav-header');var article={psl:[],list:[],future:[],acursor:0,curpage:1,offset:{is:'130%',cs:'30%'},init:function(){article.list.push($.parseJSON($('input[name=meta]').val()));this.postLoad(1);$('.context-switch').waypoint({offset:article.offset.cs,handler:article.switchContext});$('#infinite-scroll').waypoint({offset:article.offset.is,handler:function(dir){if(dir==='down')
{article.getNext();}},});shareBar.load();$('.gshare-show').delay(500).slideDown(500);},scrollTo:function(secIndex){var element=$("a[name='sec"+secIndex+"']");if(element.length)
{$('html, body').animate({scrollTop:(element.offset().top-110)},1000,'swing');}},getNext:function(fn)
{var nextArticle=article.future.shift().replace('article','iarticle');if(typeof nextArticle=='undefined'){$('#infinite-scroll').waypoint('disable');article.getNext=function(){};return false;}
$.waypoints('disable');var newContainer=$('<div style="display:none">');$('#infinite-loading').show();$.ajax({url:nextArticle,cache:false,async:true,error:function(jqXHR,textStatus,errorThrown){},success:function(data){var incoming=$.parseJSON($(data).filter('input:first').val());article.list.push(incoming);newContainer.html(data);$('#postswrapper').append(newContainer);shareBar.load({title:incoming.title,canonical:incoming.canonical,desc:incoming.description,hero:"http://www.entreprneur.com"+incoming.image,type:incoming.type,objectID:incoming.id});ad.newPage(incoming);$('.context-switch:last').waypoint({offset:article.offset.cs,handler:article.switchContext});article.postLoad(++article.curpage);$('.gshare').slideDown(200);var keywords=incoming.keywords.split(',');for(i in keywords)
{keywords[i]=keywords[i].toLowerCase().replace(/\W+/g,"");}
incoming.keywords=keywords;ad.omniture(incoming);newContainer.show();$('#infinite-loading').hide();$.waypoints('enable');$("img.lazy").lazyload({effect:"fadeIn",threshold:300});if(fn)fn();ent.nlCookie(0,true);},});},put:function(context)
{this.list.push(context);},switchContext:function(dir){if(dir==='down')
{article.acursor++;}else article.acursor--;var cursor=article.acursor;if(typeof article.list[cursor]!='undefined')
{data=article.list[cursor];document.title=decodeURIComponent(data.title);url=data.canonical.replace('http://www.entrepreneur.com','');var partnerContent=url.startsWith('http://');if(partnerContent==false){if(article.psl[cursor]==='undefined')
{history.pushState(null,null,url);window._comscore=null;var _comscore=_comscore||[];_comscore.push({c1:"2",c2:"9564200"});(function(){var s=document.createElement("script"),el=document.getElementsByTagName("script")[0];s.async=true;s.src=(document.location.protocol=="https:"?"https://sb":"http://b")+".scorecardresearch.com/beacon.js";el.parentNode.insertBefore(s,el);})();(function(){var d=new Image(1,1);d.onerror=d.onload=function(){d.onerror=d.onload=null;};d.src=["//secure-us.imrworldwide.com/cgi-bin/m?ci=us-304769h&cg=0&cc=1&si=",escape(window.location.href),"&rp=",escape(document.referrer),"&ts=compact&rnd=",(new Date()).getTime()].join('');})();}
else
history.replaceState(null,null,url);}
article.psl[cursor]=1;}else{}},getContext:function(last)
{return article.list[(last?article.list.length-1:article.acursor)];},getLoadables:function(){$('#repeater .listitem').each(function(i,el){article.future.push($(el).find('a').attr('href'));});},postLoad:function(page){c=article.list[article.list.length-1];fyre.conv.load({network:"livefyre.com"},[{"collectionMeta":{articleId:c.id,url:fyre.conv.load.makeCollectionUrl(),},"siteId":"334706","articleId":c.id,"el":$('.comment-block:last').attr('id')}]);LF.CommentCount({replacer:function(element,count){element.innerHTML=(count===0)?'Comment':count;$(".livefyre-commentcount.barcount").each(function(e){if($(this).text()=='Comment')
$(this).parent().html('<i class="fa fa-comments"></i> CLICK HERE TO ADD A COMMENT');});}});$('.load-comments').click(function(){$(this).hide().prev('.comment-holder').addClass('active').css('height','auto');});$('.content-main-body iframe').css('width','100%');},};var ss={data:[],cursor:1,offset:0,pkey:null,th:null,init:function(){$.get('/async/storystream',function(data){ss.data=data;for(i in ss.data)
{$('.ss-articles').append($('<a>').attr('style','display:none;').attr('href',ss.data[i].canonicalUrl).html('<span class="i-'+ss.data[i].key+'"></span>'+ss.data[i].headline));}
$('.ss-articles a:first').show();if(ss.data.length>1){setInterval(ss.tick,1000);}
$w.on('scroll',throttle(function(){if($(window).scrollTop()<=60){$('#story-stream').slideUp(50);}else{$('#story-stream').slideDown(200);}},1000));},'json');},toggle:function(){if(ss.th)clearTimeout(ss.tick)
else ss.th=setInterval(ss.tick,1000);},tick:function(){var quotient=100 / ss.data.length,time=parseInt(Date.now()/ 1000).toString().slice(-2),cursor=Math.floor(time / quotient);if(ss.cursor!=cursor){ss.cursor=cursor-ss.offset;ss.display();}},manualTick:function(){var pc=ss.cursor;ss.cursor=parseInt(Math.random()*ss.data.length);if(pc===ss.cursor)
ss.cursor++;ss.display();},display:throttle(function(){if(ss.pkey!=ss.data[ss.cursor].key)
{$('#story-stream .navarrow').fadeOut(300)
ss.pkey=ss.data[ss.cursor].key;}
$('.ss-articles a').fadeOut(300);$('.ss-articles a:nth-child('+(ss.cursor+1)+')').delay(300).fadeIn(300);},1000)};var nextButton={show:function(){$('.next a').animate({"marginRight":'0px'},200);},hide:function(){$('.next a').animate({"marginRight":'-170px'},200);},click:function(){$("div.next").addClass('active');article.getNext(function(){$('html, body').animate({scrollTop:($('.content-main:last').offset().top-470)},1000,'swing',function(){$("div.next").removeClass('active');});});}};var topButton={click:function(){$('html, body').animate({scrollTop:(0)},1000);}}
$w.load(function(){article.init();ss.init();$('.section-menu a').click(function(e){e.preventDefault();article.scrollTo($(this).attr('href').replace('#sec',''));});$d.on('click','.toggle-caption',function(e){e.preventDefault();$('.caption-text').slideToggle();}).on('click','.toggle-close',function(e){e.preventDefault();$('.caption-text').slideUp();}).on('click','.g-comments',function(e){e.preventDefault();commentParent=$(this).parents('section');commentParent.find('.load-comments').click();$('html, body').animate({scrollTop:(commentParent.find('.comment-holder').offset().top-100)},1000);}).on('click','.next .top',function(e){topButton.click();return false;}).on('click','.next .nextarticle',function(e){ent.nlCookie(0,true);nextButton.click();return false;});});