I have 2 video playlists. When the first one hits the count of 3 I need it to clear the div and run the alt1 playlist. Then when that hits a count of 3 I need it to clear its divs and go back to the regular function. I am REALLY stumped about this.

var vidCount = 0; var halfCount = 0; $(document).ready(function regular() { var videoPlayer = document.getElementById('videoStage'); videoPlayer.addEventListener("ended", function() { if (vidCount == 3) { alt1(); } else (vidCount++) console.log(vidCount); this.pause(); var videoList = ["internal1", "internal2", "internal3", "internal4", "internal5", "internal6"], videoList = videoList[Math.floor(Math.random() * videoList.length)]; $('#mp4').attr("src", "_ASSETS/_MP4/" + videoList + ".mp4"); $('#halfAd').css('visbility', 'hidden'); this.load(); this.play(); }, false); videoPlayer.play(); }); function alt1 () { var halfPlayer = document.getElementById('halfStage'); halfPlayer.addEventListener("ended", function() { if (halfCount == 3) { regular(); } else (halfCount++) console.log(halfCount); this.pause(); var halfList = ["half1", "half2"], halfList = halfList[Math.floor(Math.random() * halfList.length)]; $('#mp4').attr("src", "_ASSETS/_MP4/" + halfList + ".mp4"); $('#halfAd').css('visbility', 'visible'); this.load(); this.play(); }, false); halfPlayer.play(); };

Maybe I have been just staring at this code too long. Any help will be appreciated. Once I get this to work I'll start on randomizing between the 3 playlists. Ugh, this seems like it should work.