var videos=$("#videos");var body=$("body");var data,html,i,video;var currentView=$(window);var currentDoc=$(document);var widthAdded=0;var amountVideos=videos.data("amount");var latestVideoId=videos.data("latest");var bodyWidth,windowWidth,totalWidth,offset;var animated,loaded=false;var video_url,video_id,video_obj,hiddenVideos;$(function(){windowWidth=currentView.width();bodyWidth=(amountVideos*750);offset=currentDoc.scrollLeft();totalWidth=offset+windowWidth});currentView.scroll(function(){offset=currentDoc.scrollLeft();windowWidth=currentView.width();totalWidth=offset+windowWidth;if(totalWidth>=(bodyWidth-1000)&&!animated){animated=true;$.getJSON("videos.php?what=json&video_id="+latestVideoId,function(a){hiddenVideos=html="";for(i=0;i<a.length;i++){video=a[i];if(i<1){hiddenVideos="#video-"+video.id}else{hiddenVideos+=", #video-"+video.id}html+='<div id="video-'+video.id+'" class="video hidden"><div class="tab"><h2>'+video.day+"</h2><p>"+video.month+"</p></div><h1>"+video.title+'</h1><div class="player" data-video="'+video.id+'" data-loaded="false" data-type="'+video.type+'" data-url="'+video.url+'" data-height="'+video.height+'" style="min-height:'+video.height+'px"><div class="arrow"></div><img src="'+video.img+'" alt="video" width="500" /></div><div class="info"><div class="share"><fb:like href="http://imgoingtostartmynewlifeonmonday.com/'+video.id+'/" layout="box_count"></fb:like></div><div class="text"><p>'+video.text+"</p></div></div></div>";latestVideoId=video.id}videos.append(html);widthAdded=750*i;bodyWidth+=widthAdded;i=0;videos.animate({width:"+="+widthAdded+"px"},function(){$(hiddenVideos).fadeIn();animated=false;FB.XFBML.parse()});_gaq.push(["_trackEvent","Scroll","Show more",latestVideoId])})}});if(document.addEventListener){document.addEventListener("keydown",keyScroll,false)}else{if(document.attachEvent){document.attachEvent("keydown",keyScroll)}}function keyScroll(a){key=a.keyCode||a.charCode;switch(key){case 37:a.preventDefault();body.dequeue().animate({scrollLeft:["-=750px","swing"]});break;case 38:a.preventDefault();body.dequeue().animate({scrollLeft:["-=750px","swing"]});break;case 39:a.preventDefault();body.dequeue().animate({scrollLeft:["+=750px","swing"]});break;case 40:a.preventDefault();body.dequeue().animate({scrollLeft:["+=750px","swing"]});break}}$(".player").live("click",function(){if(!$(this).data("loaded")){$(this).data("loaded",true);video_url=$(this).data("url");video_id=$(this).data("video");if($(this).data("type")=="youtube"){video_obj='<object width="500" height="350"><param name="movie" value="http://www.youtube.com/v/'+video_url.substr(31)+'?fs=1&rel=0&autoplay=1&hd=1&showinfo=0&showsearch=0&autohide=1&modestbranding=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+video_url.substr(31)+'?fs=1&rel=0&autoplay=1&hd=1&showinfo=0&showsearch=0&autohide=1&modestbranding=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="350"></embed></object>'}else{video_obj='<object width="500" height="'+$(this).data("height")+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+video_url.substr(17)+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=F2F0D8&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+video_url.substr(17)+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=F2F0D8&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="'+$(this).data("height")+'"></embed></object>'}$("#video-"+video_id+" .player").html(video_obj);$.get("videos.php?what=json&add_views=yes&video_id="+video_id)}});var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-6635830-2']); _gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async=true; ga.src=('https:'==document.location.protocol ?'https://ssl':'http://www')+'.google-analytics.com/ga.js'; var s=document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
