var display=(function(){})();jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*50000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};videoData=function(){var id=null,hostname=null,hostId=null,title=null,description=null,link=null};var divElm=(function(){var videoBox='videoBox',playerBox='playerBox',playerContent='playerContent',playerTopLayer='onTop',playerElm='playerElm',muteIcon='http://mediastroage.s3.amazonaws.com/mute_24.png',unMuteIcon='http://mediastroage.s3.amazonaws.com/unmute_24.png',singleVideoPlayer='Single Video Player',videoTitle='vidTitle';return{videoBox:videoBox,playerBox:playerBox,playerContent:playerContent,playerTopLayer:playerTopLayer,singleVideoPlayer:singleVideoPlayer,videoTitle:videoTitle}})();var videoList=(function(){var vidList=new Array(),curIndex=-1,viewedList=new Array(),maxViewedList=75,lastRetrievedId=null,peekNextIndex=function(){if(curIndex>=vidList.length){return vidList.length}var index=curIndex;return++index},getNextIndex=function(){if(curIndex>=vidList.length){return null}return++curIndex},getCurrentIndex=function(){return curIndex},getPrvIndex=function(){if(curIndex>0){return--curIndex}return 0},onLoadPage=function(){var vl=$.cookie("_vl");if(vl!==null){viewedList=vl.split("&")}setTimeout('videoList.getNewVideo()',10000);return},onUnloadPage=function(){if(viewedList.length>0){$.cookie("_vl",viewedList.join("&"),{expires:3})}},shuffle=function(data){var tmp,cur,tp=data.length-1;if(tp){while(tp){cur=Math.floor(Math.random()*(tp+1));tmp=data[cur];data[cur]=data[tp];data[tp]=tmp;--tp}}return data},ashuffle=function(data){var allData=new Array();var newData=new Array();var i;var end;for(i=0;i<(data.length);i+=10){end=(i+10>data.length)?data.length:i+10;newData=shuffle(data.slice(i,end));allData=allData.concat(newData)}return allData},getMoreVideo=function(link){var ytJsonData=$.ajax({url:link,dataType:"json",async:false,timeout:2000,success:function(msg){}}).responseText;return $.parseJSON(ytJsonData)},getPrvVideo=function(){return vidList[getPrvIndex()]},addToViewedList=function(vid){if(viewedList.length>=maxViewedList){viewedList.splice(0,1)}viewedList.push(vid)},addVidData=function(vidData,hostname){var tempVid=new videoData();tempVid.id=vidData.id;tempVid.hostname=hostname;tempVid.hostId=vidData.id;tempVid.title=vidData.title;return tempVid},getNewVideo=function(){var tempVid=new Array();var url="http://tiltview.com/data/new.php?id="+lastRetrievedId;var ytJsonData=getMoreVideo(url);var index=0;if(ytJsonData&&ytJsonData.items.length>0){lastRetrievedId=ytJsonData.items[0].id;for(var key in ytJsonData.items){tempVid[index]=addVidData(ytJsonData.items[key],'youtube');if(vidList.length==0){vidList=tempVid}else{vidList.splice(peekNextIndex(),0,tempVid[index])}++index}}setTimeout('videoList.getNewVideo()',500000)},getNextVideo=function(){var urls=new Array();urls[0]="http://tiltview.com/data/bd.php";if((getCurrentIndex()<=-1)||(vidList.length<=0)||(getCurrentIndex()>=(vidList.length-1))){vidList=[];curIndex=-1;for(var url in urls){var ytJsonData=getMoreVideo(urls[url]);if(ytJsonData.items.length>0){lastRetrievedId=ytJsonData.items[0].id}var endIndex=(vidList.length<=0)?0:vidList.length;for(var key in ytJsonData.items){if($.inArray(ytJsonData.items[key].id,viewedList)==-1){vidList[endIndex]=addVidData(ytJsonData.items[key],'youtube');++endIndex}else{}}}vidList=ashuffle(vidList)}var index=getNextIndex();if(index!==null){addToViewedList(vidList[index].id);return vidList[index]}return null},displayList=function(){var key;for(key in vidList){}},getVideoList=function(){var urls=new Array();urls[0]="http://tiltview.com/data/br.php";var ytJsonData=getMoreVideo(urls[0]);return ytJsonData};return{getNextVideo:getNextVideo,getPrvVideo:getPrvVideo,onUnloadPage:onUnloadPage,onLoadPage:onLoadPage,getNewVideo:getNewVideo,displayList:displayList,getVideoList:getVideoList}})();var PLAYER_STATE=(function(){var state={"unstarted":-1,"ended":0,"playing":1,"paused":2,"buffering":3,"cued":5};return state})();function setDiv(elmId,value){$(elmId).text(value);$(elmId).fadeIn('slow')}function updateDiv(elmId,value){$("#"+elmId).fadeOut('slow',function(){$("#"+elmId).html(value)})}function updateHtml(elmId,value){document.getElementById(elmId).innerHTML=value}function updateStatus(title,link,hash){if(vidPlayer.playSingleVideo()===false){$('#vidTitle').css("color","#555555");var str=title;$('#'+divElm.videoTitle).fadeIn('slow',updateDiv(divElm.videoTitle,str))}window.location.hash=hash;var url="http://www.facebook.com/share.php?u="+(window.location.href.replace("#","%23")+'&t=')+escape(title);url='http://www.facebook.com/share.php?u='+window.location.href.replace('#','%23')+'&t='+title+' (Tiltview.com) ';document.getElementById('fbLink').href='http://www.facebook.com/share.php?u=http://tiltview.com';var t=typeof(title)!='undefined'?title.replace(/ /g,"_"):' ';url=window.location.href.split('#')[0]+"?t="+t+window.location.hash;url='http://twitter.com/share?url='+url.replace('#','%23')+'&via=tiltv&text='+escape(title)+'  ';document.getElementById('twLink').href=(url)}function onPlayerError(errorCode){playNext()}function min(sec){var minTemp=sec%(60*60);var min=Math.floor(minTemp/60);var secTemp=minTemp%60;sec=Math.ceil(secTemp);return min+":"+sec.toPrecision(2)}function updatePlayerInfo(){var cur=ytplayer.getCurrentTime();var dur=ytplayer.getDuration();updateHtml("vStatus",min(dur-cur)+'/'+min(dur));$("#pbar").css("left",Math.round(($("#title").width()-20)*(cur/dur)));return}function setVideoVolume(){var volume=parseInt(document.getElementById("volumeSetting").value,10);if(isNaN(volume)||volume<0||volume>100){}else if(ytplayer){ytplayer.setVolume(volume)}}function playVideo(){if(ytplayer){ytplayer.playVideo();_gaq.push(['_trackEvent','Videos','Number of Video Played','http://tiltview.com/#yt'+vidData.hostId])}}function pauseVideo(){if(ytplayer){ytplayer.pauseVideo();_gaq.push(['_trackEvent','Videos','Pause',vidData.hostId])}}function muteVideo(){if(ytplayer){ytplayer.mute();_gaq.push(['_trackEvent','Videos','Mute',vidData.hostId])}}function unMuteVideo(){if(ytplayer){ytplayer.unMute()}}function isSoundMuted(){if(ytplayer){return ytplayer.isMuted()}return false}function cueVideo(videoId){if(ytplayer){ytplayer.cueVideoById(videoId)}}function setYtHash(hash){return'yt'+hash}function getYtHash(hash){return hash.substring(3)}function playById(vid,title){if(ytplayer){cueVideo(vid);playVideo();updateStatus(title,'',setYtHash(vid))}}function playNext(){if(ytplayer&&vidPlayer.playSingleVideo()===false){vidData=videoList.getNextVideo();if(vidData!==null){cueVideo(vidData.hostId);playVideo();updateStatus(vidData.title,vidData.link,setYtHash(vidData.hostId));_gaq.push(['_trackEvent','Videos','Play Next',vidData.hostId])}}else{window.location="http://tiltview.com"}}function playPrv(){if(ytplayer){vidData=videoList.getPrvVideo();cueVideo(vidData.hostId);playVideo();updateStatus(vidData.title,vidData.link,setYtHash(vidData.hostId));_gaq.push(['_trackEvent','Videos','Play Previous',vidData.hostId])}}function showPauseButton(){document.getElementById('playButton').src="http://mediastroage.s3.amazonaws.com/pause4.jpg"}function showPlayButton(){document.getElementById('playButton').src="http://mediastroage.s3.amazonaws.com/play4.jpg"}function onPlayerStateChange(newState){if(newState==PLAYER_STATE["ended"]){if(vidPlayer.playSingleVideo()===false){playNext()}else{window.location="http://tiltview.com"}}else if(newState==PLAYER_STATE["playing"]||newState==PLAYER_STATE["buffering"]){showPauseButton()}else if(newState==PLAYER_STATE["paused"]){showPlayButton()}}function togglePlay(){if(ytplayer){var state=ytplayer.getPlayerState();if(state==PLAYER_STATE["playing"]){pauseVideo();showPlayButton()}else{playVideo();showPauseButton()}}}function setSeekTime(pos){ytplayer.seekTo(ytplayer.getDuration()*pos,true);$("#pbar").css("left",(($("#pBarBg").width()-20)*pos))}function playerResize(){var dh=$(window).height();var otherHeight=10+$('#menuBox').outerHeight()+$('#header').outerHeight()+$('#title').outerHeight()+$('#pBarBg').outerHeight();$('#'+divElm.videoBox).stop().animate({height:dh-otherHeight},800)}function startPlay(id){if(divElm.playerContent==id){playerResize();showPauseButton();if(vidPlayer.playSingleVideo()!==false){playById(vidPlayer.playSingleVideo(),' ')}else{playNext()}if(vidPlayer.isLandingPageActive()===true){muteVideo()}}else{cueVideo(listPlayer.getVideo());setDiv("#listTitle","")}}function onYouTubePlayerReady(id){ytplayer=document.getElementById(id);updatePlayerInfo();ytplayer.addEventListener("onStateChange","onPlayerStateChange");ytplayer.addEventListener("onError","onPlayerError");startPlay(id);setInterval(updatePlayerInfo,250);updatePlayerInfo()}function loadPlayer(objId){var params={allowScriptAccess:"always",wmode:"opaque",bgcolor:"#000000"};var atts={'id':objId,'class':'playerElm'};var url="http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid="+objId;swfobject.embedSWF(url,objId,'100','100',"9.0.0",null,null,params,atts)}function loadListPlayer(objId){var params={allowScriptAccess:"always",wmode:"opaque",bgcolor:"#000000"};var url="http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid="+objId;swfobject.embedSWF(url,objId,'680','385',"9.0.0",null,null,params,{'id':objId})}var vidPlayer=(function(){var timer,singleVideo=false,landingPageActive=false,setEvents=function(){$(window).resize(playerResize);$("#"+divElm.playerTopLayer).click(togglePlay);$("#"+divElm.videoBox).click(togglePlay);timer=setTimeout('vidPlayer.hidePlayControl()',8000);$(document).mousemove(function(event){vidPlayer.autoPlayControl()});$("#playControl").mouseover(function(){vidPlayer.mouseOverPlayControl()});$("#pBarBg").click(function(e){vidPlayer.getPlayOffset(e)});$(window).unload(videoList.onUnloadPage);document.onkeydown=function(e){if(!e){e=window.event}switch(e.keyCode){case 37:playPrv();break;case 38:break;case 39:playNext();break;case 40:break;case 13:case 19:case 32:togglePlay();break;case 179:togglePlay();break;case 178:pauseVideo();break;case 176:playNext();break;case 177:playPrv();break;case 77:toggleSound();break;default:break}}},mOutPlayControl=function(){$(document).mousemove(function(event){vidPlayer.autoPlayControl()})},mouseOverPlayControl=function(){$(document).unbind("mousemove");clearTimeout(timer);showPlayControl()},hidePlayControl=function(){$("#playControl").hide("slow")},showPlayControl=function(){$("#playControl").show("fast")},getPlayOffset=function(e){var pos=e.pageX/$("#title").width();setSeekTime(pos)},autoPlayControl=function(){showPlayControl();clearTimeout(timer);timer=setTimeout('timer=null;vidPlayer.hidePlayControl()',4000)},showBar=function(){$("#pbar").fadeIn()},toggleSound=function(){if(isSoundMuted()){unMuteVideo();document.getElementById('muteIcon').src="http://mediastroage.s3.amazonaws.com/mute_24.png"}else{muteVideo();document.getElementById('muteIcon').src="http://mediastroage.s3.amazonaws.com/unmute_24.png"}},toggleAboutPage=function(){if($("#about").is(":visible")){$("#playControl").show("slow");playVideo()}else{$("#playControl").hide("slow");pauseVideo()}$("#about").toggle("slow");$("#bg").toggle("slow")},fullMenu=function(){$("#logo").text('Tiltview.com <span id="fullMenu"> from different sourced &#9660; </span>')},smallMenu=function(){$("#logo").text('Tiltview.com ')},isLandingPageActive=function(){return landingPageActive},hideAll=function(){$("#land").hide("slow");$("#about").hide("slow");$("#bg").hide("slow");landingPageActive=false;playVideo();unMuteVideo()},hideLandingPage=function(){$("#land").hide("slow");$("#bg").hide("slow");landingPageActive=false;unMuteVideo()},showLandingPage=function(){var vl=$.cookie("_visit");if(vl===null){$.cookie("_visit","y",{expires:365});if(singleVideo===false){$("#land").show();$("#bg").show();landingPageActive=true}}},playSingleVideo=function(){return singleVideo},onReadyForAction=function(){var hash;videoList.onLoadPage();if(!(typeof window.location.hash=="undefined")&&(window.location.hash!='')){singleVideo=getYtHash(window.location.hash)}loadPlayer(divElm.playerContent);setEvents();showLandingPage()};return{hideAll:hideAll,onReadyForAction:onReadyForAction,toggleAboutPage:toggleAboutPage,autoPlayControl:autoPlayControl,mouseOverPlayControl:mouseOverPlayControl,hidePlayControl:hidePlayControl,fullMenu:fullMenu,smallMenu:smallMenu,getPlayOffset:getPlayOffset,showBar:showBar,playSingleVideo:playSingleVideo,isLandingPageActive:isLandingPageActive,hideLandingPage:hideLandingPage,toggleSound:toggleSound,mOutPlayControl:mOutPlayControl}})();var listPlayer=(function(){var timer,vidList,index,getVideo=function(){return vidList.items[0].id},onReadyForAction=function(){var i=0;$('#listBox').hide();vidList=videoList.getVideoList();for(i=0;i<20;i++){$('#listBox').append('<div class="listItem" onclick="playById(\''+vidList.items[i].id+'\',\''+vidList.items[i].title+'\' , \'#listTitle\')"> <img width="240" height="180"  src="'+vidList.items[i].thumbnail.hqDefault+'" /> </div>')}$('#listBox').show();loadListPlayer('listPlayerContent')};return{onReadyForAction:onReadyForAction,getVideo:getVideo}})();

